|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.robotics.navigation.TachoPilot
public class TachoPilot
The TachoPilot class is a software abstraction of the Pilot mechanism of a
NXT 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.
Note: this class will only work with two independently controlled motors to
steer differentially, so it can rotate within its own footprint (i.e. turn on
one spot).
It can be used with robots that have reversed motor design: the robot moves
in the direction opposite to the the direction of motor rotation. Uses the
Motor class, which regulates motor speed using the NXT motor's built in
tachometer.
Some methods optionally return immediately so the thread that called the
method can monitor sensors and call stop() if necessary.
Uses the smoothAcceleration property of Motors to improve motor
synchronization when starting a movement. Example:
Pilot pilot = new TachoPilot(2.1f, 4.4f, Motor.A, Motor.C, true); // parameters in inches
pilot.setRobotSpeed(10); // inches per second
pilot.travel(12); // inches
pilot.rotate(-90); // degree clockwise
pilot.travel(-12,true);
while(pilot.isMoving())Thread.yield();
pilot.rotate(-90);
pilot.rotateTo(270);
pilot.steer(-50,180,true);
while(pilot.isMoving())Thread.yield();
pilot.steer(100);
try{Thread.sleep(1000);}
catch(InterruptedException e){}
pilot.stop();
Field Summary | |
---|---|
protected TachoMotor |
_left
Left motor. |
protected float |
_leftDegPerDistance
Left motor degrees per unit of travel. |
protected float |
_leftTurnRatio
Left motor revolutions for 360 degree rotation of robot (motors running in opposite directions). |
protected float |
_leftWheelDiameter
Diameter of left wheel. |
protected int |
_motorSpeed
Motor speed degrees per second. |
protected TachoMotor |
_right
Right motor. |
protected float |
_rightDegPerDistance
Right motor degrees per unit of travel. |
protected float |
_rightTurnRatio
Right motor revolutions for 360 degree rotation of robot (motors running in opposite directions). |
protected float |
_rightWheelDiameter
Diameter of right wheel. |
protected float |
_robotMoveSpeed
Speed of robot for moving in wheel diameter units per seconds. |
protected float |
_robotTurnSpeed
Speed of robot for turning in degree per seconds. |
protected float |
_trackWidth
Distance between wheels. |
Constructor Summary | |
---|---|
TachoPilot(float leftWheelDiameter,
float rightWheelDiameter,
float trackWidth,
TachoMotor leftMotor,
TachoMotor rightMotor,
boolean reverse)
Allocates a TachoPilot object, and sets the physical parameters of the NXT robot. |
|
TachoPilot(float wheelDiameter,
float trackWidth,
TachoMotor leftMotor,
TachoMotor rightMotor)
Allocates a TachoPilot object, and sets the physical parameters of the NXT robot. Assumes Motor.forward() causes the robot to move forward. |
|
TachoPilot(float wheelDiameter,
float trackWidth,
TachoMotor leftMotor,
TachoMotor rightMotor,
boolean reverse)
Allocates a TachoPilot object, and sets the physical parameters of the NXT robot. |
Method Summary | |
---|---|
void |
arc(float radius)
Starts the NXT robot moving along an arc with a specified radius. |
void |
arc(float radius,
float angle)
Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving. |
void |
arc(float radius,
float angle,
boolean immediateReturn)
Moves the NXT robot along an arc with a specified radius and angle, after which the robot stops moving. |
void |
backward()
Moves the NXT robot backward until stop() is called. |
void |
forward()
Moves the NXT robot forward until stop() is called. |
float |
getAngle()
angle of rotation of the robot since last call to reset. |
TachoMotor |
getLeft()
|
int |
getLeftActualSpeed()
|
int |
getLeftCount()
|
float |
getMoveMaxSpeed()
|
float |
getMoveSpeed()
|
TachoMotor |
getRight()
|
int |
getRightActualSpeed()
|
int |
getRightCount()
|
float |
getTravelDistance()
distance traveled since the last call to reset. |
float |
getTurnMaxSpeed()
|
float |
getTurnRatio()
|
float |
getTurnSpeed()
|
boolean |
isMoving()
true if the robot is moving |
void |
regulateSpeed(boolean yes)
|
void |
reset()
Resets tacho count for both motors. |
void |
rotate(float angle)
Rotates the NXT robot through a specific angle. |
void |
rotate(float angle,
boolean immediateReturn)
Rotates the NXT robot through a specific angle. |
void |
setMoveSpeed(float speed)
also sets _motorSpeed |
void |
setSpeed(int speed)
Sets speed of both motors, as well as moveSpeed and turnSpeed. |
void |
setTurnSpeed(float speed)
Sets the turning speed of the robot. |
boolean |
stalled()
|
void |
steer(float turnRate)
Starts the robot moving along a curved path. |
void |
steer(float turnRate,
float angle)
Moves the robot along a curved path through a specified turn angle. |
void |
steer(float turnRate,
float angle,
boolean immediateReturn)
Moves the robot along a curved path for a specified angle of rotation. |
void |
stop()
Stops the NXT robot. |
void |
travel(float distance)
Moves the NXT robot a specific distance in an (hopefully) straight line. A positive distance causes forward motion, a negative distance moves backward. |
void |
travel(float distance,
boolean immediateReturn)
Moves the NXT robot a specific distance in an (hopefully) straight line. A positive distance causes forward motion, a negative distance moves backward. |
void |
travelArc(float radius,
float distance)
Moves the NXT robot a specified distance along an arc mof specified radius, after which the robot stops moving. |
void |
travelArc(float radius,
float 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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final TachoMotor _left
protected final TachoMotor _right
protected final float _leftDegPerDistance
protected final float _rightDegPerDistance
protected final float _leftTurnRatio
protected final float _rightTurnRatio
protected float _robotMoveSpeed
protected float _robotTurnSpeed
protected int _motorSpeed
protected final float _trackWidth
protected final float _leftWheelDiameter
protected final float _rightWheelDiameter
Constructor Detail |
---|
public TachoPilot(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor)
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).public TachoPilot(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor, boolean reverse)
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.public TachoPilot(float leftWheelDiameter, float rightWheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor, boolean reverse)
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.Method Detail |
---|
public TachoMotor getLeft()
public TachoMotor getRight()
public int getLeftCount()
public int getRightCount()
public int getLeftActualSpeed()
public int getRightActualSpeed()
public float getTurnRatio()
public void setSpeed(int speed)
setSpeed
in interface Pilot
speed
- The wanted speed in degrees per second.public void setMoveSpeed(float speed)
setMoveSpeed
in interface Pilot
speed
- The speed in wheel diameter units per second.Pilot.setMoveSpeed(float)
public float getMoveSpeed()
getMoveSpeed
in interface Pilot
Pilot.getMoveSpeed()
public float getMoveMaxSpeed()
getMoveMaxSpeed
in interface Pilot
Pilot.getMoveMaxSpeed()
public void setTurnSpeed(float speed)
Pilot
setTurnSpeed
in interface Pilot
speed
- The speed in degree per second.Pilot.setTurnSpeed(float)
public float getTurnSpeed()
getTurnSpeed
in interface Pilot
Pilot.getTurnSpeed()
public float getTurnMaxSpeed()
getTurnMaxSpeed
in interface Pilot
Pilot.getTurnMaxSpeed()
public void forward()
forward
in interface Pilot
public void backward()
backward
in interface Pilot
public void rotate(float angle)
rotate
in interface Pilot
angle
- The wanted angle of rotation in degrees. Positive angle rotate
left (clockwise), negative right.public void rotate(float angle, boolean immediateReturn)
rotate
in interface Pilot
angle
- The wanted angle of rotation in degrees. Positive angle rotate
left (clockwise), negative right.immediateReturn
- If true this method returns immediately.public float getAngle()
Pilot
getAngle
in interface Pilot
public void stop()
stop
in interface Pilot
public boolean isMoving()
Pilot
isMoving
in interface Pilot
public void reset()
reset
in interface Pilot
public float getTravelDistance()
Pilot
getTravelDistance
in interface Pilot
public void travel(float distance)
travel
in interface Pilot
distance
- The distance to move. Unit of measure for distance must be
same as wheelDiameter and trackWidth.public void travel(float distance, boolean immediateReturn)
travel
in interface Pilot
distance
- The distance to move. Unit of measure for distance must be
same as wheelDiameter and trackWidth.immediateReturn
- If true this method returns immediately.public void steer(float turnRate)
Pilot
Pilot.arc(float radius)
method except it uses a ratio of motor
speeds to determine the curvature of the path and therefore has the ability to drive straight. This makes
it usrful for line following applications.
The turnRate
specifies the sharpness of the turn, between -200 and +200.
The turnRate
is used to calculate the ratio of inner wheel speed to outer wheel speed as a percent.
Formula: ratio = 100 - abs(turnRate)
.
When the ratio is negative, the outer and inner wheels rotate in
opposite directions.
If turnRate
is positive, the center of the turning circle is on the left side of the robot.
If turnRate
is negative, the center of the turning circle is on the right side of the robot.
If turnRate
is zero, the robot travels in a straight line
Examples of how the formula works:
steer(0)
-> inner and outer wheels turn at the same speed, travel straight
steer(25)
-> the inner wheel turns at 75% of the speed of the outer wheel, turn left
steer(100)
-> the inner wheel stops and the outer wheel is at 100 percent, turn left
steer(200)
-> the inner wheel turns at the same speed as the outer wheel - a zero radius turn.
Note: If you have specified a drift correction in the constructor it will not be applied in this method.
steer
in interface Pilot
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.public void steer(float turnRate, float angle)
Pilot
Pilot.arc(float radius , float angle)
method except it uses a ratio of motor
speeds 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 does not return until the robot has
completed moving angle
degrees along the arc.turnRate
specifies the sharpness of the turn, between -200 and +200.Pilot.steer(float turnRate)
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.
Note: If you have specified a drift correction in the constructor it will not be applied in this method.
steer
in interface Pilot
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.public void steer(float turnRate, float angle, boolean immediateReturn)
Pilot
Pilot.arc(float radius, float angle, boolean immediateReturn)
method except it uses a ratio of motor
speeds to speeds 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, between -200 and +200.
For details about how this paramet works, see Pilot.steer(float turnRate)
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.
Note: If you have specified a drift correction in the constructor it will not be applied in this method.
steer
in interface Pilot
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 and your code MUST call
updatePostion() when the robot has stopped. Otherwise, the robot position is lost.public boolean stalled()
public void regulateSpeed(boolean yes)
public void arc(float radius)
Pilot
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 arc(float)
method can not drive a straight line, which makes
it impractical for line following. A better solution for line following is
Pilot.steer(float)
, which uses proportional steering and can drive straight lines and arcs.
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 Pilot
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.Pilot.steer(float)
public void arc(float radius, float angle)
Pilot
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.
The arc(float)
method can not drive a straight line, which makes
it impractical for line following. A better solution for line following is
Pilot.steer(float)
, which uses proportional steering and can drive straight lines and arcs.
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.
arc
in interface Pilot
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.Pilot.steer(float, float)
,
Pilot.travelArc(float, float)
public void arc(float radius, float angle, boolean immediateReturn)
Pilot
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 arc(float, float, boolean)
method can not drive a straight line, which makes
it impractical for line following. A better solution for line following is
Pilot.steer(float, float, boolean)
, which uses proportional steering and can drive straight lines and arcs.
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.
arc
in interface Pilot
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 and your code MUST call
updatePostion() when the robot has stopped. Otherwise, the robot position is lost.Pilot.steer(float, float, boolean)
,
Pilot.travelArc(float, float, boolean)
public void travelArc(float radius, float distance)
Pilot
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 travelArc(float, float)
method can not drive a straight line, which makes
it impractical for line following. A better solution for line following is
Pilot.steer(float)
, which uses proportional steering and can drive straight lines and arcs.
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.
Note: If you have specified a drift correction in the constructor it will not be applied in this method.
travelArc
in interface Pilot
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.Pilot.steer(float, float)
,
Pilot.arc(float, float)
public void travelArc(float radius, float distance, boolean immediateReturn)
Pilot
immediateReturn
parameter.
The units (inches, cm) for distance
should be the same as the units used for radius
.
Warning: Your code must call updatePostion() when the robot has stopped,
otherwise, the robot position is lost.
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 travelArc(float, float, boolean)
method can not drive a straight line, which makes
it impractical for line following. A better solution for line following is
Pilot.steer(float, float, boolean)
, which uses proportional steering and can drive straight lines and arcs.
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.
Note: If you have specified a drift correction in the constructor it will not be applied in this method.
travelArc
in interface Pilot
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 and your code MUST call
updatePostion() when the robot has stopped. Otherwise, the robot position is lost.Pilot.steer(float, float, boolean)
,
Pilot.arc(float, float, boolean)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |