Speed of movement
Hi!
I built a patch that detects color. I have a color light and when it detects the color I want to calculate the speed of the movement of the light. The point is to build a conducting baton that when I speed up the movement, the music that is being played speeds up too.
What can I do to calculate the speed of the movement?
Thanks
Rita Macedo
Here's a very primitive way to do it:
I'm basically using the formula for velocity ( v = dx/dt), so I just take the displacement and divide it over time.
I'm sure someone will come up with a more elegant solution.. :S
Thanks that was really helpful. But look what happens.
This is my patch:
I applied what you gave to me with the x and y values that I have and nothing happens, the velocity slider doesn't move, and I can't understand why. Can you help me?
Thank you for your help ;)
Ok - when you take an example someone else posted, and then you change ten things, and you wonder why it doesn't work as in the beginning, don't ask the person who showed you the example why it doesn't work (when it worked in the first place) but go back and see how every little thing you change may have altered the example.
In your case, you changed many things: first of all, you need to retain the little dot (.) after the zeroes, in objects such as [- ] and [/ ]. Max deals with a few different kinds of data, such as integers, floats, and symbols, and on many occasions you need to specify which one you're dealing with (usually there is a default).
Also, you changed the range of the incoming numbers to the [anal] objects: the [anal] objects work only with numbers from 0 to 127, while they were receiving numbers up to 240 on one axis and 320 on the other axis. You need to scale that input (from the camera's pixels) to 0-127 in order for [anal] to work.
If you just type [- ], or [- 0], then it deals with integers. If you want it to deal with floats, you need to specify it with the period, so you need to write [- 0.] (same with the [scale] object and similar)
Another example of this is that the [expr] object, by nature of the equation it is executing, will output a float, which cannot be stored in an [int] object (i.e. the [int] needs to be changed to [float])
Lastly, you may need to play around with the [scale] values depending on the velocity range of your object (so try [scale 0. 2. 0. 127.] or even [scale 0. 1. 0. 127.] if it's moving very slowly)
Here's your patcher corrected:
Hope this helps :) As I said, when you're copying things out, it always helps to copy them exactly as they're written, and if you change something, it is important to debug it instantly and see if what you changed had an effect on the function of the whole.
Also, check the help files, there's a lot in there :)
Hey :)
Sorry I did copy it exactly as it was, but it didn't work so I was experimenting and I forgot to put it the way it was before I send it to you. I'm pretty new at this so I still don't know very well what to do.
But it still isn't working, the velocity slider doesn't move. What should I do?
I've been very helpful, thank you a lot ;)
*you've been
ah, thanks for pointing this out, it was a mistake on my part (because I worked this example by controlling the [pictslider], not by using a webcam)
now it should work:
I added some comments on there to explain what was the problem.
Also, if you are tracking colours, you might want to invert the image horizontally so that when you move left, the image on [jit.pwindow] moves left as well. Just add this after [jit.qt.grab]:
[jit.rota @zoom_x -1 @offset_x 320]
That should do it.