Go Down

### Topic: noob question about the MPU-6050 accelerometer (Read 1 time)previous topic - next topic

#### Garberg

##### Sep 02, 2013, 01:13 pm
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

#1
##### Sep 02, 2013, 01:49 pm
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

#2
##### Sep 02, 2013, 01:54 pm
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