In this lab session we will try to make a self-balancing LEGO robot
inspired by Steve Hassenplug's origional Legway controlled by the RCX, .
Two examples of self-balancing robots controlled by the
NXT is Philippe Hurbain's NXTway, , and Brian Bagnall's balancing robot, .
Self-balancing robot with light sensorUse the LEGO model suggested by Phillippe Hurbain, , and the java program from Brian Bagnall,  to start experiments with a self-balancing robot. Under the headline Usage Phillippe Hurbain describes under which conditions the NXTway works best. Try to follow some of his advices.
Choice of parameters on-the-flyDuring the development of a balancing robot a lot of adjustment of constants is needed. This can be done by editing the Java source code, compile and transfere it to the NXT before the next trial. To speed up this trial and error process a wireless communication could be established between PC and NXT so the constants of the program can be changed on-the-fly.
An exanple of such a pair of programs, one program for the PC and one for the NXT, is PCcarController.java and BTcontrolledCar.java. The PCcarController is a GUI that runs on the PC. It establish a Bluetooth connection to the NXT and use wireless communication to drive a simple car with different values of power to the motors and for different durations. The BTcontrolledCar waits for a connection to be established, receives the values of power and duration and make the car drive controlled by the received values. When the car stops BTcontrolledCar reads the tacho counters (the Car class from Lesson 2 has been extended with a method counter, Car.java) and sends the value for display in the GUI.
A similar setup can be used to make it possible to choose parameters for the balance controller from a GUI on the PC.
Self-balancing robots with color sensorThe NXT Segway with rider, , use a color sensor to measure the position of the robot. Try that as an alternative to the light sensor. And mayby the physical structure of this robot is better that the structure in  and . Maybe it is worth to try it.
Self-balancing robots with gyro sensorBoth the robots in  and  use the light sensor to measure the tilt of the robot by measuring the distance to the surface. In  and  other more reliable types of sensors are used to measure the tilt of the robot during balancing. One such sensor is the HiTechnic gyro sensor, , .
Investigate the readings from the gyro sensor and how they relate to the motion of the gyro sensor. As a simple tool for such an investigation use the program GyroTest.java. Estimate the offset of the gyro sensor, , , when the sensor is not moving and experiment with the gyro sensor drifts e.g. when motors are activated.In  it is described how an angle can be obtained from the gyro sensor readings. This can e.g. be implemented as in this NXC routine from :
An explanation of the calculations performed in this routine can be found in  and . Based on this implement a self-balancing robot by means of data from the gyro sensor.