|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object icommand.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 sc = new Pilot(2.1f,4.4f,Motor.A, Motor.C,true);
sc.setSpeed(720);// 2 RPM
sc.travel(12);
sc.rotate(-90);
sc.travel(-12,true);
while(sc.isMoving())Thread.yield();
sc.rotate(-90);
sc.rotateTo(270);
sc.steer(-50,180,true);
while(sc.isMoving())Thread.yield();
sc.steer(100);
try{Thread.sleep(1000);}
catch(InterruptedException e){}
sc.stop();
Field Summary | |
---|---|
double |
_degPerDistance
motor degrees per unit of travel |
Motor |
_left
left motor |
Motor |
_right
right motor |
protected int |
_speed
motor speed degrees per second. |
double |
_trackWidth
distance between wheels - used in steer() |
double |
_wheelDiameter
diameter of tires |
Constructor Summary | |
---|---|
Pilot(double wheelDiameter,
double trackWidth,
Motor leftMotor,
Motor rightMotor)
Allocates a Pilot object, and sets the physical parameters of the NXT robot. |
|
Pilot(double wheelDiameter,
double 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; |
int |
getLeftCount()
returns tachoCount of left motor; Positive value means motor has moved the robot forward; |
int |
getRightCount()
returns tachoCount of the right motor; Positive value means motor has moved the robot forward; |
int |
getSpeed()
Returns speed of both motors, degrees/sec |
double |
getTravelDistance()
returns distance taveled since last reset of tacho count |
double |
getTurnRatio()
return ratatio of Motor revolutions per 360 degree rotation of the robot |
boolean |
isMoving()
returns true iff the NXT robot is moving |
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(double distance)
Moves the NXT robot a specific distance; A positive distance causes forward motion; negative distance moves backward. |
void |
travel(double distance,
boolean immediateReturn)
Moves the NXT robot a specific distance; if immediateReturn is true, method returns immediately. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public Motor _left
public Motor _right
public final double _degPerDistance
protected int _speed
public final double _trackWidth
public final double _wheelDiameter
Constructor Detail |
---|
public Pilot(double wheelDiameter, double 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(double wheelDiameter, double 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 int getLeftCount()
public int getRightCount()
public double getTurnRatio()
public void setSpeed(int speed)
public int getSpeed()
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 double getTravelDistance()
public void travel(double distance)
distance
- of robot movement. Unit of measure for distance must be same as wheelDiameter and trackWidthpublic void travel(double 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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |