|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.robotics.navigation.SimpleNavigator
public class SimpleNavigator
The SimpleNavigator class uses dead reckoning to keep track of its robot pose (the location in the plane
and its heading - the direction in which it moves). While dead reckoning is relatively
easy to implement and very quick to caolculate, its disadvantage
is that errors in the estimated pose accumulate.
SimpleNavigator can perform three elementary movements in a plane: trvel in a straignt line,
move in the arc of a circle, and a rotate in place. The movement commands
have an immediate return option which is useful, for example, for a client
class that uses s SimpleNavigataor to detect obstacles or monitor incoming messages while moving.
This class uses a private Pilot object to execute these moves. The Pilot directly
controls the hardware, which must be able to turn in place,
for example using 2 wheel differential steering. The Pilot is passed to the Navitator
a the parameter of its constructor. After the Navigator is constructed,
the client has no further need for the Pilot, but issues commands to the Navigator.
If the client bypasses the navigator and issues commsnds directly to the Pilot, this will destroy
the accuracy of the Navigataor's pose.
A note about coordinates: All angles are in degrees, distances in the units used to specify robot dimensions.
Angles related to positions in the plane are relative to the X axis ; direction of the Y axis is 90 degrees.
The x and y coordinate values and the direction angle are all initialized to 0, so if the first move is forward() the robot will run along
the x axis.
Constructor Summary | |
---|---|
SimpleNavigator(float wheelDiameter,
float trackWidth,
TachoMotor leftMotor,
TachoMotor rightMotor)
Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about! |
|
SimpleNavigator(float wheelDiameter,
float trackWidth,
TachoMotor leftMotor,
TachoMotor rightMotor,
boolean reverse)
Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about! |
|
SimpleNavigator(Pilot pilot)
Allocates a SimpleNavigator with a Pilot that you supply. |
Method Summary | |
---|---|
float |
angleTo(float x,
float y)
Returns the angle from robot current location to the point with coordinates x,y |
void |
arc(float radius)
Starts the NXT robot moving in a circular path with a specified radius; The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. |
void |
arc(float radius,
int angle)
Moves the NXT robot in a circular arc through the specified angle; The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. |
void |
arc(float radius,
int angle,
boolean immediateReturn)
Moves the NXT robot in a circular arc through a specific angle; The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. |
void |
backward()
|
float |
distanceTo(float x,
float y)
Returns the distance from robot current location to the point with coordinates x,y |
void |
forward()
|
float |
getAngle()
gets the current robot pose |
float |
getHeading()
gets the current value of the robot heading |
Pose |
getPose()
|
float |
getX()
gets the current value of the X coordinate |
float |
getY()
gets the current value of the Y coordinate |
void |
goTo(float x,
float y)
Robot moves to grid coordinates x,y. |
void |
goTo(float x,
float y,
boolean immediateReturn)
Robot moves to grid coordinates x,y. |
boolean |
isMoving()
returns true if the robot is moving |
void |
rotate(float angle)
Rotates the NXT robot through a specific number of degrees in a direction (+ or -). |
void |
rotate(float angle,
boolean immediateReturn)
Rotates the NXT robot through a specific number of degrees in a direction (+ or -). |
void |
rotateLeft()
|
void |
rotateRight()
|
void |
rotateTo(float angle)
Rotates the NXT robot to point in a specific direction, using the smallest rotation necessary |
void |
rotateTo(float angle,
boolean immediateReturn)
Rotates the NXT robot to point in a specific direction relative to the x axis. |
void |
setMoveSpeed(float speed)
sets the robots movement speed - distance units/second |
void |
setPose(float x,
float y,
float heading)
sets the robot pose to the new coordinates and heading |
void |
setPose(Pose pose)
sets the robot pose |
void |
setPosition(float x,
float y,
float heading)
|
void |
setTurnSpeed(float speed)
sets the robot turn speed -degrees/second |
void |
steer(int turnRate)
Starts the robot moving along a curved path. |
void |
steer(int turnRate,
int angle)
Moves the robot along a curved path through a specified turn angle. |
void |
steer(int turnRate,
int angle,
boolean immediateReturn)
Moves the robot along a curved path for a specified angle of rotation. |
void |
stop()
Stops the robot. |
void |
travel(float distance)
Moves the NXT robot a specific distance. |
void |
travel(float distance,
boolean immediateReturn)
Moves the NXT robot a specific distance. |
void |
travelArc(float radius,
float distance)
Moves the NXT robot in a circular arc through a specific distance; The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. |
void |
travelArc(float radius,
float distance,
boolean immediateReturn)
Moves the NXT robot in a circular arc through a specific distance; The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. |
void |
updatePose()
|
void |
updatePosition()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleNavigator(Pilot pilot)
pilot
- can be any class that implements the pilot interfacepublic SimpleNavigator(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor, boolean reverse)
wheelDiameter
- The diameter of the wheel, usually printed on the Lego tire.
Use any units you wish (e.g. 56 mm = 5.6 cm = 2.36 in)trackWidth
- The distance from the center of the left tire to the center
of the right tire, same units as wheel diameterrightMotor
- The motor used to drive the right wheel e.g. Motor.C.leftMotor
- The motor used to drive the left wheel e.g. Motor.A.reverse
- If motor.forward() dives the robot backwars, set this parameter true.public SimpleNavigator(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor)
wheelDiameter
- The diameter of the wheel, usually printed on the Lego tire.
Use any units you wish (e.g. 56 mm = 5.6 cm = 2.36 in)trackWidth
- The distance from the center of the left tire to the center
of the right tire, sane units as wheel diameterrightMotor
- The motor used to drive the right wheel e.g. Motor.C.leftMotor
- The motor used to drive the left wheel e.g. Motor.AMethod Detail |
---|
public float getX()
public float getY()
public float getHeading()
public float getAngle()
public void forward()
public void backward()
public void rotateLeft()
public void rotateRight()
public Pose getPose()
public void updatePosition()
public void setPose(float x, float y, float heading)
x
- coordinatey
- coordinateheading
- direction of robot forward movementpublic void setPose(Pose pose)
pose
- new posepublic void setPosition(float x, float y, float heading)
public void setMoveSpeed(float speed)
speed
- public void setTurnSpeed(float speed)
speed
- public void stop()
public boolean isMoving()
public void travel(float distance)
distance
- The positive or negative distance to move the robot, same units as _wheelDiameterpublic void travel(float distance, boolean immediateReturn)
distance
- The positive or negative distance to move the robot, same units as _wheelDiameterimmediateReturn
- if true, the method returns immediatelypublic void rotate(float angle)
angle
- Angle to rotate in degrees. A positive value rotates left, a negative value right.public void rotate(float angle, boolean immediateReturn)
angle
- Angle to rotate in degrees. A positive value rotates left, a negative value right.immediateReturn
- if true, the method returns immediatelypublic void rotateTo(float angle)
angle
- The angle to rotate to, in degrees.public void rotateTo(float angle, boolean immediateReturn)
angle
- The angle to rotate to, in degrees.immediateReturn
- if true, method returns immediatelypublic void goTo(float x, float y)
x
- destination X coordinatey
- destination Y coordinatepublic void goTo(float x, float y, boolean immediateReturn)
x
- destination X coordinatey
- destination Y coordinatepublic float distanceTo(float x, float y)
x
- coordinate of destinationy
- coordinate of destination
public float angleTo(float x, float y)
x
- coordinate of destinationy
- coordinate of destination
public void updatePose()
public void arc(float radius)
radius
- - the radius of the circular path. If positive, the left wheel is on the inside of the turn.
If negative, the left wheel is on the outside.public void arc(float radius, int angle)
travelArc(float radius, float distance)
radius
- - the radius of the circular path. If positive, the left wheel is on the inside of the turn.
If negative, the left wheel is on the outside.public void arc(float radius, int angle, boolean immediateReturn)
travelArc(float radius, float distance, boolean immedisteReturn)
radius
- - the radius of the circular path. If positive, the left wheel is on the inside of the turn.
If negative, the left wheel is on the outside.angle
- The sign of the angle determines the direction of robot motionimmediateReturn
- if true, the method returns immediatelypublic void travelArc(float radius, float distance)
arc(float radius, int angle)
radius
- of the turning circle; the sign determines if the center if the turn is left or right of the robot.distance
- The sign of the distance determines the direction of robot motion
updatePosition() before the robot moves again.public void travelArc(float radius, float distance, boolean immediateReturn)
arc(float radius, int angle, boolean immediateReturn)
radius
- of the turning circle; the sign determines if the center if the turn is left or right of the robot.distance
- The sign of the distance determines the direction of robot motionimmediateReturn
- if true, the method returns immediately.public void steer(int turnRate)
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 useful 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.
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(int turnRate, int angle)
arc(float radius , int 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.steer(int 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.
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(int turnRate, int angle, boolean immediateReturn)
arc(float radius, int 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 steer(int 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.
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |