|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.nxt.addon.MMXRegulatedMotor
public class MMXRegulatedMotor
Supports Mindsensors NXTMMX motor multiplexer. This 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 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 |
getPower()
Returns the current motor power setting (%). |
int |
getRotationSpeed()
Returns the actual speed. |
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 is currently stalled after a motor action method is executed. |
void |
lock()
Locks the motor in current position. |
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 |
setPower(int power)
Set the power level 0-100% to be applied to the 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 |
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 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 float getMaxSpeed()
getMaxSpeed
in interface RegulatedMotor
public int getRotationSpeed()
getRotationSpeed
in interface Tachometer
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)
,
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()
,
setPower(int)
public int getPower()
getPower
in interface DCMotor
setPower(int)
,
getSpeed()
public void setPower(int power)
setPower
in interface DCMotor
power
- new motor power 0-100%setSpeed(int)
,
getPower()
public void forward()
forward
in interface BaseMotor
backward()
public void backward()
backward
in interface BaseMotor
forward()
public void flt(boolean immediateReturn)
flt
in interface RegulatedMotor
immediateReturn
- If true
do not wait for the motor to actually stopflt()
public void flt()
flt
in interface BaseMotor
flt(boolean)
,
lock()
,
stop()
public 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 void stop()
stop()
is
complete.
Cancels any rotate()
orders in progress.
stop
in interface BaseMotor
stop(boolean)
,
flt()
,
lock()
public void setRotateStopMode(int mode)
Default on instantiation is ROTSTOP_BRAKE
.
mode
- ROTSTOP_FLOAT
, ROTSTOP_BRAKE
, or
ROTSTOP_LOCK
rotate(int)
,
rotateTo(int)
public void lock()
stop()
,
flt()
public void waitComplete()
waitComplete
in interface RegulatedMotor
public int getTachoCount()
getTachoCount
in interface Encoder
resetTachoCount()
public void resetTachoCount()
resetTachoCount
in interface Encoder
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 is currently stalled after a motor action method is executed.
isStalled
in interface RegulatedMotor
true
if the motor is stalled, else false
forward()
,
backward()
,
rotate(int)
public 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
true
if the motor is rotating, false
otherwise.flt()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |