Go Down

### Topic: Simpler tipping calculations for balancing robot  (Read 1 time)previous topic - next topic

#### briantee

##### Feb 10, 2016, 04:22 pm
I see most if not all balancing robot programs calculate the actual degrees of the lean of the robot using Xacc Zacc and gyro Y. What is to be gained by taking the arctan of the X and Z accelerometer reading if you are only using the first 20 "units" of tipping? Can you not just use the Xacc?

Why not just use the AccX and Gyro Y in either a Kalman or complimentary to calculate how far the robot is leaning over and skip the x and z atan2 calculation? All the PID is looking for is a place to call zero and how far it is leaning just those few degress to get back there.

#### jremington

#1
##### Feb 10, 2016, 04:54 pm
Try all the methods and let us know how well each works!

#### briantee

#2
##### Feb 10, 2016, 07:53 pm
More specifically, why calculate for quadrants III and IV if you are only operating in I and II. Its not really about "better".

#### MarkT

#3
##### Feb 11, 2016, 12:21 amLast Edit: Feb 11, 2016, 12:23 am by MarkT
You have to combine the gyro and accelerometer (gyro gives angle information, accelerometer
corrects for slow drift).  The combined angle estimate is then used.  In general accelerometer
data gets less and less useful if there is a lot of movement (oscillation), since the slow average
gravity vector you are trying to get from it is polluted by all the motion (and the non-linearities
and imperfections of the sensor).

If you calibrate gyro drift really well you'll basically only be using gyro for balance, and accelerometer
will correct for long term drift on longer timescales.  You need to sample the gyro at a high rate,
probably 200Hz or more to have a chance of stable behaviour.  The accelerometer is nowhere near
so critical I think.

You also with a wheeled balancing robot can correct for slow drift from the wheels acceleration
(if only running a balance loop the acceleration is due to gyro being out of true w.r.t. gravity)

So in theory a single axis gyro is all you need, if you start the thing in balance, because any small
error from balance shows up as acceleration of the whole thing, which you can measure directly
from your drive output to the motor.

To balance and move, you need two control loops, one to hold the balance, and one to control
the precise balance point to allow controlled acceleration (and thus change velocity).

[ Caveat - I've programed an IMU, but not actually built a balancing robot! ]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### briantee

#4
##### Feb 11, 2016, 07:20 am
You have to combine the gyro and accelerometer (gyro gives angle information, accelerometer
corrects for slow drift).  The combined angle estimate is then used.

[ Caveat - I've programed an IMU, but not actually built a balancing robot! ]

You are correct, however the two measurements i am talking about are the accelerometer axis X and Z and the arc tangent whose only purpose is to determine which quadrant you are in. A balancing robot, unlike an acrobotic helicopter, always remains wiggling only a few degrees back and forth in quadrant I and II.

I changed the code and the only difference is less noise, which is understandable as there is less being added to it. Makes sense as even at 70 degrees of tip, sin of theta is still 0.94.

So to answer your question jremington, its faster and less noise, so its better.

#### jremington

#5
##### Feb 11, 2016, 06:30 pmLast Edit: Feb 11, 2016, 06:31 pm by jremington
But the measurement is highly nonlinear in the tip angle, and error linearity is an assumption for a PID algorithm.

#### briantee

#6
##### Feb 11, 2016, 06:50 pm
Highly nonlinear? Got some math to back that up?

#### jremington

#7
##### Feb 11, 2016, 07:12 pmLast Edit: Feb 11, 2016, 07:16 pm by jremington
Yes, the inverse sine function. X acceleration = g sin(theta) with Z pointing more or less up or down.
The approximation sin(theta) ~ theta is OK for small theta (in radians).

#### briantee

#8
##### Feb 11, 2016, 08:54 pmLast Edit: Feb 11, 2016, 09:16 pm by briantee
But the robot is pointing more or less up or down and theta is small.

For example at sin(80 degrees) = the "error" is 0.985   Pretty close.

#### jremington

#9
##### Feb 11, 2016, 10:57 pm
Optimistically speaking, yes.

#### charliesixpack

#10
##### Feb 13, 2016, 01:54 pmLast Edit: Feb 13, 2016, 03:28 pm by charliesixpack
My robot maintains balance +/- 1 degree or +/- .017 rad.  This is a number I have measured.

Assuming an accelerometer measures tilt, the max measurement will be .017 g.  But the MP6050 spec for calibration tolerance is +/- .050 g and the spec for change with temperature over 0 to 70C is +/- .035 g.  Does that make sense?  The signal is buried in the mud.

My robot does not use an accelerometer.  There are robots that use an accelerometer to balance.  Those accelerometers are not measuring tilt.  They are measuring lateral acceleration.  They think they are measuring tilt with the accelerometer.  They are not.

#### jremington

#11
##### Feb 13, 2016, 06:49 pm
Accelerometers moving in the horizontal plane measure the vector sum of lateral acceleration and g. If the lateral acceleration is zero, g can be used to accurately estimate the tilt angle.

Consumer grade accelerometers with much better noise specs that the MPU6050 are available, allowing tilt measurements of better than 1 degree accuracy.

#### charliesixpack

#12
##### Feb 13, 2016, 07:21 pmLast Edit: Feb 13, 2016, 07:22 pm by charliesixpack
Accelerometers moving in the horizontal plane measure the vector sum of lateral acceleration and g. If the lateral acceleration is zero, g can be used to accurately estimate the tilt angle.

Consumer grade accelerometers with much better noise specs that the MPU6050 are available, allowing tilt measurements of better than 1 degree accuracy.
How about the robots that are using the MPU6050?

Also, what are the numbers on these better "consumer grade accelerometers?"  Without numbers statements are meaningless.

Sure, you can use an accelerometer to measure tilt between 5 and 175 degrees if you are at rest.  But on a moving robot without knowing lateral acceleration, no.

#### jremington

#13
##### Feb 13, 2016, 07:52 pmLast Edit: Feb 13, 2016, 07:57 pm by jremington
Quote
Sure, you can use an accelerometer to measure tilt between 5 and 175 degrees if you are at rest.
Here is one, built into a convenient tool, that measures between 0 and 90 degrees with +/- 0.2 degree accuracy. There are more expensive versions that perform much better.

For robotics, I recommend the Bosch BNO055 self contained absolute orientation sensor, which is very easy to use. At least in my hands, it is accurate to about 1 degree in absolute orientation, seemingly regardless of the gyrations it is forced to undergo.

#### charliesixpack

#14
##### Feb 13, 2016, 08:40 pm
Here is one, built into a convenient tool, that measures between 0 and 90 degrees with +/- 0.2 degree accuracy. There are more expensive versions that perform much better.

For robotics, I recommend the Bosch BNO055 self contained absolute orientation sensor, which is very easy to use. At least in my hands, it is accurate to about 1 degree in absolute orientation, seemingly regardless of the gyrations it is forced to undergo.

The Bosch accelerometer has a zero g offset of +/-.150 g (p. 13 of the data sheet) which is worse than the MPU6050.

Even if you can get an accuracy of 1 deg with sensor fusion it is not good enough.  My robot balances to less than 1 deg.

Go Up