// ForwardBehavior.java // // A behavior for the LeJOS behavior-based approach. Drives the robot forward. // // Simon Parsons // 17th October 2013 // // Based on an example at www.lejos.org import lejos.robotics.subsumption.*; import lejos.nxt.*; // Structure follows the basic design pattern for a behavior. public class ForwardBehavior implements Behavior{ public boolean suppressed; private StandardRobot robot; public ForwardBehavior(StandardRobot r){ robot = r; } // Behavior is always ready to take control public boolean takeControl(){ return true; } public void suppress(){ suppressed = true; } // Start driving and then yield (for a non-busy wait). If // suppressed, then stop the motors and quit. public void action(){ suppressed = false; robot.startMotors(); while(!suppressed){ Thread.yield(); } robot.stopMotors(); } }