Lego Mindstorms NXT Balancing robot Ondfej Herman, Ondfej Hlousa, Vladislav Malynyc May 11, 2014 Abstract The aim of our project is to design a Segway-like, self-balancing robot, using Lego NXT 2.0. To achieve the best results a gyroscope is usually used. However, to make the project more interesting (and because we don't have a gyroscope), we will use two ADXL312 accelerometers to derive the orientation of the robot in space. 1 Overview The gyroscope is an instrument which measures the change in angular velocity. To approximate the same information using two accelerometers, which measure the change in linear velocity, we used the following method. One of the accelerometers is aligned with the axis of the wheel shaft, so the rotation of the robot around this axis has no effect on the acceleration data obtaned from this sensor. On the other hand, the second sensor, which is mounted near the top of the robot, is influenced by the rotation - we can take the difference of these accelerations and obtain the rate of rotation around the wheels. In theory, this information is enough to keep the robot upright, but in practice the solution diverges very fast and it is necessary to measure the orientation of the robot directly. The accelerometers have three axes, so the angle respective to the gravitational force vector can be easily calculated. Software controller manages robot by the PID control scheme. 2 Implementation The project targets the Lejos firmware, which implements a rich subset of the Java platform on the Lego Mindstorms. Apart from ROBOTC, this seems to be the only firmware which supports the 100 kbaud I2C mode. The regular firmware can only communicate at 9600 baud. At this speed, the link budget is exhausted very soon. Another reason for using Lejos is its use of a regular and widely used language. 2.1 Accelerometer interface We have used two ADXL312 accelerometers connected to the NXT brick using the serial I2C interface. The final schematic can be seen in the Figure 3. 1 Figure 1: Detail of accelerometer ADXL312 The circuit is split into three subboards: two of them carry the accelerom-eters themselves and the third board contains auxiliary power and signal conditioning circuitry: the 4.5 V from the NXT is regulated down to the 3.3 V needed by the integrated circuits using a Zener diode. The I2C pullups are also located on this board. Both of the accelerometers are connected to the same I2C bus of the NXT, one of them is configured with an alternate address. The only other components located on these boards are the power supply bypassing capacitors. 2.2 Software controller The core functionality is provided by two threads: the MotorThread and the SensorThread. The SensorThread configures the accelerometers and reads and preprocesses their data, which is then stored in variables shared with the MotorThread. This thread executes the control loop and interfaces with the motors. Meanwhile, the main thread waits for a keypress, after which the program is terminated. 2.3 Evaluation We didn't manage to satisfy our original specification. The accelerometer interface works well, but the robot isn't able to keep the balance for more than a short while. We believe this is due to the mechanical imprecision in the motor gearing and the dependence of their speed on the remaining energy stored in the batteries. This, combined with the low power and speed provided by the motors, makes finding the constants necessary for the proper operation of the PID control scheme difficult, if not impossible. 2 Figure 2: The upper part of "Segway" with accelerometer 3 Team • Ondřej Herman - team leader, idea and physical construction of accelerometer cicuit, implementation of series of (un)balancing methods, testing, project report • Ondřej Hlouša - implementation of series of (un)balancing methods, testing, project report • Vladislav Malynyč - project abstract, testing, presentation • Adam Třešňák - no communication from his side during whole semester Bibliography 1. Maia R. Bageant: Balancing a Two-Wheeled Segway Robot, Massachusetts institute of technology, June 2011. 2. HTWay - A Segway type robot, online at http://www.hitechnic.com/blog/gyro-sensor/htway/, 2010. 3. Dennis Jin: Development of a Stable Control System for a Segway, Royal Institute of Technology, July 2013. 4. NXT SEGWAY with Hitechnic Gyro Sensor, online at forum http://www.robotc.net/forums/viewtopic.php?p=11549, 2010. 5. PID controller, online at http://en.wikipedia.org/wiki/PID.controller, May 2014. 3 1 D? I Distribution board VDDio GND NC ADXL350 RESERVED nc o q. INT1 >SCL/SCLK g© RESERVED NC INT2 < o t/i sou l/l l/l c XT ! +*c: C3 O.luF lOuF VDDio NC NC g >SCL/SCLK S, NC > GND ADXL350 RESERVED INT1 RESERVED INT2 < o l/l Q Q U [/I l/l C "P" ; +1 c? O.luF 10uF Accelerometer board A Figure 3: Accelerometer interface schematic diagram Accelerometer board B