NXT Programming


Lesson 5

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, [2]. Two examples of self-balancing robots controlled by the NXT is Philippe Hurbain's NXTway, [3], and Brian Bagnall's balancing robot, [4].

Self-balancing robot with light sensor

Use the LEGO model suggested by Phillippe Hurbain, [3], and the java program from Brian Bagnall, [4] 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-fly

During 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 sensor

The NXT Segway with rider, [7], 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 [3] and [4]. Maybe it is worth to try it.

Self-balancing robots with gyro sensor

Both the robots in [2] and [3] use the light sensor to measure the tilt of the robot by measuring the distance to the surface. In [5] and [6] 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, [8], [9].

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, [9], [10], when the sensor is not moving and experiment with the gyro sensor drifts e.g. when motors are activated.

In [9] 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 [6]:

An explanation of the calculations performed in this routine can be found in [9] and [6]. Based on this implement a self-balancing robot by means of data from the gyro sensor.


References


Last update: 5-3-15