|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.navigation.TachoNavigator
public class TachoNavigator
The TachoNavigator class can keep track of the robot position and the direction angle it faces; It uses a _pilot object to control NXT robot movements.
The position and direction angle values are updated automatically when the movement command returns after the movement is complete and and after stop() command is issued.
However, some commands optionally return immediately, to permit sensor monitoring in the main thread. It is then the programmers responsibility to
call updatePosition() when the robot motion is completed. All angles are in degrees, distances in the units used to specify robot dimensions.
As with pilot, the robot must be have two independently controlled drive wheels.
The assumed initial position of the robot is at (0,0) and initial angle 0 i.e. pointing in the +X direction.
Field Summary | |
---|---|
protected float |
_heading
|
protected int |
_left0
|
protected Pilot |
_pilot
|
protected int |
_right0
|
Constructor Summary | |
---|---|
TachoNavigator(float wheelDiameter,
float driveLength)
Overloaded TachoNavigator constructor that assumes the following: Left motor = Motor.A Right motor = Motor.C |
|
TachoNavigator(float wheelDiameter,
float trackWidth,
Motor leftMotor,
Motor rightMotor)
|
|
TachoNavigator(float wheelDiameter,
float trackWidth,
Motor leftMotor,
Motor rightMotor,
boolean reverse)
Allocates a Navigator object and initializes it with the proper motors. |
|
TachoNavigator(Pilot pilot)
|
Method Summary | |
---|---|
float |
angleTo(float x,
float y)
returns the direction angle (degrees) to point with coordinates (x,y) |
void |
backward()
Moves the NXT robot backward until stop() is called. |
float |
distanceTo(float x,
float y)
distance from robot to the point with coordinates (x,y) . |
void |
forward()
Moves the NXT robot forward until stop() is called. |
float |
getAngle()
Returns the current angle the NXT robot is facing, relative to the +X axis direction; the +Y direction is 90 degrees. |
Pilot |
getPilot()
|
float |
getX()
Returns the current x coordinate of the NXT. |
float |
getY()
Returns the current y coordinate of the NXT. |
void |
goTo(float x,
float y)
Rotates the NXT robot towards the target point (x,y) and moves the required distance. |
void |
goTo(float x,
float y,
boolean immediateReturn)
Rotates the NXT robot towards the target point (x,y) and moves the required distance. |
boolean |
isMoving()
returns true iff the robot is moving under power |
void |
rotate(float angle)
Rotates the NXT robot a specific number of degrees in a direction (+ or -). |
void |
rotate(float angle,
boolean immediateReturn)
Rotates the NXT robot a specific number of degrees in a direction (+ or -). |
void |
rotateLeft()
Rotates the NXT to the left (increasing angle) until stop() is called; |
void |
rotateRight()
Rotates the NXT to the right (decreasing angle) until stop() is called; |
void |
rotateTo(float angle)
Rotates the NXT robot to point in a specific direction. |
void |
rotateTo(float angle,
boolean immediateReturn)
Rotates the NXT robot to point in a specific direction. |
void |
setPosition(float x,
float y,
float directionAngle)
sets robot location (x,y) and direction angle |
void |
setSpeed(int speed)
sets the motor speed of the robot, in degrees/second. |
void |
stop()
Halts the NXT robot and calculates new x, y coordinates. |
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 |
turn(float radius)
Moves the NXT robot in a circular path with a specified radius. |
void |
turn(float radius,
int angle)
Moves the NXT robot in a circular path through a specific angle; If waitForCompletion is true, returns when angle is reached. |
void |
turn(float radius,
int angle,
boolean immediateReturn)
Moves the NXT robot in a circular path through a specific angle; If waitForCompletion is true, returns when angle is reached. |
void |
updatePosition()
Updates robot location (x,y) and direction angle. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait |
Field Detail |
---|
protected float _heading
protected int _left0
protected int _right0
protected Pilot _pilot
Constructor Detail |
---|
public TachoNavigator(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)
wheelDiameter
- The diameter of the wheel, usually printed right on the
wheel, in centimeters (e.g. 49.6 mm = 4.96 cm = 1.95 in)trackWidth
- The distance from the center of the left tire to the center
of the right tire, in units of your choicerightMotor
- 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 TachoNavigator(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor)
public TachoNavigator(Pilot pilot)
public TachoNavigator(float wheelDiameter, float driveLength)
wheelDiameter
- The diameter of the wheel, usually printed right on the
wheel, in centimeters (e.g. 49.6 mm = 4.96 cm)driveLength
- The distance from the center of the left tire to the center
of the right tire,Method Detail |
---|
public Pilot getPilot()
public float getX()
getX
in interface Navigator
public float getY()
getY
in interface Navigator
public float getAngle()
getAngle
in interface Navigator
public void setPosition(float x, float y, float directionAngle)
setPosition
in interface Navigator
x
- the x coordinate of the roboty
- the y coordinate of the robotdirectionAngle
- the angle the robot is heading, measured from the x axis. 90 degrees is the +Y directionpublic void setSpeed(int speed)
setSpeed
in interface Navigator
public void forward()
forward
in interface Navigator
Navigator.stop().
public void backward()
backward
in interface Navigator
Navigator.stop().
public void stop()
stop
in interface Navigator
Navigator.forward().
public boolean isMoving()
isMoving
in interface Navigator
public void travel(float distance)
travel
in interface Navigator
distance
- The positive or negative distance to move the robot, same units as _wheelDiameterpublic void travel(float distance, boolean immediateReturn)
travel
in interface Navigator
distance
- The positive or negative distance to move the robot, same units as _wheelDiameterimmediateReturn
- iff true, the method returns immediately, in which case the programmer public void rotateLeft()
rotateLeft
in interface Navigator
public void rotateRight()
rotateRight
in interface Navigator
public void rotate(float angle)
rotate
in interface Navigator
angle
- Angle to rotate in degrees. A positive value rotates left, a negative value right.public void rotate(float angle, boolean immediateReturn)
rotate
in interface Navigator
angle
- Angle to rotate in degrees. A positive value rotates left, a negative value right.immediateReturn
- iff true, the method returns immediately, in which case the programmer public void rotateTo(float angle)
rotateTo
in interface Navigator
angle
- The angle to rotate to, in degrees.public void rotateTo(float angle, boolean immediateReturn)
rotateTo
in interface Navigator
angle
- The angle to rotate to, in degrees.immediateReturn
- iff true, method returns immediately and the programmer is responsible for calling
updatePosition() before the robot moves again.public void goTo(float x, float y)
goTo
in interface Navigator
x
- The x coordinate to move to.y
- The y coordinate to move to.public void goTo(float x, float y, boolean immediateReturn)
goTo
in interface Navigator
x
- The x coordinate to move to.y
- The y coordinate to move to.immediateReturn
- iff true, method returns immediatelypublic float distanceTo(float x, float y)
distanceTo
in interface Navigator
x
- coordinate of the pointy
- coordinate of the point
public float angleTo(float x, float y)
angleTo
in interface Navigator
x
- coordinate of the pointy
- coordinate of the point
public void updatePosition()
updatePosition
in interface Navigator
public void turn(float radius)
radius
- is 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 turn(float radius, int angle)
radius
- radius of the turning circleangle
- the angle by which the robot heading changes, + or -public void turn(float radius, int angle, boolean immediateReturn)
radius
- see turn(turnRage, angle)immediateReturn
- iff true, the method returns immediately, in which case the programmer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |