import josx.platform.rcx.*; /** * Class that represents the roverbot * robot (has two motors, one on the left * and one on the right) * @author Barb Ericson ericson@cc.gatech.ed */ public class Roverbot { ///////////// fields ////////////// private Motor leftMotor = Motor.A; private Motor rightMotor = Motor.C; private int powerLevel = 7; ///////////// Constructor //////// /** Constructor take takes no * arguments */ public Roverbot() {} /** * Constructor that takes the left * motor and right motor * @param left the left motor * @param right the right motor */ public Roverbot(Motor left, Motor right) { leftMotor = left; rightMotor = right; } /** * Method to make the robot go forward * for the passed amount of time (in * milliseconds) */ public void forward(int numMillisecs) throws Exception { leftMotor.setPower(powerLevel); rightMotor.setPower(powerLevel); leftMotor.forward(); rightMotor.forward(); Thread.sleep(numMillisecs); leftMotor.flt(); rightMotor.flt(); } /** * Method to make the robot go backward * for the passed amount of time (in * milliseconds) */ public void backward(int numMillisecs) throws Exception { leftMotor.setPower(powerLevel); rightMotor.setPower(powerLevel); leftMotor.backward(); rightMotor.backward(); Thread.sleep(numMillisecs); leftMotor.flt(); rightMotor.flt(); } /** * Method to turn the robot to the * right for the passed number * of milliseconds * @param numMillisecs the number of * milliseconds to turn */ public void turnRight(int numMillisecs) throws Exception { leftMotor.setPower(powerLevel); leftMotor.forward(); rightMotor.stop(); Thread.sleep(numMillisecs); leftMotor.flt(); } /** * Method to turn the robot to the * right for the passed number * of milliseconds * @param numMillisecs the number of * milliseconds */ public void turnLeft(int numMillisecs) throws Exception { rightMotor.setPower(powerLevel); rightMotor.forward(); leftMotor.stop(); Thread.sleep(numMillisecs); rightMotor.flt(); } /** * Method to spin the robot left * @param numMills the number of * milliseconds */ public void spinLeft(int numMills) throws Exception { rightMotor.setPower(powerLevel); rightMotor.forward(); leftMotor.setPower(powerLevel); leftMotor.backward(); Thread.sleep(numMills); rightMotor.flt(); leftMotor.flt(); } /** * Method to spin the robot right * @param numMills the number of * milliseconds */ public void spinRight(int numMills) throws Exception { leftMotor.setPower(powerLevel); leftMotor.forward(); rightMotor.setPower(powerLevel); rightMotor.backward(); Thread.sleep(numMills); rightMotor.flt(); leftMotor.flt(); } /** * Method to zig-zag the robot * turn left and then right * @param numMills the number milliseconds * @param numZZ the number of zig and zags */ public void zigZag(int numMills, int numZZ throws Exception { leftMotor.setPower(powerLevel); rightMotor.setPower(powerLevel); leftMotor.forward(); Thread.sleep(numMills); rightMotor.forward(); Thread.sleep(numMills); leftMotor.flt(); rightMotor.flt(); } public static void main(String[] args) { try { Roverbot robot = new Roverbot(); robot.forward(3000); robot.spinLeft(3000); } catch (Exception ex) { TextLCD.print ("error"); } } }