Implementing Positioning Algorithms Using Accelerometer MMA7260Q

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Implementing Positioning Algorithms Using Accelerometer MMA7260Q

12,337 Views
night_mode
Contributor I

I`ve just got my MMA7260Q accelerometer sample thanks to Freescale. Using this accelerometer i want to make a position application. My question is if somebody had implemented a position algorithm using this kind of accelerometer and where can i find some tips ?
Thanks.

--
Alban edit: FSL Part number in message subject.

Message Edited by Alban on 2007-03-28 08:48 AM

Labels (1)
0 Kudos
Reply
21 Replies

2,660 Views
OscarC
Contributor I
Hi,
 
Our experience on this kind of implementation is documented on app note AN3397:
 
you should be able to find some tips for the implementation in here.
 
cheers,
Oscar
0 Kudos
Reply

2,661 Views
rocco
Senior Contributor II
Hi, Night_Mode:

Yes, I have done that with Analog Devices accelerometers, but I can't share the code. I can share an overview of my algorithm.

The accelerometer provides you with acceleration (gee, really?). Mathematically, velocity is the integral-over-time of acceleration, and position is the integral-over-time of velocity. So position can be determined by doing a double-integral of the data derived from the accelerometer.

Easier said than done.

To get any accuracy, both the samples must be accurate and the sample rate high. Any errors in the sample will be integrated as well, and can accumulate quickly. Be careful not to loose any precision in your math, as that loss will also be integrated.

You also have to consider the effects of gravity. The three axes will be affected by 32 feet-per-second-per-second of gravitational acceleration. Somehow, you need to determine which direction is down, and subtract out gravity. I did this subtraction as a vector near the tail end of my calculations.

Without additional sensors to close the loop, you will get both velocity and position drift. That is the nature of an integral that is not using perfectly measured samples.

If you instrument can tilt, a pair of inclinometers would help to determine the direction of the gravitational vector.

I could go on and on. There is a lot to the subject.

Message Edited by rocco on 2007-03-2706:07 PM

0 Kudos
Reply

2,661 Views
night_mode
Contributor I
Ooo, i have the mathematical background of this problem. I whant to ask you what was the sesitivity of your accelerometer and what was it`s maximum rating: 1.5g,2g,.... I tried to implement the algorithm found in the freescale AN3397 using a 3-axis 2g accelerometer LIS3L02AS4 from ST but it acts very strange, it gave accelerations only when the pcb starts moving and after that if I continued to move the pcb with a normal speed the acceleration was 0.
You confirmed me that the mathematical background is ok and I`ll try this algorithm with the accelerometer used in the application note: MMA7260Q. Another question: what can you tell me about hardware consideration between sensor and ADC ?
0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I

Hi All,

 

When reading AN3397 I  think I found some small mistakes. Please confirm.

 

Formula 1:

 

Area = Samplen-1 + [Samplen-Samplen-1]/2 (Total area of slice. A1 + A2)

 

No index on Area and no need T, because T=1 (For each slice there is A1 and A2)

 

Figure 3: Lacks of an axis indicating positive direction of t. Samplen-1 and Samplen should be interchanged if time-axis is from left to right.

 

 

In general the text is very good and will help me a lot (I´m sure).

 

 

thanx

 

As soon as I have tested MMA7620QT with MSP430 I will post my results.

0 Kudos
Reply

2,661 Views
hazeeq
Contributor I

Hi,

 

I tried to implement the formula found in http://www.freescale.com/files/sensors/doc/app_note/AN3397.pdf?fsrch=1 to measure displacement in 1 dimension, however apparently the result is way off compared to the actual distance.Here's what I did( I also noticed that the formula is slightly wrong);

 

velocity[1] = velocity[0] + acceleration[0]*T + ((acceleration[1] - acceleration[0] )/ 2)*T

 

and

 

position[1] = position[0] + velocity[0]*T + ((velocity[1] - velocity[0] )/ 2)*T

 

where T = 0.001s  in my case.

 

can somone please verify me if I did the correct calculation here?

 

Thanks.

0 Kudos
Reply

2,660 Views
JimB
Contributor I

I might be a bit tired, but what is the error that people are talking about - is it the "absolute value" thing in formula 1 of the AN? I'd be inclined to think that you could forget about the T if it was constant, along the lines that if your acceleration was in m/s/s, but T was 1 ms, then the velocity would end up being in mm/s and position in micrometres - or something like that (I think?) They don't seem to worry about T in the AN, at least in the integration bit anyway.

0 Kudos
Reply

2,661 Views
kef
Specialist I

Hi Arquimedes

 

Yes, formula is bit wrong. But area index is indeed required. Also T (sampling time) is in general case not equal 1. T should be as small as possible for better accuracy.

 

Area[n] = (Sample[n-1] + (Sample[n] - Sample[n-1])/2 ) * T

 

or

 

Area[n] = ( (Sample[n-1] + Sample[n])/2 ) * T ,

 

 

Area = sum of A[i]

 

0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I

Hi all,

 

 

the program to test ST evaluation board STEVAL-MKI006V1 is stopping responding after a time of use. My operational system is Windows Vista 64 bits (Laptop HP Pavilion dv6000 with 4GB of DDRII-RAM). Map browsing demo is out of control. Do I need to change registers values?

0 Kudos
Reply

2,661 Views
bigmac
Specialist III

Hello,

 

You are unlikely to receive help on this forum concerning an evaluation board that uses a non-Freescale processor.

 

Regards,

Mac

 

0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I
I´m testing the evaluation board. It comes with a freescale processor. I just plug the eval board on my PC and ran the demo software downloaded from ST. As you can see I didn´t connect any other processor.
0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I
I´m sorry! I´m sorry! You are right! The board I´m testing is an ST board, not Freescale!! :smileysad:
0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I

Hi All,

 

I´m testing MMA7260QT accelerometer. My microcontroller is an MSP430F2274. I connect accelerometer to my microcontroller according schematic in AN3397. The code I used was derived from the source code in same AN (just added code for z-axis). I used P2.1, P2.2 and P2.3 in MSP430. The problem is that with the accelerometer in a fixed position (no-movement), there´s a big variation in x,y,z position. I expected to read values around zero in such situation. Below is my ADC_GetAllAxis routine

 

void ADC_GetAllAxis(void)
{
    unsigned int delay;
   
   ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE;

   delay = 0x0100;                              

   //X-Axis

   ADC10AE0 |= 0x02;                             //P2.1 - A1 ADC input port

   ADC10CTL0 &= ~ENC;                          //Disable conversion

   while (ADC10CTL1 & BUSY);                  //Wait ADC10 to be ready

   ADC10CTL0 |= ENC + ADC10SC;            //Enable and start conversion

   Sample_X = ADC10MEM;                      //Take converted value

   while(--delay);                                  //Wait
     
   delay = 0x0100;                               
   //Y-Axis
   ADC10AE0 |= 0x04;                             //P2.2 - A2 ADC input port

   ADC10CTL0 &= ~ENC;                            

   while (ADC10CTL1 & BUSY);                   

   ADC10CTL0 |= ENC + ADC10SC;                 

   Sample_Y = ADC10MEM;                        

   while(--delay);                                

   
   delay = 0x0100;                               

   //Z-Axis

   ADC10AE0 |= 0x08;                             //P2.3 - A3 ADC input port

   ADC10CTL0 &= ~ENC;                            

   while (ADC10CTL1 & BUSY);                  
   ADC10CTL0 |= ENC + ADC10SC;                

   Sample_Z= ADC10MEM;                           
   while(--delay);                               
}
 

0 Kudos
Reply

2,661 Views
bigmac
Specialist III

Hello,


Arquimedes wrote:

The problem is that with the accelerometer in a fixed position (no-movement), there´s a big variation in x,y,z position. I expected to read values around zero in such situation.
 


My understanding is that the outputs from the accelerometer are biased to about one-half the supply rail voltage to operate at the centre of the linear output region.  Each output will therefore swing positively and negatively about this point.  This offset voltage must be taken into account for the ADC calculations.

 

The other factor is that, one or more axes, depending on the orientation of the accelerometer, will output a static voltage swing corresponding to its component of gravitational acceleration.

 

Regards,

Mac

0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I

I forgot to put ISR routine

 

__interrupt void ADC_ISR(void)
{
    return;           

}
ADC10_ISR(ADC_ISR)

 

0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I
Your are RIGHT!!! One doubt: Output signals are analog, right? So I must input those signals to an A/D converter. In my breadboard I use P2.1, P2.2 and P2.3 of MSP430F2274. Those pins should be configured as alternative A/D pins. At no movement I measured Vz = 0,846V, Vy = 1,546V and Vx = 1,614V. Those values change a lot if I change MMA7620QT position. So, how can I determine the better position to measure voltages? Or this doesn´t matter? In my circuit in reality I do not have precision requirements. I just want to identify an attempt of violation (removing equipment from its home position). Of course there could be some natural displacements due to cars moving (specially trucks) around and other things. I think that only practice would determine the best threshold in this application.
0 Kudos
Reply

2,661 Views
bigmac
Specialist III

Hello,

 

If you are attempting to detect the removal of equipment from a motor vehicle, perhaps you might utilize a potential change of tilt condition on the action of removal. This could be enhanced if the physical mounting would provide a "built in" tilt motion during installation and removal.  The tilt would be detected by a change in the gravitational axis.

 

Changes of vehicle motion are tyically likely to be significantly less than 1g, and would be present for only short duration.  Low pass filtering, or averaging of the results for each axis, should filter out vibration components.

 

Regards,

Mac

0 Kudos
Reply

2,661 Views
Arquimedes
Contributor I

Hi Bigmac!

 

 

I´m not trying to detect the removal of my circuit from a motor. My equipment is collecting data and transmitting to a remote Data Collector (300 meters afar) that sends this information (encrypted) to our office via Web. Both the End Device and Access Point have accelerometers to detect the removal from its home position (could be an wall near the point of interest).In reality I think that accelerometers could be 2-axis. I received my ST eval board (LIS302DL) today and I´ll test it.My processor is Texas MSP430F2274.

 

Thank you

 

Arqui

0 Kudos
Reply

2,661 Views
rocco
Senior Contributor II
Hi, Night_Mode:


I want to ask you what was the sensitivity of your accelerometer and what was it`s maximum rating?
I used three of the Analog Devices ADXL105, which measure with 2mG sensitivity, up to 1G.
I tried to implement the algorithm found in the freescale AN3397 using a 3-axis 2g accelerometer LIS3L02AS4 from ST but it acts very strange, it gave accelerations only when the pcb starts moving and after that if I continued to move the pcb with a normal speed the acceleration was 0.
Yes. That is exactly what you should be seeing. When the board is moving at a constant velocity, the acceleration is zero. However, your integration of acceleration would have given you the current velocity. As you integrate that current velocity (now constant), you will get a changing position. It's unlikely to be very accurate, though.
Another question: what can you tell me about hardware consideration between sensor and ADC?
I needed a small amount of analog between the sensors and the DSP, mainly to trim the gain and offset, and convert to differential signals. I then used an audio ADC to sample at 24-bit resolution and 48kHz. I then did the bandwidth filters in DSP firmware. I used the DSP56002.

Message Edited by rocco on 2007-03-2812:33 AM

0 Kudos
Reply

2,661 Views
night_mode
Contributor I
I whant to mount this device with the accelerometer on the hand and using a software to generate the 3d trajectory of the hand movement and I tought that I`ll never have a constant speed. When I start moving the hand lets say we have an acceleration. Supposing I have a normal speed of the hand in one direction how can i differentiate the no movement case from moving with a constant speed ?, in both cases i have a 0 g acceleration.
Thanks for the hardware considerations, these are very usefull.
0 Kudos
Reply

2,661 Views
RHA
Contributor II
Check out this video !
 
http://www.youtube.com/watch?v=yfp5HBUizOQ
 
this is the implementation of a positioning algorithm based in the following appnote !
 
 
saludos !
 
r
0 Kudos
Reply