Accessing sensor minimum and maximum values of a sensor

owen planchart's icon

Hi all,

I am using Max to receive data from and a gyroscope (BNO055). I have the sensor attached to a pendulum and I am trying to get a bang everytime the pendulum swings. The patch below allows me to get a bang whenever the direction changes but that is already too late for the desired effect. Ideally I would be able to get the moment when the difference between the current angle and the previous angle is exactly 0 but I can't seem to patch that. When I try to use a threshold, I get multiple bangs and inconsistencies. Peak and Trough would probably work if it wasn't for the fact that every swing has a higher minimum and a lower maximum than the previous one. Any other ideas? I've also tried delta and snapshot without much success.

Thanks in advance,

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

Maybe you want to bang when pendulum stops moving in either
direction instead of detecting direction change on edges ?

owen planchart's icon

Hi Source Audio,

That's exactly right, but what objects/logic do I use to detect the stopping of the movement on each swing?
I'm trying with "t f f" pathched into "!- 0. " but that doesn't seem to work. Do I need to work out the gradient of the curve somehow?

Source Audio's icon

no, it is much simpler, you bang into delay which outputs
only when input is quiet for set delay time.

Max Patch
Copy patch and select New From Clipboard in Max.


owen planchart's icon

Thank you so much for taking the time. This is a really nice solution. The problem that I am having is my gyro sensor drifts significantly so the gswitch at the end isn't giving me the bang that represents the other swing. I am also finding it hard to get the right grain value (the data sheet says 100hz), which means I get too many bangs or not enough bangs. Sorry for the clunky screen recording. Thanks again

Screen Recording 2023-03-24 at 21.13.05.mov
video/quicktime 2.53 MB
Using Delay for Sensor values

Source Audio's icon

you mentioned pendulum, but your input does not show that behaviour,
but erratic jumps
Either your object is not swinging as pendulum,
you are capturing movements in a wrong way, or something else ?
You need to look at hardware side and fix that first.
that delay should be kept as low as data input rate.

maybe you should capture raw input and then explain what is hidden in that OSC patch.