Forums > MaxMSP

integrate to get displacement from acceleration over time

April 23, 2006 | 3:36 pm

Hello all,

I have a 2-axis accelerometer circuit that will be sending values to max/msp, and I’d like to be able to determine location information over time. The last time I used calculus was about 15 years ago, so I’m a little rusty here, but I think I’d need to integrate to get velocity and then displacement.

Is this something that’s possible in Max? Any pointers would be greatly appreciated!!

Spencer


April 24, 2006 | 11:00 am

I tried this before, but didn’t get accurate results and stopped.

The idea in integration is to sum the difference between consecutive
values of your data stream multiplied by the duration of the interval
between these values (like computing a surface):
-> sum [ (value[timeX]-value[timeX-1])*(timeX-(timeX-1)) ]

should give you the speed. And if you apply the same process on speed,
you’ll get the position.

You probably won’t get your data on a regular time interval, so
timeX-(timeX-1) will vary over time.

The problem is that the datas, and especially the time intervals, are
not extremely accurate, so after a while, your speed won’t be 0
although the accelerometer doesn’t move anymore because the sum of
acceleration and deceleration won’t _perfectly_ match. And so the
positions will move too.

As an accelaration of 0 doesn’t mean that there is no movement (I was
surprised to notice that the violin player I worked with moved her bow
with a perfectly stable speed, i.e. no acceleration!), it is not easy
to add some "reset" function to the speed and position; it depends on
the physical properties of your moving object (in the case of a bow,
you know the range of the movement, and could eventually manually reset
the position when an extremity of the bow is reached).

Another issue is that your accelerometer will probably return 0->1 G
values if it’s only rotated, without changing its position within the
world.

Good luck.

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max


April 24, 2006 | 1:39 pm

On 24 avr. 06, at 13:00, Patrick Delges wrote:

Ooooppppsssss, I’m afraid I wasn’t very concentrate when I posted this
message and made a strange mix between integration and derivation…
You don’t want to sum the differences between values, but the values
themselves, times the delta-time. I found a small test patch I made
that may give you some ideas… but there is still a lot to do!

#P window setfont "Sans Serif" 9.;
#P flonum 51 205 79 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 51 182 67 196617 * 1.;
#P flonum 51 160 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 51 137 27 196617 / 2.;
#P newex 51 112 27 196617 + 0;
#P newex 50 69 40 196617 t i i b;
#P number 108 104 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 108 62 34 196617 b;
#P newex 108 83 34 196617 timer;
#P outlet 150 510 15 0;
#P number 150 440 72 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 150 366 27 196617 + 0.;
#P newex 150 404 27 196617 i;
#P button 153 222 15 0;
#P inlet 153 34 15 0;
#P outlet 51 514 15 0;
#P message 151 244 14 196617 0;
#P number 51 312 72 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 51 238 27 196617 + 0.;
#P newex 51 276 27 196617 i;
#P inlet 50 33 15 0;
#P comment 202 112 53 196617 acc to pos;
#P comment 201 125 100 196617 integral;
#P comment 143 312 100 196617 speed;
#P comment 243 444 100 196617 position;
#P connect 14 0 15 0;
#P fasten 14 0 13 1 155 462 236 462 236 346 172 346;
#P connect 10 0 11 0;
#P connect 11 0 8 0;
#P connect 12 0 14 0;
#P connect 8 0 5 0;
#P connect 8 0 12 0;
#P connect 13 0 12 0;
#P connect 7 0 9 0;
#P fasten 7 0 6 1 56 347 137 347 137 230 73 230;
#P fasten 7 0 13 0 56 360 155 360;
#P connect 17 1 16 1;
#P connect 18 0 23 1;
#P connect 16 0 18 0;
#P connect 17 0 16 0;
#P connect 4 0 19 0;
#P connect 4 0 17 0;
#P connect 19 0 20 1;
#P connect 5 0 7 0;
#P connect 6 0 5 0;
#P connect 24 0 6 0;
#P connect 23 0 24 0;
#P connect 22 0 23 0;
#P connect 21 0 22 0;
#P connect 20 0 21 0;
#P connect 19 1 20 0;
#P window clipboard copycount 25;

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max


April 24, 2006 | 1:48 pm

Thanks for your reply! I will be testing this week, and I’ll let you know how it works out.

Best,

Spencer


April 24, 2006 | 4:31 pm

FYI…going from acceleration to position is going to be tricky as
you’re going to have a second order integrator. Errors will
accumulate very fast without some sort of error correction term in
your calculations.

best,
wes


April 26, 2006 | 7:46 am

spencer kiser wrote:
> I have a 2-axis accelerometer circuit that will be sending values to
> max/msp, and I’d like to be able to determine location information
> over time. The last time I used calculus was about 15 years ago, so
> I’m a little rusty here, but I think I’d need to integrate to get
> velocity and then displacement.

Mathematically its not a problem as Patrick showed, but as your
accelerometers are analog you will get errors which add up fast. You
won’t be able to track absolute positions with that very precisely,
unless you combine it with a way to correct it, for example with a
camera, or with single events which could only occur at a defined point.

All depends on what you want to do with it.

Stefan

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


Viewing 6 posts - 1 through 6 (of 6 total)