icommand.robotics
Class ServoNavigator

java.lang.Object
  extended by icommand.robotics.ServoNavigator
All Implemented Interfaces:
Navigator

public class ServoNavigator
extends java.lang.Object
implements Navigator

The ServoNavigator class contains methods for performing basic navigational movements. This class uses two standard NXT servo motors to monitor the wheels of the differential drive.
PRELIMINARY: Doesn't work very good because of SyncMotors poor performance. Note: This class will only work for robots using two motors to steer differentially that can rotate within its footprint (i.e. turn on the spot).

Version:
0.1 22-October-2006
Author:
Brian Bagnall

Constructor Summary
ServoNavigator(double wheelDiameter, double driveLength, double ratio, SyncMotors vehicle)
          Allocates a ServoNavigator object and initializes it with a SyncMotors object.
ServoNavigator(double wheelDiameter, double driveLength, SyncMotors vehicle)
          For use only if the wheel axle is inserted directly into the motor.
ServoNavigator(float wheelDiameter, float driveLength, float ratio, Motor left, Motor right)
           
 
Method Summary
 void backward()
          Moves the NXT robot backward until stop() is called.
 void forward()
          Moves the NXT robot forward until stop() is called.
 double getAngle()
          Returns the current angle the NXT robot is facing.
 float getX()
          Returns the current x coordinate of the NXT.
 float getY()
          Returns the current y coordinate of the NXT.
 void gotoAngle(double degrees)
          Rotates the NXT robot to point in a certain direction.
 void gotoPoint(double x, double y)
          Rotates the NXT robot towards the target point and moves the required distance.
 void rotate(double degrees)
          Rotates the NXT robot a specific number of degrees in a direction (+ or -).
 void stop()
          Halts the NXT robot and calculates new x, y coordinates.
 void travel(long dist)
          Moves the NXT robot a specific distance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServoNavigator

public ServoNavigator(double wheelDiameter,
                      double driveLength,
                      SyncMotors vehicle)
For use only if the wheel axle is inserted directly into the motor. (i.e. use a different constructor if your drive train uses gears)

Parameters:
wheelDiameter -
driveLength -
vehicle -

ServoNavigator

public ServoNavigator(double wheelDiameter,
                      double driveLength,
                      double ratio,
                      SyncMotors vehicle)
Allocates a ServoNavigator object and initializes it with a SyncMotors object. 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.

Parameters:
wheelDiameter - The diameter of the wheel, usually printed right on the wheel, in millimeters (e.g. 56 mm)
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. 720 tacho counts for every one turn of the wheel = 720f
If your wheel axle is directly in the motor, use 360.
vehicle - A SyncMotors object containing two synchronized motors.

ServoNavigator

public ServoNavigator(float wheelDiameter,
                      float driveLength,
                      float ratio,
                      Motor left,
                      Motor right)
Parameters:
wheelDiameter - The diameter of the wheel, usually printed right on the wheel, in millimeters (e.g. 56 mm)
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
left - Left Motor e.g. Motor.B
right - Right Motor e.g. Motor.B
Method Detail

getX

public float getX()
Returns the current x coordinate of the NXT. If NXT is moving it will try to calculate the current position.

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

getY

public float getY()
Returns the current y coordinate of the NXT. If NXT is moving it will try to calculate the current position.

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

getAngle

public double getAngle()
Returns the current angle the NXT robot is facing. Note: At present it will only give an updated reading when the NXT is not in the midst of rotating.

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

rotate

public void rotate(double degrees)
Rotates the NXT robot a specific number of degrees in a direction (+ or -). This method will return once the rotation is complete. PRELIMINARY: The code is accurate but the SyncMotors.left(count) and SyncMotors.right(count) are not very good right now.

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

gotoAngle

public void gotoAngle(double degrees)
Rotates the NXT 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(double x,
                      double y)
Rotates the NXT 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(long dist)
Moves the NXT robot a specific distance. A positive value moves it forwards and a negative value moves it backwards. Method returns when movement is done. PRELIMINARY (Currently overshoots by about half an axle turn)

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 NXT robot forward until stop() is called.

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

backward

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

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

stop

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

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