|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectlejos.nxt.NXTRegulatedMotor
public class NXTRegulatedMotor
Abstraction for a NXT motor.
The basic control methods are:
forward, backward, reverseDirection, stop
and flt. To set each motor's velocity, use .
The maximum velocity of the motor is limited by the battery voltage and load.
With no load, the maximum degrees per second is about 100 times the voltage. setSpeed
The velocity is regulated by comparing the tacho count with velocity times elapsed
time, and adjusting motor power to keep these closely matched. Changes in velocity
will be made at the rate specified via the
setAcceleration(int acceleration) method.
The methods rotate(int angle) and rotateTo(int ange)
use the tachometer to control the position at which the motor stops, usually within 1 degree
or 2.
Listeners. An object implementing the interface may register with this class.
It will be informed each time the motor starts or stops.
RegulatedMotorListener
Stall detection If a stall is detected or if for some other reason
the speed regulation fails, the motor will stop, and
isStalled() returns true.
Motors will hold thier position when stopped. If this is not what you require use
the flt() method instead of stop().
Example:
Motor.A.setSpeed(720);// 2 RPM
Motor.C.setSpeed(720);
Motor.A.forward();
Motor.C.forward();
Delay.msDelay(1000);
Motor.A.stop();
Motor.C.stop();
Motor.A.rotateTo( 360);
Motor.A.rotate(-720,true);
while(Motor.A.isMoving()Thread.yield();
int angle = Motor.A.getTachoCount(); // should be -360
LCD.drawInt(angle,0,0);
| Nested Class Summary | |
|---|---|
protected static class |
NXTRegulatedMotor.Controller
This class provides a single thread that drives all of the motor regulation process. |
protected class |
NXTRegulatedMotor.Regulator
Inner class to regulate velocity; also stop motor at desired rotation angle. |
| Field Summary | |
|---|---|
protected int |
acceleration
|
protected static NXTRegulatedMotor.Controller |
cont
|
protected int |
limitAngle
|
protected RegulatedMotorListener |
listener
|
protected static int |
NO_LIMIT
|
protected NXTRegulatedMotor.Regulator |
reg
|
protected float |
speed
|
protected boolean |
stalled
|
protected int |
stallLimit
|
protected int |
stallTime
|
protected TachoMotorPort |
tachoPort
|
| Constructor Summary | |
|---|---|
NXTRegulatedMotor(TachoMotorPort port)
Use this constructor to assign a variable of type motor connected to a particular port. |
|
| Method Summary | |
|---|---|
void |
addListener(RegulatedMotorListener listener)
Add a motor listener. |
void |
backward()
Causes motor to rotate backwards until stop() or flt() is called. |
void |
flt()
Set the motor into float mode. |
void |
flt(boolean immediateReturn)
Set the motor into float mode. |
void |
forward()
Causes motor to rotate forward until stop() or flt() is called. |
int |
getAcceleration()
returns acceleration in degrees/second/second |
int |
getLimitAngle()
Return the angle that this Motor is rotating to. |
float |
getMaxSpeed()
Returns the maximim speed of the motor. |
int |
getPosition()
Returns the current position that the motor regulator is trying to maintain. |
int |
getRotationSpeed()
Return the current velocity. |
int |
getSpeed()
Return the current target speed. |
int |
getTachoCount()
Returns the tachometer count. |
boolean |
isMoving()
This method returns true if the motor is attempting to rotate. |
boolean |
isStalled()
Return true if the motor is currently stalled. |
void |
lock(int power)
Deprecated. The regulator will always try to hold position unless the motor is set into float mode using flt(). |
RegulatedMotorListener |
removeListener()
Removes the RegulatedMotorListener from this class. |
void |
resetTachoCount()
Reset the tachometer associated with this motor. |
void |
rotate(int angle)
Rotate by the requested number of degrees. |
void |
rotate(int angle,
boolean immediateReturn)
Rotate by the request number of degrees. |
void |
rotateTo(int limitAngle)
Rotate to the target angle. |
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 |
setAcceleration(int acceleration)
sets the acceleration rate of this motor in degrees/sec/sec The default value is 6000; Smaller values will make speeding up. |
void |
setSpeed(float speed)
Sets desired motor speed , in degrees per second; The maximum reliably sustainable velocity is 100 x battery voltage under moderate load, such as a direct drive robot on the level. |
void |
setSpeed(int speed)
Sets desired motor speed , in degrees per second; The maximum reliably sustainable velocity is 100 x battery voltage under moderate load, such as a direct drive robot on the level. |
void |
setStallThreshold(int error,
int time)
Set the parameters for detecting a stalled motor. |
void |
stop()
Causes motor to stop, pretty much instantaneously. |
void |
stop(boolean immediateReturn)
Causes motor to stop, pretty much instantaneously. |
boolean |
suspendRegulation()
Removes this motor from the motor regulation system. |
void |
waitComplete()
Wait until the current movement operation is complete (this can include the motor stalling). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int NO_LIMIT
protected final NXTRegulatedMotor.Regulator reg
protected TachoMotorPort tachoPort
protected boolean stalled
protected RegulatedMotorListener listener
protected float speed
protected int acceleration
protected int limitAngle
protected int stallLimit
protected int stallTime
protected static final NXTRegulatedMotor.Controller cont
| Constructor Detail |
|---|
public NXTRegulatedMotor(TachoMotorPort port)
port - to which this motor is connected| Method Detail |
|---|
public boolean suspendRegulation()
public int getTachoCount()
Encoder
getTachoCount in interface EncoderEncoder.getTachoCount()public int getPosition()
public void forward()
BaseMotorstop() or flt() is called.
forward in interface BaseMotorBasicMotor.forward()public void backward()
BaseMotorstop() or flt() is called.
backward in interface BaseMotorBasicMotor.backward()public void flt()
flt in interface BaseMotorpublic void flt(boolean immediateReturn)
flt in interface RegulatedMotorimmediateReturn - If true do not wait for the motor to actually stoppublic void stop()
stop in interface BaseMotorpublic void stop(boolean immediateReturn)
stop in interface RegulatedMotorimmediateReturn - if true do not wait for the motor to actually stoppublic boolean isMoving()
isStalled();
isMoving in interface BaseMotorpublic void waitComplete()
waitComplete in interface RegulatedMotor
public void rotateTo(int limitAngle,
boolean immediateReturn)
RegulatedMotor
rotateTo in interface RegulatedMotorlimitAngle - 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 setSpeed(int speed)
setSpeed in interface RegulatedMotorspeed - value in degrees/secpublic void setSpeed(float speed)
speed - value in degrees/secpublic void setAcceleration(int acceleration)
setAcceleration in interface RegulatedMotoracceleration - public int getAcceleration()
public int getLimitAngle()
getLimitAngle in interface RegulatedMotorpublic void resetTachoCount()
resetTachoCount in interface Encoderpublic void addListener(RegulatedMotorListener listener)
addListener in interface RegulatedMotorlistener - public RegulatedMotorListener removeListener()
RegulatedMotor
removeListener in interface RegulatedMotor
public void rotate(int angle,
boolean immediateReturn)
rotate in interface RegulatedMotorangle - number of degrees to rotate relative to the current positionimmediateReturn - if true do not wait for the move to completeRegulatedMotor.rotate(int, boolean)public void rotate(int angle)
rotate in interface RegulatedMotorangle - public void rotateTo(int limitAngle)
rotateTo in interface RegulatedMotorlimitAngle - Angle to rotate to.public int getSpeed()
getSpeed in interface RegulatedMotor@Deprecated public void lock(int power)
power - - a value between 1 and 100;public boolean isStalled()
isStalled in interface RegulatedMotor
public void setStallThreshold(int error,
int time)
setStallThreshold in interface RegulatedMotorerror - The error thresholdtime - The time that the error threshold needs to be exceeded for.public int getRotationSpeed()
getRotationSpeed in interface Tachometerpublic float getMaxSpeed()
RegulatedMotor
getMaxSpeed in interface RegulatedMotor
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||