|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.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 ValuesConstructor 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_2
NXTMMX
,
NXTMMX.MMX_MOTOR_1
,
NXTMMX.MMX_MOTOR_2
Method Detail |
---|
public void addListener(RegulatedMotorListener listener)
addListener
in interface RegulatedMotor
listener
- An instance of type RegulatedMotorListener
RegulatedMotorListener
public RegulatedMotorListener removeListener()
RegulatedMotorListener
.
removeListener
in interface RegulatedMotor
null
if none registered.public float getMaxSpeed()
getMaxSpeed
in interface RegulatedMotor
public int getRotationSpeed()
getRotationSpeed
in interface Tachometer
public void waitComplete()
forward()
or backward()
call.
waitComplete
in interface RegulatedMotor
public void rotate(int angle, boolean immediateReturn)
rotate
in interface RegulatedMotor
angle
- 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 RegulatedMotor
angle
- 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 RegulatedMotor
limitAngle
- 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 RegulatedMotor
limitAngle
- Angle to rotate to.rotateTo(int, boolean)
,
setRotateStopMode(int)
public int getLimitAngle()
getLimitAngle
in interface RegulatedMotor
public int getSpeed()
getSpeed
in interface RegulatedMotor
setSpeed(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 RegulatedMotor
speed
- Motor speed in degrees per secondgetSpeed()
,
MMXMotor.setPower(int)
public final void forward()
forward
in interface BaseMotor
forward
in class MMXMotor
backward()
public final void backward()
backward
in interface BaseMotor
backward
in class MMXMotor
forward()
public void flt(boolean immediateReturn)
flt
in interface RegulatedMotor
immediateReturn
- If true
, do not wait for the motor to actually stopflt()
public final void flt()
flt
in interface BaseMotor
flt
in class MMXMotor
flt(boolean)
,
lock()
,
stop()
public final void stop(boolean immediateReturn)
Cancels any rotate()
orders in progress.
stop
in interface RegulatedMotor
immediateReturn
- 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 BaseMotor
stop
in class MMXMotor
stop(boolean)
,
flt()
,
lock()
public final void setRotateStopMode(int mode)
Default on instantiation is ROTSTOP_BRAKE
.
mode
- ROTSTOP_FLOAT
, ROTSTOP_BRAKE
, or
ROTSTOP_LOCK
rotate(int)
,
rotateTo(int)
public final void lock()
stop()
,
flt()
public final int getTachoCount()
getTachoCount
in interface Encoder
getTachoCount
in class MMXMotor
resetTachoCount()
public final void resetTachoCount()
resetTachoCount
in interface Encoder
resetTachoCount
in class MMXMotor
getTachoCount()
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 RegulatedMotor
acceleration
- >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 RegulatedMotor
true
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 BaseMotor
isMoving
in class MMXMotor
true
if the motor is rotating, false
otherwise.flt()
public void setStallThreshold(int error, int time)
setStallThreshold
in interface RegulatedMotor
error
- ignoredtime
- ignored
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |