Pages: [1]   Go Down
Author Topic: noob question about the MPU-6050 accelerometer  (Read 659 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: