|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.nxt.Motor
public class Motor
Abstraction for a NXT motor. Three instances of Motor
are available: Motor.A
, Motor.B
and Motor.C
. To control each motor use
methods forward, backward, reverseDirection, stop
and flt
. To set each motor's speed, use
setSpeed. Speed is in degrees per second.
.\
Methods that use the tachometer: regulateSpeed, rotate, rotateTo
Motor has 2 modes : speedRegulation and smoothAcceleration. These are initially enabled. <>
They can be switched off/on by the methods regulateSpeed() and smoothAcceleration().
The actual maximum speed of the motor depends on battery voltage and load..
Speed regulation fails if the target speed exceeds the capability of the motor.
Example:
Motor.A.setSpeed(720);// 2 RPM
Motor.C.setSpeed(7200);
Motor.A.forward();
Motor.C.forward();
Thread.sleep (1000);
Motor.A.stop();
Motor.C.stop();
Motor.A.regulateSpeed(true);
Motor.A.rotateTo( 360);
Motor.A.rotate(-720,true);
while(Motor.A.isRotating();
int angle = Motor.A.getTachoCount(); // should be -360
Field Summary | |
---|---|
static Motor |
A
Motor A. |
static Motor |
B
Motor B. |
static Motor |
C
Motor C. |
lejos.nxt.Motor.Regulator |
regulator
|
Constructor Summary | |
---|---|
Motor(MotorPort port)
|
Method Summary | |
---|---|
void |
backward()
Causes motor to rotate backwards. |
void |
flt()
Causes motor to float. |
void |
forward()
Causes motor to rotate forward. |
int |
getActualSpeed()
returns actualSpeed degrees per second, calculated every 100 ms; negative value means motor is rotating backward |
int |
getLimitAngle()
Return the angle that a Motor is rotating to. |
int |
getMode()
Returns the mode. |
int |
getPower()
Returns the current power setting. |
int |
getSpeed()
Returns the current motor speed in degrees per second |
int |
getStopAngle()
|
int |
getTachoCount()
Returns the tachometer count. |
boolean |
isBackward()
Return true if motor is backward. |
boolean |
isFloating()
Returns true iff the motor is in float mode. |
boolean |
isForward()
Return true if motor is forward. |
boolean |
isMoving()
Returns true iff the motor is in motion. |
boolean |
isRotating()
returns true when motor is rotating towarad a specified angle |
boolean |
isStopped()
Return true if motor is stopped. |
void |
regulateSpeed(boolean yes)
turns speed regulation on/off; Cumulative speed error is within about 1 degree after initial acceleration. |
void |
resetTachoCount()
Resets the tachometer count to zero. |
void |
reverseDirection()
Reverses direction of the motor. |
void |
rotate(int angle)
causes motor to rotate through angle. |
void |
rotate(int angle,
boolean immediateReturn)
causes motor to rotate through angle; iff immediateReturn is true, method returns immediately and the motor stops by itself When the angle is reached, the method isRotating() returns false; |
void |
rotateTo(int limitAngle)
causes motor to rotate to limitAngle; Then getTachoCount should be within +- 2 degrees of the limit angle when the method returns |
void |
rotateTo(int limitAngle,
boolean immediateReturn)
causes motor to rotate to limitAngle; if immediateReturn is true, method returns immediately and the motor stops by itself Then getTachoCount should be within +- 2 degrees if the limit angle When the angle is reached, the method isRotating() returns false; |
void |
setPower(int power)
sets motor power. |
void |
setSpeed(int speed)
Sets motor speed , in degrees per second; Up to 900 is posssible with 8 volts. |
void |
shutdown()
causes run() to exit |
void |
smoothAcceleration(boolean yes)
enables smoother acceleration. |
void |
stop()
Causes motor to stop, pretty much instantaneously. |
void |
timedOut()
requred by TimerListener interface |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait |
Field Detail |
---|
public lejos.nxt.Motor.Regulator regulator
public static final Motor A
public static final Motor B
public static final Motor C
Constructor Detail |
---|
public Motor(MotorPort port)
Method Detail |
---|
public int getStopAngle()
public final boolean isMoving()
public void rotate(int angle)
angle
- through which the motor will rotatepublic void rotate(int angle, boolean immediateReturn)
angle
- through which the motor will rotateimmediateReturn
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.public void rotateTo(int limitAngle)
limitAngle
- to which the motor will rotatepublic void rotateTo(int limitAngle, boolean immediateReturn)
limitAngle
- to which the motor will rotate, and then stop.immediateReturn
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.public void shutdown()
public void regulateSpeed(boolean yes)
yes
- is true for speed regulation onpublic void smoothAcceleration(boolean yes)
public final void setSpeed(int speed)
speed
- value in degrees/secpublic void setPower(int power)
power
- power setting: 0 - 100public final int getSpeed()
public int getMode()
public int getPower()
public int getLimitAngle()
public final boolean isRotating()
public void timedOut()
timedOut
in interface TimerListener
public int getActualSpeed()
public int getTachoCount()
public void resetTachoCount()
public void forward()
public boolean isForward()
public void backward()
public boolean isBackward()
public void reverseDirection()
public void flt()
public boolean isFloating()
public void stop()
public boolean isStopped()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |