Page 110 - The Definitive Guide to Building Java Robots
P. 110
Preston_5564C03.fm Page 91 Wednesday, October 5, 2005 7:21 AM
CHAPTER 3 ■ MOTION 91
Figure 3-12. A class diagram of classes in section 3.5
Code Objectives
The objective in this example is to create a simple model of a robot arm.
Code Discussion
The fields in this class are mostly static constants that will define the range of motion of its two
axes: the shoulder and elbow. Of the remaining fields, ssc of type MiniSSC is the worker, and
shoulderPos and elbowPos are in the class to maintain state.
The constructor of the class takes the JSerialPort, and the move() method is just a pass-
through to the MiniSSC.move() method.
The two methods, shoulder() and elbow(), take input parameters as positions from 0 to 255
for the respective limbs, and the rest() method moves both the shoulder and elbow to their
respective rest positions.
■Note If you use this class, you may find the movement rather fast and jerky. To slow it down and make it
smooth, look ahead to the discussion of the ComplexArm class.
Finally, in main() I just move the arm to its rest position, then to another position, and
then close the serial port. (See Example 3-15.)