Simpler tipping calculations for balancing robot

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.

Try all the methods and let us know how well each works!

More specifically, why calculate for quadrants III and IV if you are only operating in I and II. Its not really about "better".

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! ]

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.

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

But the measurement is highly nonlinear in the tip angle, and error linearity is an assumption for a PID algorithm.

Highly nonlinear? Got some math to back that up?

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

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.

Optimistically speaking, yes.

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.

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.

jremington:
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.

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.

jremington:
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.

Even if you can get an accuracy of 1 deg with sensor fusion it is not good enough.

Nonsense.

jremington:
Nonsense.

Hard to argue with reasoning like that. :slight_smile:

But its rate of change of tilt that matters, absolute angle is best corrected from wheel acceleration
as I've mentioned (partly because the distribution of mass may change and thus the perfect balance
angle will be different from run to run if the battery is moved/changed or a payload added).

It is interesting that for a falling inverted pendulum, the rate of change of theta (tilt) is proportional to theta (for theta << 1 radian).

This follows directly from the equation of motion about a point of unstable equilibrium:
theta dot = sqrt(g/l)*theta
where l is the distance from the pivot point to the center of mass.

jremington:
It is interesting that for a falling inverted pendulum, the rate of change of theta (tilt) is proportional to theta (for theta << 1 radian).

This follows directly from the equation of motion about a point of unstable equilibrium:
theta dot = sqrt(g/l)*theta
where l is the distance from the pivot point to the center of mass.

(theta dot)dot = sqrt(g/l)*theta