Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## lejos.navigation
Class Pilot

    java.lang.Object
      lejos.navigation.Pilot

    public class Pilot

extends Object

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
`float` | `_degPerDistance` motor degrees per unit of travel
`Motor` | `_left` left motor
`Motor` | `_right` right motor
`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;
`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;
`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;
`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) 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

### _left

    public Motor _left

  left motor

### _right

    public Motor _right

  right motor

### _degPerDistance

    public final float _degPerDistance

  motor degrees per unit of travel

### _trackWidth

    public final float _trackWidth

  distance between wheels - used in steer()

### _wheelDiameter

    public final float _wheelDiameter

  diameter of tires

Constructor Detail

### Pilot

    public Pilot(float wheelDiameter,
                 float trackWidth,
                 Motor leftMotor,
                 Motor rightMotor)

  Allocates a Pilot object, and sets the physical parameters of the NXT robot.
  Assumes Motor.forward() causes the robot to move forward);

  Parameters:
    `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 wheelDiameter

### Pilot

    public Pilot(float wheelDiameter,
                 float trackWidth,
                 Motor leftMotor,
                 Motor rightMotor,
                 boolean reverse)

  Allocates a Pilot object, and sets the physical parameters of the NXT robot.

  Parameters:
    `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 wheelDiameter
    `reverse` - if true, the NXT robot moves forward when the motors are running backward.

Method Detail

### getLeftCount

    public int getLeftCount()

  returns tachoCount of left motor; Positive value means motor has moved the robot forward;

### getRightCount

    public int getRightCount()

  returns tachoCount of the right motor; Positive value means motor has moved the robot forward;

### getLeftActualSpeed

    public int getLeftActualSpeed()

  returns actual speed of left motor in degrees per second; a negative value if motor is rotating backwards
  Updated avery 100 ms.

### getRightActualSpeed

    public int getRightActualSpeed()

  returns actual speed of right motor in deg/sec; a negative value if motor is rotating backwards.
  Updated avery 100 ms.

### getTurnRatio

    public float getTurnRatio()

  return ratatio of Motor revolutions per 360 degree rotation of the robot

### setSpeed

    public void setSpeed(int speed)

  Sets speed of both motors, degrees/sec; also sets retulate speed true

### forward

    public void forward()

  Moves the NXT robot forward until stop() is called.

### backward

    public void backward()

  Moves the NXT robot backward until stop() is called.

### rotate

    public 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. Wheels turn in opposite directions producing a zero radius turn.

  Parameters:
    `angle` - degrees. Positive angle rotates to the left (clockwise); negative to the right.
    Requires correct values for wheel diameter and track width.

### rotate

    public 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. Wheels turn in opposite directions producing a zero radius turn.

  Parameters:
    `angle` - degrees. Positive angle rotates to the left; negative to the right.
    Requires correct values for wheel diameter and track width.
    `immediateReturn` - if true this method returns immediately

### getAngle

    public int getAngle()

  returns the angle of rotation of the robot since last call to reset of tacho count;

### stop

    public void stop()

  Stops the NXT robot

### isMoving

    public boolean isMoving()

  returns true iff the NXT robot is moving

### resetTachoCount

    public void resetTachoCount()

  resets tacho count for both motors

### getTravelDistance

    public float getTravelDistance()

  returns distance taveled since last reset of tacho count

### travel

    public void travel(float distance)

  Moves the NXT robot a specific distance;
  A positive distance causes forward motion; negative distance moves backward.

  Parameters:
    `distance` - of robot movement. Unit of measure for distance must be same as wheelDiameter and trackWidth

### travel

    public void travel(float distance,
                       boolean immediateReturn)

  Moves the NXT robot a specific distance; if immediateReturn is true, method returns immediately.
  A positive distance causes forward motion; negative distance moves backward.

  Parameters:
    `immediateReturn` - If true, method returns immediately, and robot stops after traveling the distance. If false, method returns immediately.

### steer

    public void steer(int turnRate)

  Moves the NXT robot in a circular path at a specific turn rate.
  The center of the turning circle is on the right side of the robot iff parameter turnRate is negative;
  turnRate values are between -200 and +200;

  Parameters:
    `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).
    Formula: ratio = 100 - abs(turnRate). When the ratio is negative, the outer and inner wheels rotate in opposite directions.
    Examples:
    - steer(25)-> inner wheel turns at 75% of the speed of the outer wheel
    - steer(100) -> inner wheel stops.
    - steer(200) -> means that the inner wheel turns at the same speed as the outer wheel - a zero radius turn.

### steer

    public 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. If angle is negative, robot will move travel backwards.

  Parameters:
    `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.

### steer

    public 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. The robot will stop automatically when the turm is complete. The center of the turning circle is on right side of the robot iff parameter turnRate is negative
  turnRate values are between -200 and +200;

  Parameters:
    `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.

### regulateSpeed

    public 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) so direction control is from sensor inputs

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD