|
|
In General We succeeded to build a robot, using the Lego Mindstorms Robotics Invention System, that is able to control its balance. The standard light sensor is the only sensor we used and we programmed the RCX (which is the Mindstorms processor) with Lejos, the Java environment for the RCX.
MPEG4 - movie (QuickTime) AVI (+divX) - movie
History The most famous balancing robot is the nBot, designed by David P. Anderson, who is the director of the Geophysical Imaging Laboratory at Southern Methodist University in Dallas (http://www.geology.smu.edu/~dpa-www/robo/nbot/). The two-wheeled award-winning nBot is able to balance as well as drive and navigate. His website gives an overview of several related projects.
Steve Hassenplug has built the LegWay, which is a similar robot built with Lego Mindstorms Robotics Invention System and 2 Electro-Optical Proximity Detectors (http://www.teamhassenplug.org/robots/legway/). This one is able to balance and to follow a line. So what difference does our robot make? We use a Java environment (slower software response?); we intend to focus on the fact that certain Java environments are suitable for real-time applications. Another difference is that we do not use any extra component; we cope with the limited resolution of the standard light sensor we use (a mirror will do the trick). At the other hand, the LegWay robot construction is more unstable than ours.
Requirements and construction Following things were needed to construct our LegoBot:
We have constructed a reasonably unstable robot using LEGO (note that the RCX module is unstable because of the batteries at the backside).
The light sensor is attached to an arm to increase the variation of the distance to the mirror. It is attached in a way that the angle between the sensor and the robot is easily adaptable by humans (although that was the intention ; ) )
Measurement How does the sensor work? Why a mirror? The standard light sensor from the Mindstorms kit has got a red LED and an eye that just measures light intensity. The software translates the intensity into percentage with a granularity of 1%. On a normal surface (such as wood or paper) and in daylight there is a range of less than 10%, which is useless. Only on a mirror, the emitted light is reflected into the eye, which broadens the range.
Because of the reflection of the mirror, the angle of the sensor has a high influence on the intensity measurement. Which values are measured in which situations? The sensor measures a maximum value (70) when it is placed 4 mm from and perpendicular to the mirror. When we turn the sensor, the value decreases to a minimal value at 45° that depends on the environmental light. When we turn it more than 45°, the value increases again because of the reflection properties of the mirror. Distance has a minor influence. Robot angle versus light intensity measurement? Starting from the equilibrium point, our robot could fall 20° forward and 40° backward. In our first experiments, we tuned the position of the sensor perpendicular to the mirror at the equilibrium point, which was useless because it is not easy to deduce whether the robot is falling backward or forward. So at a first stage, we always try to tune the position of the sensor to a light measurement in the middle of the range. The graph below depicts the relation between the robot angle and the light intensity measurement, after tuning. We choose an angle of 0° in the equilibrium point and negative values when it falls forward. The blue line is a situation in daylight, the red one with neon light.
How does the program use the measurements? Filtering noise? During balancing, each program cycle the light intensity is measured. This measurement could be subjected to noise. To filter this noise, we use a moving average filter. averagen = (averagen-1 + sensorvaluen) / 2 and average0 = sensorvalue0 This filter introduces a slower reaction time. Each cycle, the average is used to control the robot motors, which keep the robot in balance.
The algorithm The program starts with a calibration procedure. This is inevitable because the range (and therefore the optimal equilibrium sensor value in the middle of the range) highly depends on the light in the environment. So during calibration, the sensor value at the equilibrium point is set. You can adjust the angle between the sensor and the robot manually so that the equilibrium sensor value is in the middle of the range. Then the balancing algorithm starts. During balancing, a program loop is executed continuously (in between each loop there is a pause of 20 ms). Each cycle the light intensity moving average is measured and calculated. What we need is an adequate reaction of the program that makes the motors keep the robot in balance.
We split the light intensity range around the calibrated equilibrium point into 3 zones:
The robot is in zone A when it measures an average value that does not deviate more than x percentage from the equilibrium value. The robot is in zone B when it measures an average value that deviates between x and x+y percentage from the equilibrium value. The robot is in zone C when it measures an average value that deviates more than x+y percentage from the equilibrium value.
To keep things simple, we assume that there is a linear relation between the robot angle and the measured light intensity around the calibration point. Note that the robot tends to fall slower forward than backward (because of the batteries). During balancing, it is still possible to adjust x and y. The optimal values for x and y depend on the calibrated value and the environmental light. Typical values are x = 4, y = 4 or x = 3, y = 5.
Results for the time being. As shown in the movie, the Lego robot is able to balance for a period of minutes. The definition of a zone D, in which the motor power is higher than 0, could be the next thing to experiment with.
The program The program code is shown below. The flat loop structure does not really support parallel execution nor time control. Use the Timer and/or Behavior class to realise that. Note that no objects are used inside the loops to avoid memory overflow. If there is a need to, use the Recycling classes.
Contact Any questions? Feel free to contact joris |DOT| maervoet |AT| kahosl |DOT| be Flemish company interested in embedded hardware/software? ADVIES |