MEMSIC 2125 object at 45deg?
simonl
Posts: 866
I wonder if someone would produce a version·of the MEMSIC 2125 object that accepts 'rest' to be with both axes at 45deg to horizontal?
I'd like to implement MEMSIC's formula for dual axis inclination sensing of a moving vehicle·[noparse][[/noparse] angle = acos( 0.707 x ( Ax + Ay ) / g ) ], as shown in their app' note #AN-00MX-012, but don't really know where to start.
Thanks in advance.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
I'd like to implement MEMSIC's formula for dual axis inclination sensing of a moving vehicle·[noparse][[/noparse] angle = acos( 0.707 x ( Ax + Ay ) / g ) ], as shown in their app' note #AN-00MX-012, but don't really know where to start.
Thanks in advance.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
Comments
This is essentially what it describes, only the sensor is fixed at 45 Deg. If you look at the 'MEMSIC 2125 object' there is a line of code that reads...
Really all this does is read the RAW X and Y values at that moment whatever the position of the sensor, and then uses those values as an offset value to subtract
from future RAW X and Y values.
If you omit this line, then you will see nothing but RAW X and Y values, because the offset will be Zero.
Mount your sensor at 45 Deg and the formula should apply to the RAW X and Y sensor values.
The difficulty then is getting 'acos' but not impossible.... There are some objects floating around to do that, but it takes up a huge amount of space with many unnecessary
functions let me look at it and I will get back to you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I've been looking for an ACos routine, but haven't yet found one. I thought there might be one in the 'Assembly Function Engine v.1.0' but there isn't. Am I looking in the right place?
Also, thanks for the acc.setlevel advice
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
Here is an updated version with ArcSine and ArcCosine.
ArcSine and ArcCosine are derived from the built-in ROM Sine table by way of successive approximation.
A reverse lookup table if you will, but instead of looking at every entry... 2048 of them, the "pivot" method
I am using here only requires 11 lookups (1 for each bit of resolution). If the table had 256 entries this
process would require 8 lookups to find the solution.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
Unfortunately I'm not getting anywhere with my demo code of the MEMSIC #AN-00MX-012 45° formula [noparse][[/noparse]angle = ACos( 0.707 x ( Ax + Ay ) / g )]. I think I've got the floating-point stuff correct, but it all seems to hang-up when I add the ArcCosine part.
I have a feeling it's something to do with scaling, but can't get my head around it. I wonder if you would mind taking a look at my code and laugh at my obvious mistake(s)!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
·
In·the formula· ...[noparse][[/noparse]angle = ACos( 0.707 x ( Ax + Ay ) / g )]
·
'g' I believe is acceleration not 'G' gravity as you have it in your formula try using roVal instead.
There are some other scaling issues I see.· The function ArcCosine is looking for a 16-bit signed
number that represents "1" (65535)·to "-1" (-65535).· The·ArcCosine function returns an 11-bit
signed angle ranging from "pi/2" (2048)·to "-pi/2" (-2048).
··
You want RAW values for Ax and Ay· ... you need to remove the line from your code that reads:
·
acc.setlevel
·
...This line of code simply creates a mathematical offset for the accelerometer that says "Whatever
position you are currently in (<-- The accelerometer), we are going to call that level".· For your
application you do not want this feature.
·
Ax, and Ay might be ok ... remember Ax and Ay are supposed to represent the number of "ticks"
the pulse from the Memsic2125 remains HIGH.· So this value needs to be scaled according to your
clock speed to represent the proper value.
·
Under "normal" conditions, Ax and Ay should produce a 5mS pulse·at "level" ... at·80MHz·(12.5nS)
Ax and Ay should return something like 400,000
·
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 9/25/2006 3:39:51 AM GMT
I'll try your suggestions, and see if I can figure-out how to do the scaling -- I'm sure I've seen some Parallax documents that show examples (I think one of them's by Andy Lindsey).
As for the 400,000 ticks, I'm seeing nothing like that but I guess there's some calculation going on in the MEMSIC driver -- I'll see if I can spot it.
Thanks again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
that is also called within '.sensor.memsic.2125'· ... also your doing a conversion (cvt) within '.sensor.memsic.2125' that attaches a valid unit of micro-Seconds to your value.· In doing
this, you should also apply 'cvt' to your roValue also.·
·
In an earlier post...
"I think I've got the floating-point stuff correct, but it all seems to hang-up when I add the ArcCosine part."
·
You need to 'start' the function engine with something like.... 'func.start' in your initialization routine.
·
·
·
Attached is a version of the '.sensor.memsic.2125' with some modifications.· With this version, you should be
able to use 'theta', and just add or subtract 45 Deg to get your position.· You should calculate 'ro' separately
though.· You should be able to derive this from the floating point math routines.
·
ro = sqr ( x^2 + y^2 )
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for the updated .sensor.memsic.2125 object, I'll try that a.s.a.p.
Last night I ended-up removing the driver completely and used BS2.Pulsin_Clk instead; that got me the 400_000 you mentioned
I've found the "Smart Sensors and Applications" (Chapter #3) article, and am trying to get my head around the scaling stuff. Am I correct in saying that I need to scale my 'ArcCosine( angle )' to be between (dec) -65535 to 65535? This will give me numbers between (dec) -2048 to 2048?
I will then need to convert that output to degrees. I'm presuming that (say) -2000 will correspond to an angle 'below horizontal', and 2000 above horizontal. Any pointer on how I determine the actual angle in degrees would be greatly appreciated (from anyone -- I realise that I'm 'leaning' on Beau quite a lot at the moment...)
Thanks in advance.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
Yes
"...This will give me numbers between (dec) -2048 to 2048?"
Should
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon