Class MovePilot
- java.lang.Object
-
- lejos.robotics.navigation.MovePilot
-
- All Implemented Interfaces:
ArcMoveController,ArcRotateMoveController,MoveController,MoveProvider,RotateMoveController
public class MovePilot extends java.lang.Object implements ArcRotateMoveController
The Pilot class is a software abstraction of the Pilot mechanism of a robot. It contains methods to control robot movements: travel forward or backward in a straight line or a circular path or rotate to a new direction.
This class will work with any chassis. Some types of chassis might not support all the movements this pilot support. An object of this class assumes that it has exclusive control of its motors. If any other object makes calls to its motors, the results are unpredictable.
It automatically updates aOdometryPoseProviderwhich has called theaddMoveListenermethod on this object.
Some methods optionally return immediately so the thread that called it can do things while the robot is moving, such as monitor sensors and callstop().
Handling stalls: If a stall is detected,isStalled()returnstrue,isMoving()returnsfalse,moveStopped()is called, and, if a blocking method is executing, that method exits. The units of measure for travel distance, speed and acceleration are the units used in specifying the wheel diameter in the chassis.
In all the methods that cause the robot to change its heading (the angle relative to the X axis in which the robot is facing) the angle parameter specifies the change in heading. A positive angle causes a turn to the left (anti-clockwise) to increase the heading, and a negative angle causes a turn to the right (clockwise).
Example of use of come common methods:Wheel wheel1 = DifferentialChassis.modelWheel(Motor.A, 43.2).offset(-72); Wheel wheel2 = DifferentialChassis.modelWheel(Motor.D, 43.2).offset(72); Chassis chassis = new DifferentialChassis(new Wheel[]{wheel1, wheel2}); MovePilot pilot = new MovePilot(chassis); pilot.setRobotSpeed(30); // cm per second pilot.travel(50); // cm pilot.rotate(-90); // degree clockwise pilot.travel(-50,true); // move backward for 50 cm while(pilot.isMoving())Thread.yield(); pilot.rotate(-90); pilot.rotateTo(270); pilot.stop();
-
-
Field Summary
-
Fields inherited from interface lejos.robotics.navigation.MoveController
WHEEL_SIZE_EV3, WHEEL_SIZE_NXT1, WHEEL_SIZE_NXT2, WHEEL_SIZE_RCX
-
-
Constructor Summary
Constructors Constructor Description MovePilot(double leftWheelDiameter, double rightWheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor, boolean reverse)Deprecated.MovePilot(double wheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor)Deprecated.MovePilot(double wheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor, boolean reverse)Deprecated.MovePilot(Chassis chassis)Allocates a Pilot object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMoveListener(MoveListener listener)Adds a MoveListener that will be notified of all movement events.voidarc(double radius, double angle)Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving.voidarc(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.voidarcBackward(double radius)Starts the NXT robot moving backward along an arc with a specified radius.voidarcForward(double radius)Starts the NXT robot moving forward along an arc with a specified radius.voidbackward()Starts the NXT robot moving backwards.voidforward()Starts the NXT robot moving forward.doublegetAngularAcceleration()Returns the acceleration at which the robot accelerates at the start of a move and decelerates at the end of a move.doublegetAngularSpeed()Returns the value of the rotation speeddoublegetLinearAcceleration()Returns the acceleration at which the robot accelerates at the start of a move and decelerates at the end of a move.doublegetLinearSpeed()Returns the speed at which the robot will travel forward and backward (and to some extent arcs, although actual arc speed is slightly less).doublegetMaxAngularSpeed()returns the maximum value of the rotation speed;doublegetMaxLinearSpeed()Returns the maximum speed at which this robot is capable of traveling forward and backward.doublegetMinRadius()The minimum steering radius this vehicle is capable of when traveling in an arc.MovegetMovement()Returns the move made since the move started, but before it has completed.booleanisMoving()true if the robot is movingvoidrotate(double angle)Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter.voidrotate(double angle, boolean immediateReturn)Rotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter.voidrotateLeft()voidrotateRight()voidsetAngularAcceleration(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.voidsetAngularSpeed(double speed)sets the rotation speed of the robot (the angular velocity of the rotate() methods)voidsetLinearAcceleration(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.voidsetLinearSpeed(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).voidsetMinRadius(double radius)Set the radius of the minimum turning circle.voidstop()Halts the NXT robotvoidtravel(double distance)Moves the NXT robot a specific distance.voidtravel(double distance, boolean immediateReturn)Moves the NXT robot a specific distance.voidtravelArc(double radius, double distance)Moves the NXT robot a specified distance along an arc of specified radius, after which the robot stops moving.voidtravelArc(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.
-
-
-
Constructor Detail
-
MovePilot
@Deprecated public MovePilot(double wheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor)Deprecated.Allocates a Pilot object, and sets the physical parameters of the robot.
Assumes Motor.forward() causes the robot to move forward.- Parameters:
wheelDiameter- Diameter of the tire, in any convenient units (diameter in mm is usually printed on the tire).trackWidth- Distance between center of right tire and center of left tire, in same units as wheelDiameter.leftMotor- The left Motor (e.g., Motor.C).rightMotor- The right Motor (e.g., Motor.A).
-
MovePilot
@Deprecated public MovePilot(double wheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor, boolean reverse)Deprecated.Allocates a Pilot object, and sets the physical parameters of the robot.- Parameters:
wheelDiameter- Diameter of the tire, in any convenient units (diameter in mm is usually printed on the tire).trackWidth- Distance between center of right tire and center of left tire, in same units as wheelDiameter.leftMotor- The left Motor (e.g., Motor.C).rightMotor- The right Motor (e.g., Motor.A).reverse- If true, the NXT robot moves forward when the motors are running backward.
-
MovePilot
@Deprecated public MovePilot(double leftWheelDiameter, double rightWheelDiameter, double trackWidth, RegulatedMotor leftMotor, RegulatedMotor rightMotor, boolean reverse)Deprecated.Allocates a Pilot object, and sets the physical parameters of the robot.- Parameters:
leftWheelDiameter- Diameter of the left wheel, in any convenient units (diameter in mm is usually printed on the tire).rightWheelDiameter- Diameter of the right wheel. You can actually fit intentionally wheels with different size to your robot. If you fitted wheels with the same size, but your robot is not going straight, try swapping the wheels and see if it deviates into the other direction. That would indicate a small difference in wheel size. Adjust wheel size accordingly. The minimum change in wheel size which will actually have an effect is given by minChange = A*wheelDiameter*wheelDiameter/(1-(A*wheelDiameter) where A = PI/(moveSpeed*360). Thus for a moveSpeed of 25 cm/second and a wheelDiameter of 5,5 cm the minChange is about 0,01058 cm. The reason for this is, that different while sizes will result in different motor speed. And that is given as an integer in degree per second.trackWidth- Distance between center of right tire and center of left tire, in same units as wheelDiameter.leftMotor- The left Motor (e.g., Motor.C).rightMotor- The right Motor (e.g., Motor.A).reverse- If true, the NXT robot moves forward when the motors are running backward.
-
MovePilot
public MovePilot(Chassis chassis)
Allocates a Pilot object.- Parameters:
chassis- A Chassis object describing the physical parameters of the robot.
-
-
Method Detail
-
setLinearAcceleration
public void setLinearAcceleration(double acceleration)
Description copied from interface:MoveControllerSets the acceleration at which the robot will accelerate at the start of a move and decelerate at the end of a move. Acceleration is measured in units/second^2. e.g. If wheel diameter is cm, then acceleration is cm/sec^2.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.
- Specified by:
setLinearAccelerationin interfaceMoveController- Parameters:
acceleration- in chosen units/second^2
-
getLinearAcceleration
public double getLinearAcceleration()
Description copied from interface:MoveControllerReturns the acceleration at which the robot accelerates at the start of a move and decelerates at the end of a move.- Specified by:
getLinearAccelerationin interfaceMoveController- Returns:
- acceleration in chosen units/second^2
-
setAngularAcceleration
public void setAngularAcceleration(double acceleration)
Description copied from interface:RotateMoveControllerSets the acceleration at which the robot will accelerate at the start of a move and decelerate at the end of a move. Acceleration is measured in units/second^2. e.g. If wheel diameter is cm, then acceleration is cm/sec^2.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.
- Specified by:
setAngularAccelerationin interfaceRotateMoveController- Parameters:
acceleration- in chosen units/second^2
-
getAngularAcceleration
public double getAngularAcceleration()
Description copied from interface:RotateMoveControllerReturns the acceleration at which the robot accelerates at the start of a move and decelerates at the end of a move.- Specified by:
getAngularAccelerationin interfaceRotateMoveController- Returns:
- acceleration in chosen units/second^2
-
setLinearSpeed
public void setLinearSpeed(double speed)
Description copied from interface:MoveControllerSets 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:
setLinearSpeedin interfaceMoveController- Parameters:
speed- In chosen units per second (e.g. cm/sec)
-
getLinearSpeed
public double getLinearSpeed()
Description copied from interface:MoveControllerReturns 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:
getLinearSpeedin interfaceMoveController- Returns:
- Speed in chosen units per second (e.g. cm/sec)
-
getMaxLinearSpeed
public double getMaxLinearSpeed()
Description copied from interface:MoveControllerReturns 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:
getMaxLinearSpeedin interfaceMoveController- Returns:
- Speed in chosen units per second (e.g. cm/sec)
-
setAngularSpeed
public void setAngularSpeed(double speed)
Description copied from interface:RotateMoveControllersets the rotation speed of the robot (the angular velocity of the rotate() methods)- Specified by:
setAngularSpeedin interfaceRotateMoveController- Parameters:
speed- in degrees per second
-
getAngularSpeed
public double getAngularSpeed()
Description copied from interface:RotateMoveControllerReturns the value of the rotation speed- Specified by:
getAngularSpeedin interfaceRotateMoveController- Returns:
- the rotate speed in degrees per second
-
getMaxAngularSpeed
public double getMaxAngularSpeed()
Description copied from interface:RotateMoveControllerreturns the maximum value of the rotation speed;- Specified by:
getMaxAngularSpeedin interfaceRotateMoveController- Returns:
- max rotation speed
-
getMinRadius
public double getMinRadius()
Description copied from interface:ArcMoveControllerThe 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:
getMinRadiusin interfaceArcMoveController- Returns:
- the radius in degrees
-
setMinRadius
public void setMinRadius(double radius)
Description copied from interface:ArcMoveControllerSet the radius of the minimum turning circle.- Specified by:
setMinRadiusin interfaceArcMoveController- Parameters:
radius- the radius in degrees
-
forward
public void forward()
Description copied from interface:MoveControllerStarts the NXT robot moving forward.- Specified by:
forwardin interfaceMoveController
-
backward
public void backward()
Description copied from interface:MoveControllerStarts the NXT robot moving backwards.- Specified by:
backwardin interfaceMoveController
-
travel
public void travel(double distance)
Description copied from interface:MoveControllerMoves 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:
travelin interfaceMoveController- Parameters:
distance- The positive or negative distance to move the robot.
-
travel
public void travel(double distance, boolean immediateReturn)Description copied from interface:MoveControllerMoves the NXT robot a specific distance. A positive value moves it forward and a negative value moves it backward.- Specified by:
travelin interfaceMoveController- 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.
-
arcForward
public void arcForward(double radius)
Description copied from interface:ArcMoveControllerStarts the NXT robot moving forward along an arc with a specified radius.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis 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:
arcForwardin interfaceArcMoveController- 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.
-
arcBackward
public void arcBackward(double radius)
Description copied from interface:ArcMoveControllerStarts the NXT robot moving backward along an arc with a specified radius.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis 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:
arcBackwardin interfaceArcMoveController- 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.
-
arc
public void arc(double radius, double angle)Description copied from interface:ArcMoveControllerMoves 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 movingangledegrees along the arc.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis zero, is zero, the robot rotates in place.Robot will stop when the degrees it has moved along the arc equals
angle.
Ifangleis positive, the robot will turn to the left (anti-clockwise).
Ifangleis negative, the robot will turn to the right (clockwise). Ifangleis 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:
arcin interfaceArcMoveController- 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 the robot turns: Positive is anti-clockwise, negative is clockwise.- See Also:
ArcMoveController.travelArc(double, double)
-
travelArc
public void travelArc(double radius, double distance)Description copied from interface:ArcMoveControllerMoves 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 movingdistancealong the arc. The units (inches, cm) fordistancemust be the same as the units used forradius.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis zero, the robot rotates in placeThe robot will stop when it has moved along the arc
distanceunits.
Ifdistanceis positive, the robot will move travel forwards.
Ifdistanceis negative, the robot will move travel backwards.
Ifdistanceis zero, the robot will not move and the method returns immediately.Postcondition: Motor speeds are unpredictable.
- Specified by:
travelArcin interfaceArcMoveController- 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 asradius. 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:ArcMoveControllerMoves 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 theimmediateReturnparameter. The units (inches, cm) fordistanceshould be the same as the units used forradius.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis zero, the robot rotates in place.The robot will stop when it has moved along the arc
distanceunits.
Ifdistanceis positive, the robot will move travel forwards.
Ifdistanceis negative, the robot will move travel backwards.
Ifdistanceis zero, the robot will not move and the method returns immediately.Postcondition: Motor speeds are unpredictable.
- Specified by:
travelArcin interfaceArcMoveController- 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 asradius. 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)
-
rotate
public void rotate(double angle)
Description copied from interface:RotateMoveControllerRotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter. Method returns when rotation is done.- Specified by:
rotatein interfaceRotateMoveController- Parameters:
angle- The angle to rotate in degrees. A positive value rotates left, a negative value right (clockwise).
-
rotate
public void rotate(double angle, boolean immediateReturn)Description copied from interface:RotateMoveControllerRotates the NXT robot the specified number of degrees; direction determined by the sign of the parameter. Method returns immediately if immediateReturn flag is true, otherwise returns when rotation is done.- Specified by:
rotatein interfaceRotateMoveController- Parameters:
angle- The angle to rotate in degrees. A positive value rotates left, a negative value right (clockwise).immediateReturn- If true, method returns immediately, otherwise blocks until rotation is complete.
-
rotateLeft
public void rotateLeft()
- Specified by:
rotateLeftin interfaceRotateMoveController
-
rotateRight
public void rotateRight()
- Specified by:
rotateRightin interfaceRotateMoveController
-
arc
public void arc(double radius, double angle, boolean immediateReturn)Description copied from interface:ArcMoveControllerMoves 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 theimmediateReturnparameter.If
radiusis positive, the robot arcs left, and the center of the turning circle is on the left side of the robot.
Ifradiusis negative, the robot arcs right, and the center of the turning circle is on the right side of the robot.
Ifradiusis zero, is zero, the robot rotates in place.The robot will stop when the degrees it has moved along the arc equals
angle.
Ifangleis positive, the robot will turn to the left (anti-clockwise).
Ifangleis negative, the robot will turn to the right (clockwise). Ifangleis 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:
arcin interfaceArcMoveController- 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 the robot turns: Positive is anti-clockwise, negative is clockwise.immediateReturn- If immediateReturn is true then the method returns immediately.- See Also:
ArcMoveController.travelArc(double, double, boolean)
-
stop
public void stop()
Description copied from interface:MoveControllerHalts the NXT robot- Specified by:
stopin interfaceMoveController
-
isMoving
public boolean isMoving()
Description copied from interface:MoveControllertrue if the robot is moving- Specified by:
isMovingin interfaceMoveController- Returns:
- true if the robot is moving under power.
-
getMovement
public Move getMovement()
Description copied from interface:MoveProviderReturns 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:
getMovementin interfaceMoveProvider- Returns:
- The move made since the move started.
-
addMoveListener
public void addMoveListener(MoveListener listener)
Description copied from interface:MoveProviderAdds a MoveListener that will be notified of all movement events.- Specified by:
addMoveListenerin interfaceMoveProvider- Parameters:
listener- the move listener
-
-