Page 246 - The Definitive Guide to Building Java Robots
P. 246
Preston_5564C07.fm Page 227 Monday, September 26, 2005 5:38 AM
CHAPTER 7 ■ NAVIGATION 227
Figure 7-5. A class diagram of NavStamp and Data structures
Before I get data from the microcontroller, I decided to create some data structures to hold
this information. Those structures include the following:
• SonarReadings: To hold sonar data
• IRReadings: To hold infrared data
• DistanceReadings: To hold combination data
• GPSReadings: To hold GPS longitude and latitude data
All the readings discussed next will be a ~ (tilde)-delimited string. While having a byte
array is just as useful for these numbers, the returns come from either a web serial port or a
standard serial port. If it was just coming from a serial port, I could use a byte[], but byte
streams over the Web are less convenient.
All readings also have public fields. I avoid the typical Java setter/getter convention
because I want to access these data structures like I access java.awt.Point.
In SonarReadings (see Example 7-3), the constructor takes a string of value
Sonar1~Sonar2~Sonar3.
97022d2480fe4a63cfdfa123a6e70098