Page 250 - The Definitive Guide to Building Java Robots
P. 250
Preston_5564C07.fm Page 231 Monday, September 26, 2005 5:38 AM
CHAPTER 7 ■ NAVIGATION 231
// get ir
public IRReadings getIR() throws Exception {
String readings = execute(new byte[] { CMD_INIT, CMD_IR }, 75);
return new IRReadings(readings);
}
// get sonar
public SonarReadings getSonar() throws Exception {
String readings = execute(new byte[] { CMD_INIT, CMD_SONAR }, 75);
return new SonarReadings(readings);
}
// get both ir and sonar
public DistanceReadings getSonarIR() throws Exception {
String readings = execute(new byte[] { CMD_INIT, CMD_IR_SONAR }, 200);
return new DistanceReadings(readings);
}
// get gps longitude
public String getGpsLongitude() throws Exception {
byte[] readings = execute2(new byte[] { CMD_INIT, CMD_GPS_LON }, 5000);
return Utils.toAscii(readings);
}
// get gps latitude
public String getGpsLatitude() throws Exception {
byte[] readings = execute2(new byte[] { CMD_INIT, CMD_GPS_LAT }, 5000);
return Utils.toAscii(readings);
}
// get both longitude and latitude
public GpsReading getGps() throws Exception {
String lon = getGpsLongitude();
String lat = getGpsLatitude();
return new GpsReading(lon, lat);
}
// get diagnostic signal
public boolean diagnostic() throws Exception {
String s = execute(new byte[] { CMD_INIT, CMD_DIAG }, 80);
if (s.equals("1~2~3")) {
return true;
}
return false;
}