Go Down

Topic: noob question about the MPU-6050 accelerometer (Read 885 times) previous topic - next topic

Garberg

I'm currently building a little lego segway and I thing I might have made a small misstake...

I'm using this formula to calculate an angle from the accelerometers raw data:

Code: [Select]
angle=((atan(y/sqrt(pow(x, 2)+pow(z,2))))*(180/3.14159265359));

This works just fine as long as the segway is lying down flat on a table. The accelerometer circuit board is mounted on my veroboard in such a way that it is also lying flat on a table when the entire segway is lying flat on a table. This position will give me an angle of about zero degrees. And if I raise the seaway up into an upright position the accelerometer shows around 90 degrees. So far so good. But if I tilt the segway more than 90 degrees the accelerometer shows less than 90 degrees. It seems as the accelerometer can't produce a value more than 90 degrees? As long as the segway is upright I have no way of knowing if it's tilting forwards or backwards. Is there a clever way to work around this or do I have no other choice then to mount the accelerometer the correct way?

johnwasser

Try mounting your accelerometer at a 45° angle with Y pointing up and forward and X pointing up an back.  When they are equal your device is vertical.  If your device tilts back the Y will go up and the X will go down.  The opposite happens if you tilt forward.  You should be able to just take the difference between X and Y and feed that into the PID library without trying to convert to angles.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Garberg

I see your point but mounting the accelerometer in a 45 degree angle would still mean to re-mount the damn thing. In that case i might as well mount it correctly.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy