Page 97 - The Definitive Guide to Building Java Robots
P. 97
Preston_5564C03.fm Page 78 Wednesday, October 5, 2005 7:21 AM
78 CHAPTER 3 ■ MOTION
while (true) {
try {
pt.moveUp();
} catch (Exception e) {
break;
}
}
// tilt down
while (true) {
try {
pt.moveDown();
} catch (Exception e) {
break;
}
}
// reset head
pt.reset();
// close serial port
sPort.close();
} catch (Exception e) {
// print stack trace and exit
e.printStackTrace();
System.exit(1);
}
}
}
Section Summary
So now you can move your robot and position its camera/eye(s). Moving it gracefully may still
take some experimenting, but we created some classes that provide the foundation for panning
and tilting and other similar servo configurations.
In this section, I created the following two classes:
• PanTilt.java: The base class for pan and tilt operations
• PanTiltSpeed.java: This is extended from PanTilt to provide smoother movement from
one position to another.
While this will function adequately for most tasks, you still might want smoother move-
ment or need more servos to move. In such cases, you may want to try the Lynxmotion SSC-32
and then implement another protocol besides the SSCProtocol so you can move more than
one servo with a single serial command. I’ll discuss that and more in the next section.
3.4 Advanced Servo Control
From the last example, which showed pan and tilt with speed and error control, you can see
that the control of a few servos can get quite complicated. As I get ready to discuss robotic arms