Software
The software is coded in C and compiled using the GNU Compiler Collection GCC under WinAVR. The compiled code (intel hex format) is then loaded into the Atmel microcontrollers flash memory using the sp12 programming hardware (self-made board connected to the computer’s parallel interface named Ken’s Dongle after its creator Ken Huntington) and software (download available) developed by Steven Bolt, the founder of Pitronics in the Netherlands. A further programming software, which is compatible to the sp12 hardware, is provided under the name TwinAVR by Roland Walter (Berlin, Germany).
Sensor Data Processing
The main problem to solve is to get reliable information on the state of the robot with regard to tilt angle and angular change rate (angular velocity). Neither the accelerometers nor the rate gyro alone are capable of providing this information with sufficient stability or accuracy. The accelerometers give a long term stable information of the direction to the earth’s middle, however they give a noisy signal and are not sufficiently accurate for this kind of control. The rate gyro is very accurate but has a drift of its bias. To obtain the tilt angle, the angular change rate of the gyro must be integrated. When integrating the signal with a bias error, this error sums up considerably and leads to an instable behaviour of the robot.
All my previous approaches based on using only the accelerometer or the gyro were not successful in praxis so far: the pure accelerometer approach has a too noisy signal to be used for this kind of control (robot is shaking heavily around the stable position) and for the pure gyro approach I was not yet able to really compensate for the drift only by software (robot starts running faster and faster until it falls).
One way to solve these problems is to use the strengths of both sensor types and eliminate their weaknesses. This may be done using the so called Kalman filter algorithm. The basic principle of such filtering is described here:
Kalman filter @edu
and here:
Kalman filter @wikipedia
The filter implementation I have used here was provided with a nuts & volts article from October 2006 (part 1) and December 2006 (part 2). The original links
- http://www.nutsvolts.com/toc_Pages/oct06toc.htm
- http://www.nutsvolts.com/toc_Pages/dec06toc.htm
- http://www.nutsvolts.com/toc_Pages/TOC_Related_Info/0612/PersonalRobotics.php
- http://www.nutsvolts.com/~downloads/
You may download my complete code for my balancing robot named ARTIST including Kalman filter functions here:
artist.zip
Calculating Tilt Angle from 2-Axis Accelerometer Data
To avoid the error induced by the acceleration of the robot influencing the measurement values of the two-axis accelerometer I suggest the following: First of all use both readings of the two-axis accelerometer. The accelerometer should be placed in the lower part of the robot. If you use the x-axis in direction of the robots acceleration and the y-axis in the direction to the sky or ground (starting initially without tilt), both the tilt and the acceleration can be calculated from the data using trigonometric relations and solving a squared equation. I used the drawing in the paper of Joe Le Pendulum for reference, see their paper on the web Joe le Pendule
or download their .pdf file
Joe Paper
and look for Figure 5 or see the drawing here:
Then the forward (or backward) acceleration a of the robot can be calculated to:
a= +- SquareRoot( Square(x) + Square(y) - 1)
+ for the case a>0
- for the case a<0
and
tilt=arcsin((x-y*a)/(Square(x)+Square(y)))
# for the case a>0
tilt=arcsin((x+y*a)/(Square(x)+Square(y)))
# for the case a<0
tilt=arcsin(x)
# for the case a=0
All values are normalized to the earth's acceleration g (g=1).
The remaining unknown figure is the sign or direction of the acceleration a to get the correct result for the tilt. This could be derived from the motor control comparing the motor power during the last two control steps before this measurement.
When adapting these formulas for the tilt angle from accelerometer data, please care for the fact, that the accelerometers have different sign for dynamic and static acceleration. This fact is not yet considered in the above mentioned formulas. So the sign of the acceleration "a" must be inverted for the real measurements.
Actuator Control
My balance regulation is now a PID control. In a previous step I used a PD-control. PID is more stable than PD. For PID the angle must be integrated for use in the control equation. Up to now, no odometry (drive control measuring the turning of the wheels with wheel encoders) is implemented. This is planned as a next step.
Top of Page