The Joystick Controlled Ultrasonic Explorer

By Sivan Toledo
September 2006

This robot demonstrates two-way Bluetooth communication between a PC and the NXT.

The joystick contolled ultrasonic explorer     A screenshot of the radar screen on the computer

A video of the robot in action (20MB)

The robot is controlled by a NXT-G program that listens to Bluetooth messages that tell it what to do. Normally, the commands are movement commands. These commands control the speed of the robot, whether it will go straight or turn left or right, or whether it will stop. It can also receive a command to do a radar-style scan with the ultrasonic sendor. When it gets such a command, it stops moving, and performs a sequence of ultrasonic measurements while rotating the sensor. It sends these measurements, along with data about what angle the sensor was looking at, back to the PC. When the scan ends, the robot starts responding to movement commands again.

On the PC side, the program that controls the robot listens to joystick events. It translates these events to commands that it sends to the NXT via bluetooth. When the next sends an ultrasonic scan, the program displays the results on a radar-style display.

Structurally, the robot uses Brian Davis's JenToo chasis.

Technical details (and problem areas) for the NXT program: the program uses two My Blocks, one for the movement phases and one for the radar scans. The one for the movement uses three threads, one that listens for text commands (left, right, straight, stop, radar), one that listens to motor-speed commands (these come as numbers), and a third that actually controls the motors. The first two threads set variables that the third reads. The radar-scan block is simpler, using a simple counting loop. When I tried to run the radar scans in parallel with the other three threads, it didn't send any information to the PC (or very little). This is either because the NXT can't run 4 threads in parallel, or (more likely) that bluetooth-receive block prevented the radio from sending data. This is why I stop the movement (and the listening to incoming bluetooth messages) when the robot does the scans. If anybody knows of a way to send and receive without blocking, let me know.

Technical details of the PC program: Written in Java, uses a native library that I wrote to do the serial-port communication with the NXT, a libtary called JXInput to read joystick data, and SWT for the graphics. The part of the code that talks to the NXT is pretty complex, due to the need to receive and send messages concurrently. I'll post all the code once I clean it up a bit.

© 2006, Sivan Toledo