package RCX3.docs; import josx.platform.rcx.Motor; import java.lang.Math; /** *Manages the motors. */ public class Pilot { public static final Motor engine = Motor.A;//movement motor public static final Motor steering = Motor.B;//steering motor /** *Initializes motors. */ public static void init(){ engine.setPower(7); steering.setPower(7); }//init /** *Turns the RCX by a given number of degrees. *@param direction True for right, False for left. *@param degrees The number of degrees to turn. */ public static void turnInPlace(boolean direction, int clicks){ int initPos = Senses.angleSensor.readValue(); stopAll(); if (direction){//if turning right steering.backward(); while(Senses.angleSensor.readValue() > initPos - clicks){ ; } steering.stop(); } if (!direction){//if turning left steering.forward(); while(Senses.angleSensor.readValue() < initPos + clicks){ ; } steering.stop(); } }//turnInPlace /** *Stops all motors. */ public static void stopAll(){ steering.stop(); engine.stop(); }//stopAll /** *Turn right for specified time, 0 for infinite. */ public static void turnRight(int time){ steering.backward(); if (time > 0){ try{ Thread.sleep(time); }catch (InterruptedException ie){} steering.stop(); } }//turnRight /** *Turn left for specified time, 0 for infinite. */ public static void turnLeft(int time){ steering.forward(); if (time > 0){ try{ Thread.sleep(time); }catch (InterruptedException ie){} steering.stop(); } }//turnLeft /** *Go forward for specified time. *@param time Milliseconds to go forward, 0 for infinite. */ public static void forward(int time){ engine.forward(); if (time > 0){ try{ Thread.sleep(time); }catch (InterruptedException ie){} engine.stop(); } }//forward }