|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectlejos.nxt.addon.MMXMotor
lejos.nxt.addon.MMXRegulatedMotor
public class MMXRegulatedMotor
Abstraction to drive a regulated encoder motor with the NXTMMX motor multiplexer. The NXTMMX motor multiplexer device allows you to connect two additional motors to your robot using a sensor port. Multiple NXTMMXs can be chained together.
Create an instance of this class passing a NXTMMX instance and Motor ID
( or MMX_MOTOR_1)
in the constructor.
MMX_MOTOR_2
NXTMMX| Field Summary | |
|---|---|
static int |
ROTSTOP_BRAKE
Use to specify motor brake when a rotate method completes. |
static int |
ROTSTOP_FLOAT
Use to specify motor float when a rotate method completes. |
static int |
ROTSTOP_LOCK
Use to specify active hold when a rotate method completes. |
| Constructor Summary | |
|---|---|
MMXRegulatedMotor(NXTMMX mux,
int motor)
Create an instance of a MMXRegulatedMotor. |
|
| Method Summary | |
|---|---|
void |
addListener(RegulatedMotorListener listener)
Add a single motor listener. |
void |
backward()
Causes motor to rotate backwards. |
void |
flt()
Causes motor to float. |
void |
flt(boolean immediateReturn)
Causes motor to float. |
void |
forward()
Causes motor to rotate forward. |
int |
getLimitAngle()
Return the absolute angle that this Motor is rotating to. |
float |
getMaxSpeed()
Return the maximum speed of the motor. |
int |
getRotationSpeed()
Returns the speed the motor is moving at. |
int |
getSpeed()
Return the current target speed. |
int |
getTachoCount()
Returns the tachometer count. |
boolean |
isMoving()
This method returns true if the motor is rotating, whether under power or not. |
boolean |
isStalled()
Return true if the motor has stalled after a motor action method was executed. |
void |
lock()
Locks the motor in current position. |
RegulatedMotorListener |
removeListener()
Remove the registered RegulatedMotorListener. |
void |
resetTachoCount()
Resets the tachometer count to zero. |
void |
rotate(int angle)
Rotate by the requested number of degrees. |
void |
rotate(int angle,
boolean immediateReturn)
Rotate by the requested number of degrees. |
void |
rotateTo(int limitAngle)
Rotate to the target angle. |
void |
rotateTo(int limitAngle,
boolean immediateReturn)
Rotate to the target angle. |
void |
setAcceleration(int acceleration)
Sets speed ramping is enabled/disabled for this motor. |
void |
setRotateStopMode(int mode)
Sets the motor stopping mode used for the rotate methods after rotation completion. |
void |
setSpeed(int speed)
Sets desired motor speed, in degrees per second. |
void |
setStallThreshold(int error,
int time)
Not implemented in the NXTMMX. |
void |
stop()
Causes motor to stop pretty much instantaneously. |
void |
stop(boolean immediateReturn)
Causes motor to stop pretty much instantaneously. |
void |
waitComplete()
Wait until the current movement operation is complete. |
| Methods inherited from class lejos.nxt.addon.MMXMotor |
|---|
getPower, setPower |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ROTSTOP_FLOAT
setRotateStopMode(int),
Constant Field Valuespublic static final int ROTSTOP_BRAKE
setRotateStopMode(int),
Constant Field Valuespublic static final int ROTSTOP_LOCK
setRotateStopMode(int),
Constant Field Values| Constructor Detail |
|---|
public MMXRegulatedMotor(NXTMMX mux,
int motor)
MMXRegulatedMotor.
mux - the motor multiplexor NXTMMX instance to bind this motor to.motor - the index of the motor connected to the NXTMMX: NXTMMX.MMX_MOTOR_1 or NXTMMX.MMX_MOTOR_2NXTMMX,
NXTMMX.MMX_MOTOR_1,
NXTMMX.MMX_MOTOR_2| Method Detail |
|---|
public void addListener(RegulatedMotorListener listener)
addListener in interface RegulatedMotorlistener - An instance of type RegulatedMotorListenerRegulatedMotorListenerpublic RegulatedMotorListener removeListener()
RegulatedMotorListener.
removeListener in interface RegulatedMotornull if none registered.public float getMaxSpeed()
getMaxSpeed in interface RegulatedMotorpublic int getRotationSpeed()
getRotationSpeed in interface Tachometerpublic void waitComplete()
forward() or backward() call.
waitComplete in interface RegulatedMotor
public void rotate(int angle,
boolean immediateReturn)
rotate in interface RegulatedMotorangle - number of degrees to rotate relative to the current positionimmediateReturn - true will not block, false will wait until completion or stall.rotate(int),
setRotateStopMode(int)public void rotate(int angle)
rotate in interface RegulatedMotorangle - number of degrees to rotate relative to the current positionrotate(int,boolean),
setRotateStopMode(int)
public void rotateTo(int limitAngle,
boolean immediateReturn)
immediateReturn is true, the 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.
When the angle is reached and the motor stops completely, the method
isMoving() returns false.
rotateTo in interface RegulatedMotorlimitAngle - Angle to rotate to.immediateReturn - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.getTachoCount(),
setRotateStopMode(int)public void rotateTo(int limitAngle)
rotateTo in interface RegulatedMotorlimitAngle - Angle to rotate to.rotateTo(int, boolean),
setRotateStopMode(int)public int getLimitAngle()
getLimitAngle in interface RegulatedMotorpublic int getSpeed()
getSpeed in interface RegulatedMotorsetSpeed(int),
MMXMotor.getPower()public void setSpeed(int speed)
The NXTMMX does not provide speed control per se (just power) so we approximate the power value used
based on the requested degress/sec (dps) passed in speed. This means if you request 400 dps, the actual dps value
may not reflect that. Setting speed during a rotate method will have no effect on the running rotate but will on the next rotate
method call.
experimental data gives: dps=8.1551*power+32.253 (unloaded @ 8.83V)
Note:The NXTMMX doesn't seem to want to drive the motor below ~40 dps.
setSpeed in interface RegulatedMotorspeed - Motor speed in degrees per secondgetSpeed(),
MMXMotor.setPower(int)public final void forward()
forward in interface BaseMotorforward in class MMXMotorbackward()public final void backward()
backward in interface BaseMotorbackward in class MMXMotorforward()public void flt(boolean immediateReturn)
flt in interface RegulatedMotorimmediateReturn - If true, do not wait for the motor to actually stopflt()public final void flt()
flt in interface BaseMotorflt in class MMXMotorflt(boolean),
lock(),
stop()public final void stop(boolean immediateReturn)
Cancels any rotate() orders in progress.
stop in interface RegulatedMotorimmediateReturn - if true, do not wait for the motor to actually stopstop()public final void stop()
stop() is
complete.
Cancels any rotate() orders in progress.
stop in interface BaseMotorstop in class MMXMotorstop(boolean),
flt(),
lock()public final void setRotateStopMode(int mode)
Default on instantiation is ROTSTOP_BRAKE.
mode - ROTSTOP_FLOAT, ROTSTOP_BRAKE, or
ROTSTOP_LOCKrotate(int),
rotateTo(int)public final void lock()
stop(),
flt()public final int getTachoCount()
getTachoCount in interface EncodergetTachoCount in class MMXMotorresetTachoCount()public final void resetTachoCount()
resetTachoCount in interface EncoderresetTachoCount in class MMXMotorgetTachoCount()public void setAcceleration(int acceleration)
RegulatedMotor interface specifies this in degrees/sec/sec
but the NXTMMX does not allow the rate to be changed, just if the motor uses smooth acceleration or not so we use the acceleration
parameter to specify ramping state. Default at instantiation is ramping enabled.
setAcceleration in interface RegulatedMotoracceleration - >0 means NXTMMX internal ramping is enabled otherwise disabledpublic boolean isStalled()
true if the motor has stalled after a motor action method was executed. The stalled status
will persist until movement occurs or a new movement or stop/flt command is issued.
isStalled in interface RegulatedMotortrue if the motor is stalled, else false.forward(),
backward(),
rotate(int)public final boolean isMoving()
true if the motor is rotating, whether under power or not.
The return value corresponds to the actual motor movement so if something external is rotating the motor,
isMoving() will return true.
After flt() is called, this method will return true until the motor
axle stops rotating by inertia, etc.
isMoving in interface BaseMotorisMoving in class MMXMotortrue if the motor is rotating, false otherwise.flt()
public void setStallThreshold(int error,
int time)
setStallThreshold in interface RegulatedMotorerror - ignoredtime - ignored
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||