public class SteeringPilot extends java.lang.Object implements ArcMoveController, RegulatedMotorListener
Vehicles that are controlled by the SteeringPilot class use a similar steering mechanism to a car, in which the front wheels pivot from side to side to control direction.
If you issue a command for travel(1000) and then issue a command travel(-500) before it completes the travel(1000) movement, it will call stop, properly inform movement listeners that the forward movement was halted, and then start moving backward 500 units. This makes movements from the SteeringPilot leak-proof and incorruptible.
Note: A DifferentialPilot robot can simulate a SteeringPilot robot by calling DifferentialPilot.setMinRadius(double)
and setting the value to something greater than zero (example: 15 cm).
DifferentialPilot.setMinRadius(double)
WHEEL_SIZE_EV3, WHEEL_SIZE_NXT1, WHEEL_SIZE_NXT2, WHEEL_SIZE_RCX
Constructor and Description |
---|
SteeringPilot(double driveWheelDiameter,
RegulatedMotor driveMotor,
RegulatedMotor steeringMotor,
double minTurnRadius,
int leftTurnTacho,
int rightTurnTacho)
Creates an instance of the SteeringPilot.
|
Modifier and Type | Method and Description |
---|---|
void |
addMoveListener(MoveListener listener)
Adds a MoveListener that will be notified of all movement events.
|
void |
arc(double turnRadius,
double arcAngle)
Moves the NXT robot along an arc with a specified radius and angle,
after which the robot stops moving.
|
void |
arc(double turnRadius,
double arcAngle,
boolean immediateReturn)
Moves the NXT robot along an arc with a specified radius and angle,
after which the robot stops moving.
|
void |
arcBackward(double turnRadius)
Starts the NXT robot moving backward along an arc with a specified radius.
|
void |
arcForward(double turnRadius)
Starts the NXT robot moving forward along an arc with a specified radius.
|
void |
backward()
Starts the NXT robot moving backwards.
|
void |
calibrateSteering()
This method calibrates the steering mechanism by turning the wheels all the way to the right and
left until they encounter resistance and recording the tachometer values.
|
void |
forward()
Starts the NXT robot moving forward.
|
double |
getLinearAcceleration()
Returns the acceleration at which the robot accelerates at the start of a move and decelerates at the end of a move.
|
double |
getLinearSpeed()
Returns the speed at which the robot will travel forward and backward (and to some extent arcs, although actual arc speed
is slightly less).
|
double |
getMaxLinearSpeed()
Returns the maximum speed at which this robot is capable of traveling forward and backward.
|
double |
getMinRadius()
In practice, a robot might steer tighter with one turn than the other.
|
Move |
getMovement()
Returns the move made since the move started, but before it has completed.
|
float |
getMovementIncrement() |
boolean |
isMoving()
true if the robot is moving
|
void |
rotationStarted(RegulatedMotor motor,
int tachoCount,
boolean stall,
long timeStamp)
Called when the motor starts rotating.
|
void |
rotationStopped(RegulatedMotor motor,
int tachoCount,
boolean stall,
long timeStamp)
Called when the motor stops rotating.
|
void |
setLinearAcceleration(double acceleration)
Sets the acceleration at which the robot will accelerate at the start of a move and decelerate at the end of a move.
|
void |
setLinearSpeed(double speed)
Sets the speed at which the robot will travel forward and backward (and to some extent arcs, although actual arc speed
is slightly less).
|
void |
setMinRadius(double minTurnRadius)
Set the radius of the minimum turning circle.
|
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 turnRadius,
double distance)
Moves the NXT robot a specified distance along an arc of specified radius,
after which the robot stops moving.
|
void |
travelArc(double turnRadius,
double distance,
boolean immediateReturn)
Moves the NXT robot a specified distance along an arc of specified radius,
after which the robot stops moving.
|
public SteeringPilot(double driveWheelDiameter, RegulatedMotor driveMotor, RegulatedMotor steeringMotor, double minTurnRadius, int leftTurnTacho, int rightTurnTacho)
Creates an instance of the SteeringPilot. The drive wheel measurements are written on the side of the LEGO tire, such as 56 x 26 (= 56 mm or 5.6 centimeters).
The accuracy of this class is dependent on physical factors:Note: If your drive motor is geared for faster movement, you must multiply the wheel size by the gear ratio. e.g. If gear ratio is 3:1, multiply wheel diameter by 3. If your drive motor is geared for slower movement, divide wheel size by gear ratio.
*driveWheelDiameter
- The diameter of the wheel(s) used to propel the vehicle.driveMotor
- The motor used to propel the vehicle, such as Motor.BsteeringMotor
- The motor used to steer the steering wheels, such as Motor.CminTurnRadius
- The smallest turning radius the vehicle can turn. e.g. 41 centimetersleftTurnTacho
- The tachometer the steering motor must turn to in order to turn left with the minimum turn radius.rightTurnTacho
- The tachometer the steering motor must turn to in order to turn right with the minimum turn radius.public void calibrateSteering()
This method calibrates the steering mechanism by turning the wheels all the way to the right and left until they encounter resistance and recording the tachometer values. These values determine the outer bounds of steering. The center steering value is the average of the two. NOTE: This method only works with steering robots that are symmetrical (same maximum steering threshold left and right).
TODO: Should be able to get steering parity right from this class! No need to fish for boolean.When you run the method, if you notice the wheels turn left first, then right, it means you need to set the reverse parameter to true for proper calibration. NOTE: The next time you run the calibrate method it will still turn left first, but...
public double getMinRadius()
getMinRadius
in interface ArcMoveController
public void arcForward(double turnRadius)
ArcMoveController
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.
arcForward
in interface ArcMoveController
turnRadius
- 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.public void arcBackward(double turnRadius)
ArcMoveController
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.
arcBackward
in interface ArcMoveController
turnRadius
- 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.public void arc(double turnRadius, double arcAngle) throws java.lang.IllegalArgumentException
ArcMoveController
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 turn to the left (anti-clockwise).
If angle
is negative, the robot will turn to the right (clockwise).
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.
arc
in interface ArcMoveController
turnRadius
- 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.arcAngle
- The sign of the angle determines the direction of the robot turns: Positive is anti-clockwise, negative is clockwise.java.lang.IllegalArgumentException
ArcMoveController.travelArc(double, double)
public void arc(double turnRadius, double arcAngle, boolean immediateReturn)
ArcMoveController
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 turn to the left (anti-clockwise).
If angle
is negative, the robot will turn to the right (clockwise).
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.
arc
in interface ArcMoveController
turnRadius
- 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.arcAngle
- The sign of the angle determines the direction of the robot turns: Positive is anti-clockwise, negative is clockwise.immediateReturn
- If immediateReturn is true then the method returns immediately.ArcMoveController.travelArc(double, double, boolean)
public void setMinRadius(double minTurnRadius)
ArcMoveController
setMinRadius
in interface ArcMoveController
minTurnRadius
- the radius in degreespublic void travelArc(double turnRadius, double distance)
ArcMoveController
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.
travelArc
in interface ArcMoveController
turnRadius
- 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.ArcMoveController.arc(double, double)
public void travelArc(double turnRadius, double distance, boolean immediateReturn) throws java.lang.IllegalArgumentException
ArcMoveController
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.
travelArc
in interface ArcMoveController
turnRadius
- 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.java.lang.IllegalArgumentException
ArcMoveController.arc(double, double, boolean)
public void backward()
MoveController
backward
in interface MoveController
public void forward()
MoveController
forward
in interface MoveController
public double getMaxLinearSpeed()
MoveController
getMaxLinearSpeed
in interface MoveController
public double getLinearSpeed()
MoveController
getLinearSpeed
in interface MoveController
public float getMovementIncrement()
public boolean isMoving()
MoveController
isMoving
in interface MoveController
public void setLinearSpeed(double speed)
MoveController
setLinearSpeed
in interface MoveController
speed
- In chosen units per second (e.g. cm/sec)public void stop()
MoveController
stop
in interface MoveController
public void travel(double distance)
MoveController
travel
in interface MoveController
distance
- The positive or negative distance to move the robot.public void travel(double distance, boolean immediateReturn)
MoveController
travel
in interface MoveController
distance
- The positive or negative distance to move the robot, in wheel diameter units.immediateReturn
- If immediateReturn is true then the method returns immediately.public void addMoveListener(MoveListener listener)
MoveProvider
addMoveListener
in interface MoveProvider
listener
- the move listenerpublic Move getMovement()
MoveProvider
getMovement
in interface MoveProvider
public void rotationStarted(RegulatedMotor motor, int tachoCount, boolean stall, long timeStamp)
RegulatedMotorListener
rotationStarted
in interface RegulatedMotorListener
public void rotationStopped(RegulatedMotor motor, int tachoCount, boolean stall, long timeStamp)
RegulatedMotorListener
rotationStopped
in interface RegulatedMotorListener
public void setLinearAcceleration(double acceleration)
MoveController
If acceleration is set during a move it will not be in used for the current move, it will be in effect with the next move.
setLinearAcceleration
in interface MoveController
acceleration
- in chosen units/second^2public double getLinearAcceleration()
MoveController
getLinearAcceleration
in interface MoveController