Java Reference
In-Depth Information
else if
(numMoveSteps > 0.0) {
// executes a movement step
if
(numMoveSteps < 1.0)
robotPos.rototrans(numMoveSteps*moveStep*orientation,
0.0, 0.0);
else
robotPos.rototrans(moveStep*orientation, 0.0, 0.0);
// updates the robot's position
robot.writePosition(robotPos);
// repaints the graphical interface
environment.repaint();
numMoveSteps-
#
1.0;
}
else
{
// the task has been fulfilled
running
#
false
;
writeOut("PLATFORM ARRIVED");
}
}
}
Class
Laser
extends class
Device
to implement the dynamics of the tele-
meter device. It executes four tasks: (1) positions the rotary tower at a given
direction; (2) reads a single distance measure; (3) detects obstacles in front
of the robot; (4) scans the surrounding environment and returns the list of
distance measures.
public class
Laser
extends
Device{
int
orientation
#
1; // 1: clockwise -1: otherwise
double
rotStep
#
1.0; // one degree
double
numSteps
#
0; // number of rotation steps
boolean
detect
#
false
;
// true if the laser executes a detect task
boolean
scan
#
false
;
// true if the laser executes a scan task
Measure detectMeasure
#
null
;
public void
executeCommand(String command) {
if
(command.indexOf("ROTATETO") > -1) {
rotStep
#
4.0;
double
direction
#
Math.abs(Double.parseDouble(
command.trim().substring(9).trim()));
while
(direction < 0.0)
direction
!#
360.0;
while
(direction > 360.0)
direction-
#
360.0;
double
dirDiff
#
direction - Math.toDegrees
(localPos.getT());