josx.robotics
Class RotationNavigator

java.lang.Object
  extended byjosx.robotics.RotationNavigator
All Implemented Interfaces:
Navigator, SensorConstants

public class RotationNavigator
extends Object
implements Navigator, SensorConstants

The RotationNavigator class contains methods for performing basic navigational movements. This class uses two rotation sensors to monitor the wheels of the differential drive. For this class to work properly, the rotation sensors should record positive (+) values when the wheels move forward, and negative (-) values when the wheels move backward. This class also assumes the Motor.forward() command will cause the drive wheels to move in a forward direction.
Note: This class will only work for robots using two motors to steer differentially that can rotate within its footprint (i.e. turn on one spot).


Field Summary
 
Fields inherited from interface josx.platform.rcx.SensorConstants
BOOLEAN_VALUE, CANONICAL_VALUE, RAW_VALUE, SENSOR_MODE_ANGLE, SENSOR_MODE_BOOL, SENSOR_MODE_DEGC, SENSOR_MODE_DEGF, SENSOR_MODE_EDGE, SENSOR_MODE_PCT, SENSOR_MODE_PULSE, SENSOR_MODE_RAW, SENSOR_TYPE_LIGHT, SENSOR_TYPE_RAW, SENSOR_TYPE_ROT, SENSOR_TYPE_TEMP, SENSOR_TYPE_TOUCH
 
Constructor Summary
RotationNavigator(float wheelDiameter, float driveLength, float ratio)
          Overloaded RotationNavigator constructor that assumes the following:
Left motor = Motor.A Right motor = Motor.C
Left rotation sensor = Sensor.S1 Right rotation sensor = Sensor.S3
RotationNavigator(float wheelDiameter, float driveLength, float ratio, Motor leftMotor, Motor rightMotor, Sensor leftRot, Sensor rightRot)
          Allocates a RotationNavigator object and initializes if with the proper motors and sensors.
 
Method Summary
 void backward()
          Moves the RCX robot backward until stop() is called.
 void forward()
          Moves the RCX robot forward until stop() is called.
 float getAngle()
          Returns the current angle the RCX robot is facing.
 float getX()
          Returns the current x coordinate of the RCX.
 float getY()
          Returns the current y coordinate of the RCX.
 void gotoAngle(float angle)
          Rotates the RCX robot to point in a certain direction.
 void gotoPoint(float x, float y)
          Rotates the RCX robot towards the target point and moves the required distance.
 void rotate(float angle)
          Rotates the RCX robot a specific number of degrees in a direction (+ or -).
 void stop()
          Halts the RCX robot and calculates new x, y coordinates.
 void travel(int dist)
          Moves the RCX robot a specific distance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

RotationNavigator

public RotationNavigator(float wheelDiameter,
                         float driveLength,
                         float ratio,
                         Motor leftMotor,
                         Motor rightMotor,
                         Sensor leftRot,
                         Sensor rightRot)
Allocates a RotationNavigator object and initializes if with the proper motors and sensors. The x and y values will each equal 0 (cm's) on initialization, and the starting angle is 0 degrees, so if the first move is forward() the robot will run along the x axis.
Note: If you find your robot is going backwards or in circles when you tell it to go forwards, try rotating the wires to the motor ports by 90 or 180 degrees.

Parameters:
wheelDiameter - The diameter of the wheel, usually printed right on the wheel, in centimeters (e.g. 49.6 mm = 4.96 cm)
driveLength - The distance from the center of the left tire to the center of the right tire, in centimeters.
ratio - The ratio of sensor rotations to wheel rotations.
e.g. 3 complete rotations of the sensor for every one turn of the wheel = 3f
1 rotation of the sensor for every 2 turns of the wheel = 0.5f
rightMotor - The motor used to drive the right wheel e.g. Motor.C.
leftMotor - The motor used to drive the left wheel e.g. Motor.A.
rightRot - Sensor used to read rotations from the right wheel. e.g. Sensor.S3
leftRot - Sensor used to read rotations from the left wheel. e.g. Sensor.S1

RotationNavigator

public RotationNavigator(float wheelDiameter,
                         float driveLength,
                         float ratio)
Overloaded RotationNavigator constructor that assumes the following:
Left motor = Motor.A Right motor = Motor.C
Left rotation sensor = Sensor.S1 Right rotation sensor = Sensor.S3

Parameters:
wheelDiameter - The diameter of the wheel, usually printed right on the wheel, in centimeters (e.g. 49.6 mm = 4.96 cm)
ratio - The ratio of sensor rotations to wheel rotations.
e.g. 3 complete rotations of the sensor for every one turn of the wheel = 3f
1 rotation of the sensor for every 2 turns of the wheel = 0.5f
Method Detail

getX

public float getX()
Returns the current x coordinate of the RCX. Note: At present it will only give an updated reading when the RCX is stopped.

Specified by:
getX in interface Navigator
Returns:
float Present x coordinate.

getY

public float getY()
Returns the current y coordinate of the RCX. Note: At present it will only give an updated reading when the RCX is stopped.

Specified by:
getY in interface Navigator
Returns:
float Present y coordinate.

getAngle

public float getAngle()
Returns the current angle the RCX robot is facing. Note: At present it will only give an updated reading when the RCX is stopped.

Specified by:
getAngle in interface Navigator
Returns:
float Angle in degrees.

rotate

public void rotate(float angle)
Rotates the RCX robot a specific number of degrees in a direction (+ or -). This method will return once the rotation is complete.

Specified by:
rotate in interface Navigator
Parameters:
angle - Angle to rotate in degrees. A positive value rotates left, a negative value right.

gotoAngle

public void gotoAngle(float angle)
Rotates the RCX robot to point in a certain direction. It will take the shortest path necessary to point to the desired angle. Method returns once rotation is complete.

Specified by:
gotoAngle in interface Navigator
Parameters:
angle - The angle to rotate to, in degrees.

gotoPoint

public void gotoPoint(float x,
                      float y)
Rotates the RCX robot towards the target point and moves the required distance.

Specified by:
gotoPoint in interface Navigator
Parameters:
x - The x coordinate to move to.
y - The y coordinate to move to.

travel

public void travel(int dist)
Moves the RCX robot a specific distance. A positive value moves it forwards and a negative value moves it backwards. Method returns when movement is done.

Specified by:
travel in interface Navigator
Parameters:
dist - The positive or negative distance to move the robot (in centimeters).

forward

public void forward()
Moves the RCX robot forward until stop() is called.

Specified by:
forward in interface Navigator
See Also:
Navigator.stop().

backward

public void backward()
Moves the RCX robot backward until stop() is called.

Specified by:
backward in interface Navigator
See Also:
Navigator.stop().

stop

public void stop()
Halts the RCX robot and calculates new x, y coordinates.

Specified by:
stop in interface Navigator
See Also:
Navigator.forward().