lejos.robotics.navigation
Class SegowayPilot

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.robotics.navigation.Segoway
          extended by lejos.robotics.navigation.SegowayPilot
All Implemented Interfaces:
Runnable, ArcMoveController, ArcRotateMoveController, MoveController, MoveProvider, RotateMoveController

public class SegowayPilot
extends Segoway
implements ArcRotateMoveController

Allow standard moves with a Segoway robot. Currently the robot has a 5 second delay between moves to allow it some time to rebalance and straighten out uneven tacho rotations. This can be changed with setMoveDelay().

This code will work with any Segway-style robot, but tall robots will have problems balancing when the robot is moving. To counteract this, use larger wheels and/or slow down the speed using setTravelSpeed(). Make sure the battery is fully charged. The robot is more stable on carpet than hardwood at higher speeds.

The default speed is 50, which can be changed with setTravelSpeed().

Author:
BB
See Also:
Segoway

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.UncaughtExceptionHandler
 
Field Summary
static int ARC_B
           
static int ARC_F
           
static int BACKWARD_T
           
static int FORWARD_T
           
static int ROTATE_L
           
static int ROTATE_R
           
 int SPEED
           
static int STOP
           
 
Fields inherited from class lejos.robotics.navigation.Segoway
left_motor, right_motor
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface lejos.robotics.navigation.MoveController
WHEEL_SIZE_NXT1, WHEEL_SIZE_NXT2, WHEEL_SIZE_RCX
 
Fields inherited from interface lejos.robotics.navigation.MoveController
WHEEL_SIZE_NXT1, WHEEL_SIZE_NXT2, WHEEL_SIZE_RCX
 
Constructor Summary
SegowayPilot(EncoderMotor left, EncoderMotor right, Gyroscope gyro, double wheelDiameter, double trackWidth)
          Creates an instance of SegowayPilot.
 
Method Summary
 void addMoveListener(MoveListener m)
          Adds a MoveListener that will be notified of all movement events.
 void arc(double radius, double angle)
          Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving.
 void arc(double radius, double angle, boolean immediateReturn)
          Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving.
 void arcBackward(double radius)
          Starts the NXT robot moving backward along an arc with a specified radius.
 void arcForward(double radius)
          Starts the NXT robot moving forward along an arc with a specified radius.
 void backward()
          Starts the NXT robot moving backwards.
 void forward()
          Starts the NXT robot moving forward.
 float getAngleIncrement()
           
 double getMaxTravelSpeed()
          Returns the maximum speed at which this robot is capable of traveling forward and backward.
 double getMinRadius()
          The minimum steering radius this vehicle is capable of when traveling in an arc.
 Move getMovement()
          Returns the move made since the move started, but before it has completed.
 double getMovementIncrement()
           
 double getRotateMaxSpeed()
          returns the maximum value of the rotation speed;
 double getRotateSpeed()
          Returns the value of the rotation speed
 double getTravelSpeed()
          Returns the speed at which the robot will travel forward and backward (and to some extent arcs, although actual arc speed is slightly less).
 boolean isMoving()
          true if the robot is moving
 void rotate(double angle)
          Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter.
 void rotate(double degrees, boolean immediateReturn)
          Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter.
 void setMinRadius(double radius)
          Set the radius of the minimum turning circle.
 void setMoveDelay(int millis)
          Set the delay between movements which allows the Segoway to recover balance.
 void setRotateSpeed(double arg0)
          sets the rotation speed of the robot (the angular velocity of the rotate() methods)
 void setTravelSpeed(double speed)
          Currently this method isn't properly implemented with the proper units.
 void steer(double turnRate, double angle, boolean immediateReturn)
          Moves the robot along a curved path for a specified angle of rotation.
 void stop()
          Halts the NXT robot
 void travel(double distance)
          Moves the NXT robot a specific distance.
 void travel(double distance, boolean immediateReturn)
          Moves the NXT robot a specific distance.
 void travelArc(double radius, double distance)
          Moves the NXT robot a specified distance along an arc of specified radius, after which the robot stops moving.
 void travelArc(double radius, double distance, boolean immediateReturn)
          Moves the NXT robot a specified distance along an arc of specified radius, after which the robot stops moving.
 
Methods inherited from class lejos.robotics.navigation.Segoway
run, wheelDriver
 
Methods inherited from class java.lang.Thread
currentThread, getDefaultUncaughtExceptionHandler, getName, getPriority, getUncaughtExceptionHandler, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, start, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPEED

public int SPEED

STOP

public static final int STOP
See Also:
Constant Field Values

FORWARD_T

public static final int FORWARD_T
See Also:
Constant Field Values

BACKWARD_T

public static final int BACKWARD_T
See Also:
Constant Field Values

ROTATE_L

public static final int ROTATE_L
See Also:
Constant Field Values

ROTATE_R

public static final int ROTATE_R
See Also:
Constant Field Values

ARC_F

public static final int ARC_F
See Also:
Constant Field Values

ARC_B

public static final int ARC_B
See Also:
Constant Field Values
Constructor Detail

SegowayPilot

public SegowayPilot(EncoderMotor left,
                    EncoderMotor right,
                    Gyroscope gyro,
                    double wheelDiameter,
                    double trackWidth)
Creates an instance of SegowayPilot.

Parameters:
left - The left motor.
right - The right motor.
gyro - A generic gyroscope
wheelDiameter - The diameter of the wheel. For convenience, use the WHEEL_SIZE_XXX constants.
trackWidth - Distance between the center of the right tire and left tire. Use the same units as wheelDiameter.
Method Detail

steer

public void steer(double turnRate,
                  double angle,
                  boolean immediateReturn)
Moves the robot along a curved path for a specified angle of rotation. This method is similar to the arc(double radius, double angle, boolean immediateReturn) method except it uses the turnRate() parameter to determine the curvature of the path and therefore has the ability to drive straight. This makes it useful for line following applications. This method has the ability to return immediately by using the immediateReturn parameter set to true.

The turnRate specifies the sharpness of the turn. Use values between -200 and +200.
For details about how this parameter works, see DifferentialPilot.steer(double, double)

The robot will stop when its heading has changed by the amount of the angle parameter.
If angle is positive, the robot will move in the direction that increases its heading (it turns left).
If angle is negative, the robot will move in the direction that decreases its heading (turns right).
If angle is zero, the robot will not move and the method returns immediately.
For more details about this parameter, see DifferentialPilot.steer(double, double)

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Parameters:
turnRate - If positive, the left side of the robot is on the inside of the turn. If negative, the left side is on the outside.
angle - The angle through which the robot will rotate. If negative, robot traces the turning circle backwards.
immediateReturn - If immediateReturn is true then the method returns immediately.

arc

public void arc(double radius,
                double angle,
                boolean immediateReturn)
Description copied from interface: ArcMoveController
Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving. This method has the ability to return immediately by using the immediateReturn parameter.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, is zero, the robot rotates in place.

The robot will stop when the degrees it has moved along the arc equals angle.
If angle is positive, the robot will move travel forwards.
If angle is negative, the robot will move travel backwards. If angle is zero, the robot will not move and the method returns immediately.

Postcondition: Motor speeds are unpredictable.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Specified by:
arc in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.
angle - The sign of the angle determines the direction of robot motion. Positive drives the robot forward, negative drives it backward.
immediateReturn - If immediateReturn is true then the method returns immediately.
See Also:
ArcMoveController.travelArc(double, double, boolean)

forward

public void forward()
Description copied from interface: MoveController
Starts the NXT robot moving forward.

Specified by:
forward in interface MoveController

backward

public void backward()
Description copied from interface: MoveController
Starts the NXT robot moving backwards.

Specified by:
backward in interface MoveController

setMoveDelay

public void setMoveDelay(int millis)
Set the delay between movements which allows the Segoway to recover balance. Default value is five seconds (5000 millis).


stop

public void stop()
Description copied from interface: MoveController
Halts the NXT robot

Specified by:
stop in interface MoveController

travel

public void travel(double distance,
                   boolean immediateReturn)
Description copied from interface: MoveController
Moves the NXT robot a specific distance. A positive value moves it forward and a negative value moves it backward.

Specified by:
travel in interface MoveController
Parameters:
distance - The positive or negative distance to move the robot, in wheel diameter units.
immediateReturn - If immediateReturn is true then the method returns immediately.

rotate

public void rotate(double degrees,
                   boolean immediateReturn)
Description copied from interface: RotateMoveController
Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter. Motion stops when rotation is done.

Specified by:
rotate in interface RotateMoveController
Parameters:
degrees - The angle to rotate in degrees. A positive value rotates left, a negative value right (clockwise).
immediateReturn - If immediateReturn is true then the method returns immediately

getMaxTravelSpeed

public double getMaxTravelSpeed()
Description copied from interface: MoveController
Returns the maximum speed at which this robot is capable of traveling forward and backward. Speed is measured in units/second. e.g. If wheel diameter is cm, then speed is cm/sec.

Specified by:
getMaxTravelSpeed in interface MoveController
Returns:
Speed in chosen units per second (e.g. cm/sec)

getMovementIncrement

public double getMovementIncrement()

getTravelSpeed

public double getTravelSpeed()
Description copied from interface: MoveController
Returns the speed at which the robot will travel forward and backward (and to some extent arcs, although actual arc speed is slightly less). Speed is measured in units/second. e.g. If wheel diameter is cm, then speed is cm/sec.

Specified by:
getTravelSpeed in interface MoveController
Returns:
Speed in chosen units per second (e.g. cm/sec)

setTravelSpeed

public void setTravelSpeed(double speed)
Currently this method isn't properly implemented with the proper units. Speed is just an arbitrary number up to about 200. At higher speed values it can be unstable. Currently it uses a default of 80 which is near the unstable speed. Will need to make this method use units/second.

Specified by:
setTravelSpeed in interface MoveController
Parameters:
speed - The speed to travel.

isMoving

public boolean isMoving()
Description copied from interface: MoveController
true if the robot is moving

Specified by:
isMoving in interface MoveController
Returns:
true if the robot is moving under power.

travel

public void travel(double distance)
Description copied from interface: MoveController
Moves the NXT robot a specific distance. A positive value moves it forward and a negative value moves it backward. Method returns when movement is done.

Specified by:
travel in interface MoveController
Parameters:
distance - The positive or negative distance to move the robot.

addMoveListener

public void addMoveListener(MoveListener m)
Description copied from interface: MoveProvider
Adds a MoveListener that will be notified of all movement events.

Specified by:
addMoveListener in interface MoveProvider
Parameters:
m - the move listener

getMovement

public Move getMovement()
Description copied from interface: MoveProvider
Returns the move made since the move started, but before it has completed. This method is used by GUI maps to display the movement of a robot in real time. The robot must be capable of determining the move while it is in motion.

Specified by:
getMovement in interface MoveProvider
Returns:
The move made since the move started.

getAngleIncrement

public float getAngleIncrement()

getRotateMaxSpeed

public double getRotateMaxSpeed()
Description copied from interface: RotateMoveController
returns the maximum value of the rotation speed;

Specified by:
getRotateMaxSpeed in interface RotateMoveController
Returns:
max rotation speed

getRotateSpeed

public double getRotateSpeed()
Description copied from interface: RotateMoveController
Returns the value of the rotation speed

Specified by:
getRotateSpeed in interface RotateMoveController
Returns:
the rotate speed in degrees per second

rotate

public void rotate(double angle)
Description copied from interface: RotateMoveController
Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter. Method returns when rotation is done.

Specified by:
rotate in interface RotateMoveController
Parameters:
angle - The angle to rotate in degrees. A positive value rotates left, a negative value right (clockwise).

setRotateSpeed

public void setRotateSpeed(double arg0)
Description copied from interface: RotateMoveController
sets the rotation speed of the robot (the angular velocity of the rotate() methods)

Specified by:
setRotateSpeed in interface RotateMoveController
Parameters:
arg0 - in degrees per second

arc

public void arc(double radius,
                double angle)
Description copied from interface: ArcMoveController
Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving. This method does not return until the robot has completed moving angle degrees along the arc.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, is zero, the robot rotates in place.

Robot will stop when the degrees it has moved along the arc equals angle.
If angle is positive, the robot will move travel forwards.
If angle is negative, the robot will move travel backwards. If angle is zero, the robot will not move and the method returns immediately.

Postcondition: Motor speeds are unpredictable.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Specified by:
arc in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.
angle - The sign of the angle determines the direction of robot motion. Positive drives the robot forward, negative drives it backward.
See Also:
ArcMoveController.travelArc(double, double)

arcBackward

public void arcBackward(double radius)
Description copied from interface: ArcMoveController
Starts the NXT robot moving backward along an arc with a specified radius.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, the robot rotates in place.

Postcondition: Motor speeds are unpredictable.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Specified by:
arcBackward in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.

arcForward

public void arcForward(double radius)
Description copied from interface: ArcMoveController
Starts the NXT robot moving forward along an arc with a specified radius.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, the robot rotates in place.

Postcondition: Motor speeds are unpredictable.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Specified by:
arcForward in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.

getMinRadius

public double getMinRadius()
Description copied from interface: ArcMoveController
The minimum steering radius this vehicle is capable of when traveling in an arc. Theoretically this should be identical for both forward and reverse travel. In practice?

Specified by:
getMinRadius in interface ArcMoveController
Returns:
the radius in degrees

setMinRadius

public void setMinRadius(double radius)
Description copied from interface: ArcMoveController
Set the radius of the minimum turning circle.

Specified by:
setMinRadius in interface ArcMoveController
Parameters:
radius - the radius in degrees

travelArc

public void travelArc(double radius,
                      double distance)
Description copied from interface: ArcMoveController
Moves the NXT robot a specified distance along an arc of specified radius, after which the robot stops moving. This method does not return until the robot has completed moving distance along the arc. The units (inches, cm) for distance must be the same as the units used for radius.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, the robot rotates in place

The robot will stop when it has moved along the arc distance units.
If distance is positive, the robot will move travel forwards.
If distance is negative, the robot will move travel backwards.
If distance is zero, the robot will not move and the method returns immediately.

Postcondition: Motor speeds are unpredictable.

Specified by:
travelArc in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.
distance - to travel, in same units as radius. The sign of the distance determines the direction of robot motion. Positive drives the robot forward, negative drives it backward.
See Also:
ArcMoveController.arc(double, double)

travelArc

public void travelArc(double radius,
                      double distance,
                      boolean immediateReturn)
Description copied from interface: ArcMoveController
Moves the NXT robot a specified distance along an arc of specified radius, after which the robot stops moving. This method has the ability to return immediately by using the immediateReturn parameter. The units (inches, cm) for distance should be the same as the units used for radius.

If radius is positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
If radius is negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
If radius is zero, the robot rotates in place.

The robot will stop when it has moved along the arc distance units.
If distance is positive, the robot will move travel forwards.
If distance is negative, the robot will move travel backwards.
If distance is zero, the robot will not move and the method returns immediately.

Postcondition: Motor speeds are unpredictable.

Specified by:
travelArc in interface ArcMoveController
Parameters:
radius - of the arc path. If positive, the left side of the robot is on the inside of the turn. If negative, the left side of the robot is on the outside of the turn.
distance - to travel, in same units as radius. The sign of the distance determines the direction of robot motion. Positive drives the robot forward, negative drives it backward.
immediateReturn - If immediateReturn is true then the method returns immediately.
See Also:
ArcMoveController.arc(double, double, boolean)