dLife Robotics Example 1
dLife Robotics Example 1
public class HemissonApproach extends Controller {
private HemissonProximitySensor hps;
private HemissonDifferentialDrive hdd;
public void startUp(Robot robot) {
hps = new HemissonProximitySensor();
robot.addDevice(hps);
hdd = new HemissonDifferentialDrive();
robot.addDevice(hdd);
}
public void step() {
int maxFront = hps.getMaximum(HemissonProximitySensor.FRONT_GROUP);
if (maxFront < 15) {
hdd.translate(0.5); // forward at half speed.
}
else {
hdd.translate(0); // stop.
}
}
}
The example below, for use with the ControlCenter, will cause a Hemisson robot to move forward until it is near an obstacle. In order to be used with the ControlCenter this class extends the dlife.robot.Controller class and provides two methods:
•startUp: This method is executed once when the ControlCenter’s Start Up button is clicked. It creates objects representing the Hemission’s proximity sensors and its differential drive effector and adds them to the robot.
•step: This method is executed repeatedly by the ControlCenter after the Run button is clicked. It checks the values of the proximity sensor and decides if the robot should continue moving or stop.