Page 247 - The Definitive Guide to Building Java Robots
P. 247
Preston_5564C07.fm Page 228 Monday, September 26, 2005 5:38 AM
228 CHAPTER 7 ■ NAVIGATION
Example 7-3. SonarReadings.java
package com.scottpreston.javarobot.chapter7;
import java.io.Serializable;
public class SonarReadings implements Serializable {
public int left = 0;
public int center = 0;
public int right = 0;
public SonarReadings() {
// default
}
public SonarReadings(String readings) {
// sample input "11~22~33"
String[] values = readings.split("~");
left = new Integer(values[0]).intValue();
center = new Integer(values[1]).intValue();
right = new Integer(values[2]).intValue();
}
public String toString() {
return "left=" + left + ",center=" + center + ",right=" + right;
}
}
The second data structure is for the two sharp infrared detectors above and in front of the
wheels. The constructor takes a string of value Ir1~Ir2. See Example 7-4.
Example 7-4. IRReadings.java
package com.scottpreston.javarobot.chapter7;
import java.io.Serializable;
public class IRReadings implements Serializable {
public int left = 0;
public int right = 0;
public IRReadings() {
// default
}