|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.navigation.Pilot
public class Pilot
The Pilot class is a software abstraction of the Pilot mechanism of a NXT robot. It contains methods to control robot movents: 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 Pilot 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 dirction 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 symchronication
Example:
Pilot pilot = new Pilot(2.1f,4.4f,Motor.A, Motor.C,true);
pilot.setSpeed(720);// 2 RPM
pilot.travel(12);
pilot.rotate(-90);
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 | |
---|---|
float |
_degPerDistance
motor degrees per unit of travel |
protected Motor |
_left
left motor |
protected Motor |
_right
right motor |
protected int |
_speed
motor speed degrees per second. |
float |
_trackWidth
distance between wheels - used in steer() |
float |
_wheelDiameter
diameter of tires |
Constructor Summary | |
---|---|
Pilot(float wheelDiameter,
float trackWidth,
Motor leftMotor,
Motor rightMotor)
Allocates a Pilot object, and sets the physical parameters of the NXT robot. |
|
Pilot(float wheelDiameter,
float trackWidth,
Motor leftMotor,
Motor rightMotor,
boolean reverse)
Allocates a Pilot object, and sets the physical parameters of the NXT robot. |
Method Summary | |
---|---|
void |
backward()
Moves the NXT robot backward until stop() is called. |
void |
forward()
Moves the NXT robot forward until stop() is called. |
int |
getAngle()
returns the angle of rotation of the robot since last call to reset of tacho count; |
Motor |
getLeft()
returns left motor |
int |
getLeftActualSpeed()
returns actual speed of left motor in degrees per second; a negative value if motor is rotating backwards Updated avery 100 ms. |
int |
getLeftCount()
returns tachoCount of left motor; Positive value means motor has moved the robot forward; |
Motor |
getRight()
returns right motor |
int |
getRightActualSpeed()
returns actual speed of right motor in deg/sec; a negative value if motor is rotating backwards. |
int |
getRightCount()
returns tachoCount of the right motor; Positive value means motor has moved the robot forward; |
int |
getSpeed()
return current speed setting |
float |
getTravelDistance()
returns distance taveled since last reset of tacho count |
float |
getTurnRatio()
return ratatio of Motor revolutions per 360 degree rotation of the robot |
boolean |
isMoving()
returns true iff the NXT robot is moving |
void |
regulateSpeed(boolean yes)
Sets motor speed regulation on = true (default) or off = false; Allows steer() method to be called by (for example) a line tracker or compass navigator so direction control is from sensor inputs |
void |
resetTachoCount()
resets tacho count for both motors |
void |
rotate(int angle)
Rotates the NXT robot through a specific angle; Rotates left if angle is positive, right if negative, Returns when angle is reached. |
void |
rotate(int angle,
boolean immediateReturn)
Rotates the NXT robot through a specific angle; Rotates left if angle is positive, right if negative; Returns immediately iff immediateReturn is true. |
void |
setSpeed(int speed)
Sets speed of both motors, degrees/sec; also sets retulate speed true |
void |
steer(int turnRate)
Moves the NXT robot in a circular path at a specific turn rate. |
void |
steer(int turnRate,
int angle)
Moves the NXT robot in a circular path through a specific angle; Negative turnRate means center of turning circle is on right side of the robot; Range of turnRate values : -200 : 200 ; Robot will stop when total rotation equals angle. |
void |
steer(int turnRate,
int angle,
boolean immediateReturn)
Moves the NXT robot in a circular path, and stops when the direction it is facing has changed by a specific angle; Returns immediately if immediateReturn is true. |
void |
stop()
Stops the NXT robot |
void |
travel(float distance)
Moves the NXT robot a specific distance; A positive distance causes forward motion; negative distance moves backward. |
void |
travel(float distance,
boolean immediateReturn)
Moves the NXT robot a specific distance; if immediateReturn is true, method returns immediately. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait |
Field Detail |
---|
protected Motor _left
protected Motor _right
public final float _degPerDistance
protected int _speed
public final float _trackWidth
public final float _wheelDiameter
Constructor Detail |
---|
public Pilot(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor)
wheelDiameter
- Diameter of the tire, in any convenient units. (The 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 wheelDiameterpublic Pilot(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)
wheelDiameter
- Diameter of the tire, in any convenient units. (The diameter in mm is usually printed on the tire).trackWidth
- Distance between center of right tire and center of left tire, in the same units as wheelDiameterreverse
- if true, the NXT robot moves forward when the motors are running backward.Method Detail |
---|
public Motor getLeft()
public Motor getRight()
public int getLeftCount()
public int getRightCount()
public int getLeftActualSpeed()
public int getRightActualSpeed()
public float getTurnRatio()
public int getSpeed()
public void setSpeed(int speed)
public void forward()
public void backward()
public void rotate(int angle)
angle
- degrees. Positive angle rotates to the left (clockwise); negative to the right. public void rotate(int angle, boolean immediateReturn)
angle
- degrees. Positive angle rotates to the left; negative to the right. immediateReturn
- if true this method returns immediatelypublic int getAngle()
public void stop()
public boolean isMoving()
public void resetTachoCount()
public float getTravelDistance()
public void travel(float distance)
distance
- of robot movement. Unit of measure for distance must be same as wheelDiameter and trackWidthpublic void travel(float distance, boolean immediateReturn)
immediateReturn
- If true, method returns immediately, and robot stops after traveling the distance. If false, method returns immediately.public void steer(int turnRate)
turnRate
- If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.
This parameter determines the ratio of inner wheel speed to outer wheel speed (as a percent). public void steer(int turnRate, int angle)
turnRate
- If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.
This parameter determines the ratio of inner wheel speed to outer wheel speed (as a percent). angle
- the angle through which the robot will rotate and then stop. If negative, robot traces the turning circle backwards.public void steer(int turnRate, int angle, boolean immediateReturn)
turnRate
- If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.
This parameter determines the ratio of inner wheel speed to outer wheel speed (as a percent). angle
- the angle through which the robot will rotate and then stop. If negative, robot traces the turning circle backwards.immediateReturn
- iff true, method returns immedediately.public void regulateSpeed(boolean yes)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |