Page 68 - The Definitive Guide to Building Java Robots
P. 68
Preston_5564C02.fm Page 49 Wednesday, September 14, 2005 5:42 AM
CHAPTER 2 ■ SERIAL COMMUNICATION 49
main:
serialIn(0) = 0
SERIN 0,84,1000,main,[STR serialIn\3\"!"]
PAUSE 100
LOOKDOWN serialIn(0),[100,101],serialIn
BRANCH serialIn,[test1, test2]
SEROUT 1,84,["none", CR]
PAUSE 5
GOTO main
test1:
SEROUT 1,84,["a"]
GOTO main
test2:
SEROUT 1,84,["b"]
GOTO main
By copying this code to your BASIC Stamp, to gain complete access of your now wireless
robot, all you need to do is change your serial port ID.
2.7 Chapter Summary
My goal for this chapter was to introduce you to using the Java Communications API to talk
with your microcontroller. Hopefully, you now know how to do this and a little bit more.
In section 2.0, I created ListOpenPorts.java. This class showed you how to iterate through
all the communications ports to get the serial ports with a specific com ID in the port name. I
also added a Utils class that will allow me to call the Thread.sleep function while catching the
exception.
In section 2.1, I created the JSerialPort interface and StandardSerialPort. The interface
provides a standardized behavior for all serial ports, including the WebSerialClient discussed
in section 2.3. The StandardSerialPort class provides for simpler access to the com port API for
our usage with robotics.
In section 2.2, I created a resource pool of StandardSerialPorts so that these ports could be
accessed concurrently in a multithreaded way.
In section 2.3, I created a way to access the serial port over the Internet with the WebSerialPort,
webcom.jsp, and WebSerialClient.
In section 2.4, I connected to the Basic Stamp microcontroller.
In section 2.5, I created the JController interface and Controller. The interface provides
standardized behavior for all controllers and the Controller is an abstract superclass that
provides functionality for all Parallax controllers being used in this book.
Finally, in section 2.6 I showed you an example BASIC Stamp program that allows for
Bluetooth wireless access to your microcontroller from a serial port provided by a Bluetooth
adapter.
In the next chapter, we will build on serial communication and model more robot compo-
nents to get the robot to move. We’ll work with legged robots, wheeled robots, robotic arms,
and some other types of robotic controllers.