|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.BasicMotor lejos.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. These rotate methods may not stop smoothly at the target angle if called when the motor is already moving
Motor has 2 modes : speedRegulation and smoothAcceleration which only works if speed regulation is used. These are initially enabled.
The speed is regulated by comparing the tacho count with speed times elapsed time and adjusting motor power to keep these closely matched.
Smooth acceleration corrects the speed regulation to account for the acceleration time.
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. With no load, the maximum is about 100 times the voltage.
Speed regulation fails if the target speed exceeds the capability of the motor.
If you need the motor to hold its position and you find that still moves after stop() is called , you can use the lock() method.
Example:
Motor.A.setSpeed(720);// 2 RPM
Motor.C.setSpeed(720);
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
Nested Class Summary | |
---|---|
class |
Motor.Regulator
inner class to regulate speed; also stop motor at desired rotation angle |
Field Summary | |
---|---|
TachoMotorPort |
_port
|
boolean |
_rampUp
set by smoothAcceleration, forward(),backward(), setSpeed(). |
static Motor |
A
Motor A. |
static Motor |
B
Motor B. |
static Motor |
C
Motor C. |
Motor.Regulator |
regulator
|
Constructor Summary | |
---|---|
Motor(TachoMotorPort port)
Use this constructor to assign a variable of type motor connected to a particular port. |
Method Summary | |
---|---|
void |
backward()
Causes motor to rotate backwards. |
void |
flt()
Causes motor to float. |
void |
forward()
Causes motor to rotate forward. |
float |
getBasePower()
for debugging |
float |
getError()
for debugging |
int |
getLimitAngle()
Return the angle that a Motor is rotating to. |
int |
getMode()
Returns the mode. |
int |
getPower()
Returns the current power setting. |
int |
getRotationSpeed()
Returns the actual speed. |
int |
getSpeed()
Returns the current motor speed in degrees per second |
int |
getStopAngle()
|
int |
getTachoCount()
Returns the tachometer count. |
boolean |
isMoving()
Returns true iff the motor is in motion. |
boolean |
isRegulating()
|
void |
lock(int power)
Applies power to hold motor in current position. |
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 by a specified 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 If any motor method is called before the limit is reached, the rotation is canceled. |
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 and getTachoCount should be within +- 2 degrees if the limit angle If any motor method is called before the limit is reached, the rotation is canceled. |
void |
setBrakePower(int pwr)
|
void |
setPower(int power)
sets motor power. |
void |
setSpeed(int speed)
Sets motor speed , in degrees per second; Up to 900 is possible 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. |
Methods inherited from class lejos.nxt.BasicMotor |
---|
isBackward, isFloating, isForward, isStopped |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public TachoMotorPort _port
public Motor.Regulator regulator
public boolean _rampUp
public static final Motor A
public static final Motor B
public static final Motor C
Constructor Detail |
---|
public Motor(TachoMotorPort port)
port
- to which this motor is connectedMethod Detail |
---|
public int getStopAngle()
public void forward()
BasicMotor
forward
in interface DCMotor
forward
in class BasicMotor
BasicMotor.forward()
public void backward()
BasicMotor
backward
in interface DCMotor
backward
in class BasicMotor
BasicMotor.backward()
public void reverseDirection()
reverseDirection
in class BasicMotor
public void flt()
BasicMotor
flt
in interface DCMotor
flt
in class BasicMotor
public void stop()
stop
in interface DCMotor
stop
in class BasicMotor
public void lock(int power)
power
- - a value between 1 and 100;public boolean isMoving()
BasicMotor
isMoving
in interface DCMotor
isMoving
in class BasicMotor
public void rotate(int angle)
TachoMotor
rotate
in interface TachoMotor
angle
- by which the motor will rotate.public void rotate(int angle, boolean immediateReturn)
TachoMotor
rotate
in interface TachoMotor
angle
- through which the motor will rotateimmediateReturn
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.TachoMotor.rotate(int, boolean)
public void rotateTo(int limitAngle)
TachoMotor
rotateTo
in interface TachoMotor
limitAngle
- to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.public void rotateTo(int limitAngle, boolean immediateReturn)
TachoMotor
rotateTo
in interface TachoMotor
limitAngle
- to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.immediateReturn
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.public void shutdown()
public void regulateSpeed(boolean yes)
regulateSpeed
in interface TachoMotor
yes
- is true for speed regulation onpublic void smoothAcceleration(boolean yes)
smoothAcceleration
in interface TachoMotor
yes
- is true for smooth acceleration.public void setSpeed(int speed)
setSpeed
in interface TachoMotor
speed
- value in degrees/secpublic void setPower(int power)
setPower
in class BasicMotor
power
- power setting: 0 - 100public int getSpeed()
getSpeed
in interface TachoMotor
public int getMode()
BasicMotor
getMode
in class BasicMotor
public int getPower()
BasicMotor
getPower
in class BasicMotor
public int getLimitAngle()
public boolean isRegulating()
public int getRotationSpeed()
Tachometer
getRotationSpeed
in interface Tachometer
Tachometer.getRotationSpeed()
public int getTachoCount()
Encoder
getTachoCount
in interface Encoder
Encoder.getTachoCount()
public void resetTachoCount()
resetTachoCount
in interface Encoder
public float getError()
public float getBasePower()
public void setBrakePower(int pwr)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |