dLife Robotics Example 2
dLife Robotics Example 2
The example below, for use as a stand-alone Java program, will cause a Hemisson robot to move forward until it is near an obstacle. The stand-alone program does not have the benefit of the ControlCenter’s graphical interface, but allows for the greater flexibility and more precise control often needed for research applications.
public class HemissonApproachStandAlone {
public static void main(String[] args) throws InterruptedException {
Hemisson hemi = new Hemisson();
hemi.startUp(); // will ask user to pick Hemisson
HemissonProximitySensor hps = new HemissonProximitySensor();
hemi.addDevice(hps);
HemissonDifferentialDrive hdd = new HemissonDifferentialDrive();
hemi.addDevice(hdd);
int maxFront = hps.getMaximum(HemissonProximitySensor.FRONT_GROUP);
hdd.translate(0.5); // forward at half speed
while (maxFront < 15) {
Thread.sleep(50);
maxFront = hps.getMaximum(HemissonProximitySensor.FRONT_GROUP);
}
hdd.translate(0); // stop
hemi.shutDown(); // close connection.
}
}