Abstract Robot Functions
Introduction:
Every Controller file must have dual functionality, in that it must run on both the simulator and the real robot. As such, there must be a collection of methods that provide basic services (e.g., start motor, get sensor value) with different implementations to run on the two platforms. This collection of basic services is provided to you by the AbstractRobot interface.The process for using these methods in the Controller file is as follows:
1.) Create an AbstractRobot reference as a private variable in your Controller class. For example, private AbstractRobot myRobot;
2.) Within the initController (AbstractRobot r) method, assign r to myRobot so you can access it from anywhere in your Controller class.NOTE: public abstract void initController(AbstractRobot r); is required by the Controller Interface3.) Implement ALL of the methods in the Controller File. Much of your code will be calls to the AbstractRobot's methods:myRobot.myFunction (see the sample Controller file for real examples)
List of Constants:
The List of Functions:
CONSTANTS: DESCRIPTION: 1.) BACKWARD .../** constant for direction of single motor (to move backwards) */ 2.) FORWARD .../** constant for direction of single motor (to move forwards )*/ 3.) MOTOR_A .../** constant designating MOTOR A */ 4.) MOTOR_C .../** constant designating MOTOR C */ 5.) S1 .../** constant designating Sensor 1 */ 6.) S2 .../** constant designating Sensor 2 */ 7.) S3 .../** constant designating Sensor 3*/
FUNCTION SIGNATURE: DESCRIPTION: - - - - MOVING THE ROBOT - - - - 1.) public abstract void forward(); /**
* Sets the robot moving forwards. This will continue until some other
* method is called to stop it.
*/2.) public abstract void forward(int time); /**
* Makes the robot move forwards for the given amount of time.
* @param time the time in milliseconds
*/3.) public abstract void backward(); /**
* Sets the robot moving backwards. This will continue until some other
* method is called to stop it.
*/4.) public abstract void backward(int time); /**
* Makes the robot move backwards for the given amount of time.
* @param time the time in milliseconds
*/5.) public abstract void singleMotor(int motor, int direction); /**
* Moves the robot to the right or to the left - as a corrective action
* when moving forward (or backward). This will continue until some
* other method is called to stop it.
* Created by: Simon Zienkiewicz
*
* @param motor is the motor constant
* (AbstractRobot.MOTOR_A or AbstractRobot.MOTOR_C);
* @param direction is the direction constant
* (AbstractRobot.BACKWARD or AbstractRobot.FORWARD )
*/6.) public abstract void singleMotor(int motor, int direction, int time); /**
* Moves the robot to the right or to the left - as a corrective action
* when moving forward (or backward) - for the given amount of time.
* Created by: Simon Zienkiewicz
*
* @param motor is the motor constant
* (AbstractRobot.MOTOR_A or AbstractRobot.MOTOR_C);
* @param direction is the direction constant
* (AbstractRobot.BACKWARDS or AbstractRobot.FORWARDS)
* @param time the time in milliseconds
*/7.) public abstract void stopMoving(); /**
* Stops all motors immediately
*/- - - - READING THE ROBOTS SENSORS - - - - 8.) public abstract int getSensor1(); /**
* Get the current reading of sensor 1.
*
* @return the current value
*/9.) public abstract int getSensor2(); /**
* Get the current reading of sensor 2.
*
* @return the current value
*/10.) public abstract int getSensor3(); /**
* Get the current reading of sensor 3.
*
* @return the current value
*/11.) public abstract boolean[] getTouchSensorStatus(); /**
* Gets an array of boolean values for the touch sensors
* Created by: Simon Zienkiewicz
*
* @return boolean values of the status of the sensors
*/- - - - HANDLING THE ROBOT'S LCD - - - - 12.) public abstract void displayNumberLCD(int num); /**
* Display a number on the LCD.
*
* Created by: Simon Zienkiewicz
* @param num the number to display
*/13.) public abstract void clearLCD(); /**
* Clears the LSD display
* Created by: Simon Zienkiewicz
*/14.) public abstract void displayTextLCD(String word); /**
* Display text on the LCD
* Created by: Simon Zienkiewicz
*
* @param word, string to display
*/- - - - HANDLING THE ROBOT'S PROPERTIES - - - - 15.) public abstract void setMotorPower(int power); /**
* Sets the power of the robot's motors
* Created by: Simon Zienkiewicz
*
* @param power, the desired power
*/16.) public abstract int getMotorPower(); /**
* Gets the set power of the robot's motors
* Created by: Simon Zienkiewicz
*
* @return the power of the motor 0-7
*/17.) public abstract int getVoltage(); /**
* Gets the voltage of the RCX battery in MilliVolts
* Created by: Simon Zienkiewicz
*
* @return int voltage in the battery of the RCX
*/18.) public abstract void activate(); /**
* Activates the light and touch sensors
* Created by: Simon Zienkiewicz
*
*/19.) public abstract void playTune(int frequency, int duration); /**
* Plays a sound
* Created by: Simon Zienkiewicz
*
* @param frequency, the sound frequency
* @param duration, the duration of the sound in milliseconds
*/20.) public abstract void beep(); /**
* Makes the robot beep
*/- - - - HANDLING TIMER/TIMING EVENTS- - - - 21.) public abstract int createTimer(int time); /**
* Creates a timer
* Created by: Simon Zienkiewicz
*
* @param time, the delay for the timer
* @return int, the timer identifier
*/22.) public abstract void startTimer(int num); /**
* Starts the requested timer
* Created by: Simon Zienkiewicz
*
* @param num, the timer identifier
*/23.) public void stopTimer(int num); /**
* Stops the requested timer
* Created by: Simon Zienkiewicz
*
* @param num, the timer identifier
*/24.) public void stopAllTimers(); /**
* Stops all timers
* Created by: Simon Zienkiewicz
*
*/25.) public int getDelay(int num); /**
* Gets the delay from the requested timer
* Created by: Simon Zienkiewicz
*
* @param num, the timer identifier
* @return int, the timer delay
*/26.) public void setDelay(int num, int time); /**
* Sets the delay for the requested timer
* Created by: Simon Zienkiewicz
*
* @param num, the timer identifier
* @param time, the new delay time
*/27.) public abstract void pause(int num); /**
* Pauses the simulation
* Modified by: Simon Zienkiewicz
*
* @param num, the number of milliseconds
*/
This page was last updated by Benoit Larochelle on September 23, 2004