// AvoidBehavior.java // // A behaviour for the LeJOS behavior-based approach. // Backs up and turns if it finds an obstacle. // Based on the original code by Simon Parsons, 2013. // // Terry Payne // 6th October 2017 // import lejos.robotics.subsumption.Behavior; public class AvoidBehaviour implements Behavior{ public boolean suppressed; private SimpleRobot robot; public AvoidBehaviour(SimpleRobot r){ robot = r; } public void suppress(){ suppressed = true; } // Back up, turn and then quit safely by stopping the motors. Since this // is meant to be a short, high priority, behaviour, it doesn't do being // suppressed. public void action(){ robot.reverseMotors(); try{ Thread.sleep(2000); } catch(Exception e){ } robot.turnMotors(true); try{ Thread.sleep(2000); } catch(Exception e){ } robot.stopMotors(); } // Take control if the robot hits something public boolean takeControl(){ return (robot.isLeftBumpPressed() || robot.isRightBumpPressed()); } }