Skip to content

Instantly share code, notes, and snippets.

@tgoossens
Created November 21, 2012 10:27
Show Gist options
  • Save tgoossens/4124151 to your computer and use it in GitHub Desktop.
Save tgoossens/4124151 to your computer and use it in GitHub Desktop.
Evaulate Secure
private void createQueue() {
queue = new ArrayDeque<When<Predicate<RobotState>,Fn>>();
queue.push(when(isOnWhiteLine,driveLongBackward)); //if already on white line move backward
queue.push(when( and(isIdle, not(isOnWhiteLine)), driveForward)); //start driving forward
queue.push(when( and(isMoving, isOnWhiteLine), stopRobot)); //stop when white line is detected
queue.push(when( and(isIdle, isOnWhiteLine), driveLongForward)); // drive long forward
queue.push(when( isIdle, rotateClockWise)); //start rotating clockwise
queue.push(when( and(isMoving, isOnWhiteLine), stopRobot)); //stop rotating when white line detected
queue.push(when(isIdle, rotateLeft90)); //put perpendicular
}
protected IProcedure evaluateSecure(InputData inputData,
RobotState robotState) {
if (not(queue.isEmpty())) {
if (queue.peek().pred.apply(robotState)) {
queue.pop().fn.apply();
}
} else {
terminate();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment