1. New York City College of Technology
Submitted By:
Frantz St Valliere
SEGWAY NXT
CET4962
Applied Software Technology
FINAL PROJECT PAPER
Due date: May 4, 2012
Submission date: May 4, 2012
Submitted To:
Professor C. Sher-Decusatis
2. Frantz St Valliere
CET 4962
Professor Carolyn J. Sher DeCusatis
4/29/12
Segway NXT Robot
Legos, the king of building blocks, have made it possible for children to enjoy
building and creating cars, boats, or even people using building blocks. In fact, they have
become so famous; they even have a Star Wars cartoon show, as well as the game based on the
movie series. But is Lego blocks only for kids? Well of course, Legos made it possible for adults
to join in the fun (technically that is). Legos created the Lego Mindstorms. This package includes
the intelligence brick, which controls every motor or sensor connected to it. The sensors can
include an ultrasonic sensor, which can sense distances between objects. Also included is one
light sensor, which can sense light differences in the room. A push button sensor is utilized to
prevent the robot from bumping into objects near. A microphone sensor is used to test sound in
the room. The Mindstorms also include three motors to rotate wheels or create rotating arms. Of
course Legos have made it possible to give you all the possible pieces that come with the
Mindstorms. The come include with an instructional booklet to create a robot that utilizes all
parts. A creator can make different shapes and forms of the robot, making it endless possibilities.
Of course all the sensors mentioned before are not all. There are many other sensors not included
in the Mindstorms package (which in fact is already two hundred dollars). Some extra sensors
out there feature an IR sensor to sense push button commands on a programmed remote
controller. There is also an accelerometer which can control the robots acceleration and senses
three-axis of the robot. A compass sensor can sense the direction with the earth’s magnetic field.
3. All sensors can give an output to the user (which is on the LCD screen of the intelligence brick)
so the user can know any changes that need to be made.
One sensor that is notable to this project was the gyroscopic sensor. This sensor
was not created by Legos but by a third party company HiTechnic. This sensor (which was
original one hundred and ten dollars) was the key ingredient to the project because it specializes
in balancing. My project was the Segway.
FIGURE 1 – SEGWAY
Of course the NXT robot did not look exactly like the Segway shown in Figure 1
however the prime purpose to a Segway is balance. A Segway only balances on two wheels but
how? Wouldn’t the Segway fall forward or backward? A gyro sensor is what controls the
balance because it senses the orientation of the sensor, not the robot or the human riding a human
size Segway. The robot is controlled by the readings of the gyroscopic sensor. Whatever readings
provided will control how the motor rotates. In fact the best possible way to control how the
4. NXT robot moves is to program the NXT robot in Java. Originally, the idea was to use a light
sensor to balance the robot, however it
The NXT robot comes with flash software for kids to easily program how the
robot maneuvers provided by NI LabVIEW. This program is called NXT-G. This software can
optimize how it performs in competitions. The programs uses block by block GUI commands
which features how the robot should do what you want it to do and how long you want to do it.
This GUI base program is great for the younger audience. However, there are many ways to
program the NXT brick. Prior to this project, this class was introduced to Java (different to Java
Script). This programming language is the backbone to how the NXT will function. To write
programming code, we use Eclipse.
FIGURE 2 – ECLIPSE IDE TO CODE JAVA
Eclipse is the best utility to code in Java. However, it was somewhat a headache to get
Eclipse to link the NXT intelligence brick. First, step was to install the Java SDK in order to
compile and run on the NXT using Java. The next step was to download the Fantom drivers in
order for the computer to link the NXT robot to work on USB or Bluetooth. Last step, is to
5. download the LeJOS NXJ operating system. This operating system lives on Java programming.
Using the LeJOS operating system, we can flash the NXT intelligence brick to work with Java.
This will remove the NXT-G operating system and will be replaced with the LeJOS NXJ.
Flashing the intelligence brick can be done within Eclipse with the right files installed. If
successful, you can test the simplest program “Hello World.”
This will display “Hello World!” on the LCD screen. This result will earn the access
to other programming capabilities which of course will be the Segway program.
The Segway program is not as simple as the Hello World program. In fact we have to
incorporate all the sensors available to make the NXT robot work the way it should. In the
program, the sensors and motors have to be initialized. In the program we have two sensors and
two different motors. The robot uses the ultrasonic sensor to provide protection between the
robot and the item it approaches. To initiate the ultrasonic sensor we need to write this line of
code: UltrasonicSensor us = new UltrasonicSensor(SensorPort.S4);. This will activate the
sensor as well as the port connected to the NXT intelligence brick. The keyword new creates a
class for the ultrasonic sensor. That way in line 20 (if (us.getDistance() < 40)) we can use
the dot operator to manipulate the variable “us”. This is similar to C++ except in C++ we are
forced to created public and private variables in a class. Line 20 controls the distance between
//Lab_0_HelloWorld
import lejos.nxt.*;
public class HelloWorld
{
public static void main (String[]args)
{
System.out.printIn(“Hello World!”); //Displays the string on the screen
Button.waitForPress();//Button press ends the program
}
}
6. the ultrasonic sensor and an object. If the distance is less than 40cm then it will initiate whatever
is included in the “if” statement.
Line 13 (GyroSensor g = new GyroSensor (SensorPort.S1);), initiates the gyroscopic
sensor class. The GyroSensor class contains all it needs to provide the stability it needs to control
the robot’s balance. Thankfully, the code needed to define the class is already included. Every
add-on (the ultrasonic sensor, the gyroscopic sensor and the two motors) are defined in different
classes. Each one has their own class defined. Once compiled, and tested to ensure there are no
mistakes, the robot will indeed balance and move forward. It will back up and turn when a object
is near, and continue forward until it falls.