RoboJDETM v2.0

com.ridgesoft.robotics
Class DifferentialDriveNavigator

java.lang.Object
  extended by java.lang.Thread
      extended by com.ridgesoft.robotics.DifferentialDriveNavigator
All Implemented Interfaces:
Navigator, Runnable

public class DifferentialDriveNavigator
extends Thread
implements Navigator

Implements a navigator for a differential-drive robot.

This class is designed to provide simple navigation for a robot that employs a two wheel differnetial-drive design. It steers the robot by applying different power levels to the two wheels or by powering the wheels in reverse directions.

This class relies upon an object that implements the Localizer interface to keep track of the robot's position and heading and two Motor objects to control power to the robot's left and right wheels.

This class extends the Thread class, implementing a thread which carries out navigation commands.

See Also:
Localizer, OdometricLocalizer, Motor, ContinuousRotationServo

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DifferentialDriveNavigator(Motor leftMotor, Motor rightMotor, Localizer localizer, int drivePower, int rotatePower, float gain, float goToThreshold, float rotateThreshold, int threadPriority, int period)
          Constructs a DifferentialDriveNavigator object.
 
Method Summary
 void go(float heading)
          Drive the robot indefinitely in the direction specified.
 void moveTo(float x, float y)
          Move the robot to the specified coordinates.
 void moveTo(float x, float y, boolean wait)
          Move the robot to the specified coordinates.
 void moveTo(float x, float y, NavigatorListener listener)
          Move the robot to the specified coordinates.
 void run()
          Run method for the navigation thread.
 void stop()
          Stop the robot.
 void turnTo(float heading)
          Turn the robot to the specified heading.
 void turnTo(float heading, boolean wait)
          Turn the robot to the specified heading.
 void turnTo(float heading, NavigatorListener listener)
          Turn the robot to the specified heading.
 
Methods inherited from class java.lang.Thread
activeCount, currentThread, dumpStack, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait
 

Constructor Detail

DifferentialDriveNavigator

public DifferentialDriveNavigator(Motor leftMotor,
                                  Motor rightMotor,
                                  Localizer localizer,
                                  int drivePower,
                                  int rotatePower,
                                  float gain,
                                  float goToThreshold,
                                  float rotateThreshold,
                                  int threadPriority,
                                  int period)
Constructs a DifferentialDriveNavigator object.

Parameters:
leftMotor - reference to motor object for the left wheel/track
rightMotor - reference to motor object for the right wheel/track
localizer - reference to a localizer which keeps track of the robot's position
drivePower - average motor power level to use when driving forward
rotatePower - average motor power level to use when rotating in place
gain - gain to use in the control algorithm that steers the robot toward the desired heading. The higher the gain the more agressively the navigator will attempt to eliminate heading error. Too high a gain will cause the robot to over steer.
goToThreshold - distance threshold the navigator will use to determine if the robot has reached its destination. Setting this too small will cause the robot to thrash when it gets close to the destination. Setting it too large will cause the navigator to be less precise than necessary.
rotateThreshold - radians threshold value the navigator will use to determine if the robot is facing in the desired direction. Setting this too small will cause the robot to thrash around the desired direction. Setting it too large will cause the navigator to be less precise than necessary.
threadPriority - priority to use for the navigation thread
period - period to use for repeating navigition calculations and updating motor power levels
Method Detail

go

public void go(float heading)
Drive the robot indefinitely in the direction specified.

Specified by:
go in interface Navigator
Parameters:
heading - direction in radians to head toward

moveTo

public void moveTo(float x,
                   float y)
Move the robot to the specified coordinates.

This method does not return until the robot has reached the destination.

Specified by:
moveTo in interface Navigator
Parameters:
x - x coordinate to move to
y - y coordinate to move to

moveTo

public void moveTo(float x,
                   float y,
                   boolean wait)
Move the robot to the specified coordinates.

Specified by:
moveTo in interface Navigator
Parameters:
x - x coordinate to move to
y - y coordinate to move to
wait - true if the method should wait for the operation to terminate

moveTo

public void moveTo(float x,
                   float y,
                   NavigatorListener listener)
Move the robot to the specified coordinates.

This method returns without waiting for the movement to complete.

Specified by:
moveTo in interface Navigator
Parameters:
x - x coordinate to move to
y - y coordinate to move to
listener - listener to call when the operation terminates, may be null

run

public void run()
Run method for the navigation thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

stop

public void stop()
Stop the robot.

Specified by:
stop in interface Navigator

turnTo

public void turnTo(float heading)
Turn the robot to the specified heading.

This method does not return until the robot is facing the new heading.

Specified by:
turnTo in interface Navigator
Parameters:
heading - heading to turn to in radians

turnTo

public void turnTo(float heading,
                   boolean wait)
Turn the robot to the specified heading.

Specified by:
turnTo in interface Navigator
Parameters:
heading - heading to turn to in radians
wait - true if the method should wait for the operation to terminate

turnTo

public void turnTo(float heading,
                   NavigatorListener listener)
Turn the robot to the specified heading.

This method returns without waiting for the turn to complete.

Specified by:
turnTo in interface Navigator
Parameters:
heading - heading to turn to in radians
listener - listener to call when the operation terminates, may be null

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com