Package lejos.hardware.device
Class MMXRegulatedMotor
- java.lang.Object
-
- lejos.hardware.device.MMXMotor
-
- lejos.hardware.device.MMXRegulatedMotor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,BaseMotor,DCMotor,Encoder,EncoderMotor,RegulatedMotor,Tachometer
public class MMXRegulatedMotor extends MMXMotor implements RegulatedMotor
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.Use the
NXTMMX.getRegulatedMotor()factory method to retrieve an instance of this class.- Author:
- Kirk P. Thompson
- See Also:
NXTMMX
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(RegulatedMotorListener listener)Adds a listener object that will be notified when rotation has started or stoppedvoidclose()Close the port, the port can not be used after this call.voidendSynchronization()Complete a set of synchronized motor operations.voidflt(boolean immediateReturn)Set the motor into float mode.intgetLimitAngle()Return the angle that this Motor is rotating to or last rotated to.floatgetMaxSpeed()Returns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.intgetRotationSpeed()Return the current rotational speed calculated from the encoder position every 100 ms.intgetSpeed()Return the current target speed.booleanisStalled()returns true if motor is stalledRegulatedMotorListenerremoveListener()Removes the RegulatedMotorListener from this class.voidrotate(int angle)Rotate by the requested number of degrees while blocking until completion.voidrotate(int degrees, boolean immediateReturn)Rotate by the requested number of degrees with option for wait until completion or immediate return where the motor completes its rotation asynchronously.voidrotateTo(int limitAngle)Rotate to the target angle while blocking until completion.voidrotateTo(int limitAngle, boolean immediateReturn)Rotate to the target angle with option for wait until completion or immediate return where the motor completes its rotation asynchronously.voidsetAcceleration(int acceleration)Sets speed ramping is enabled/disabled for this motor.voidsetSpeed(int speed)Sets desired motor speed, in degrees per second.voidsetStallThreshold(int error, int time)NOT IMPLEMENTED as the NXTMMX motor controller does not support this command.voidstartSynchronization()Begin a set of synchronized motor operationsvoidstop(boolean immediateReturn)Causes motor to stop, pretty much instantaneously.voidsynchronizeWith(RegulatedMotor[] syncList)Specify a set of motors that should be kept in synchronization with this one.voidwaitComplete()Wait until the current movement operation is complete (this can include the motor stalling).-
Methods inherited from class lejos.hardware.device.MMXMotor
backward, flt, forward, getPower, getTachoCount, isMoving, resetTachoCount, setPower, setRamping, setRegulate, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface lejos.robotics.Encoder
getTachoCount, resetTachoCount
-
-
-
-
Method Detail
-
addListener
public void addListener(RegulatedMotorListener listener)
Description copied from interface:RegulatedMotorAdds a listener object that will be notified when rotation has started or stopped- Specified by:
addListenerin interfaceRegulatedMotor
-
removeListener
public RegulatedMotorListener removeListener()
Description copied from interface:RegulatedMotorRemoves the RegulatedMotorListener from this class.- Specified by:
removeListenerin interfaceRegulatedMotor- Returns:
- The RegulatedMotorListener that was removed, if any. Null if none existed.
-
getRotationSpeed
public int getRotationSpeed()
Return the current rotational speed calculated from the encoder position every 100 ms. This will likely differ from what was specified insetSpeed.- Specified by:
getRotationSpeedin interfaceTachometer- Returns:
- The current rotational speed in deg/sec
-
stop
public void stop(boolean immediateReturn)
Description copied from interface:RegulatedMotorCauses motor to stop, pretty much instantaneously. In other words, the motor doesn't just stop; it will resist any further motion. Cancels any rotate() orders in progress- Specified by:
stopin interfaceRegulatedMotor- Parameters:
immediateReturn- if true do not wait for the motor to actually stop
-
flt
public void flt(boolean immediateReturn)
Description copied from interface:RegulatedMotorSet the motor into float mode. This will stop the motor without braking and the position of the motor will not be maintained.- Specified by:
fltin interfaceRegulatedMotor- Parameters:
immediateReturn- If true do not wait for the motor to actually stop
-
waitComplete
public void waitComplete()
Description copied from interface:RegulatedMotorWait until the current movement operation is complete (this can include the motor stalling).- Specified by:
waitCompletein interfaceRegulatedMotor
-
rotate
public void rotate(int angle)
Rotate by the requested number of degrees while blocking until completion.- Specified by:
rotatein interfaceRegulatedMotor- Parameters:
angle- number of degrees to rotate relative to the current position.
-
rotateTo
public void rotateTo(int limitAngle)
Rotate to the target angle while blocking until completion.- Specified by:
rotateToin interfaceRegulatedMotor- Parameters:
limitAngle- Angle [in degrees] to rotate to.
-
rotate
public void rotate(int degrees, boolean immediateReturn)Rotate by the requested number of degrees with option for wait until completion or immediate return where the motor completes its rotation asynchronously.- Specified by:
rotatein interfaceRegulatedMotor- Parameters:
degrees- number of degrees to rotate relative to the current position.immediateReturn- iftrue, do not wait for the move to complete.falsewill block until the rotation completes.- See Also:
RegulatedMotor.rotate(int, boolean)
-
rotateTo
public void rotateTo(int limitAngle, boolean immediateReturn)Rotate to the target angle with option for wait until completion or immediate return where the motor completes its rotation asynchronously.- Specified by:
rotateToin interfaceRegulatedMotor- Parameters:
limitAngle- Angle [in degrees] to rotate to.immediateReturn- iftrue, do not wait for the move to complete.falsewill block until the rotation completes.
-
setSpeed
public void setSpeed(int speed)
Sets desired motor speed, in degrees per second.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 standard NXT motor below ~40 dps.
- Specified by:
setSpeedin interfaceRegulatedMotor- Parameters:
speed- Motor speed in degrees per second- See Also:
getSpeed(),MMXMotor.setPower(int)
-
getSpeed
public int getSpeed()
Return the current target speed.- Specified by:
getSpeedin interfaceRegulatedMotor- Returns:
- Motor speed in degrees per second.
- See Also:
setSpeed(int),MMXMotor.getPower()
-
getMaxSpeed
public float getMaxSpeed()
Description copied from interface:RegulatedMotorReturns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.- Specified by:
getMaxSpeedin interfaceRegulatedMotor- Returns:
- the maximum speed of the Motor in degrees per second.
-
isStalled
public boolean isStalled()
Description copied from interface:RegulatedMotorreturns true if motor is stalled- Specified by:
isStalledin interfaceRegulatedMotor- Returns:
- true if stalled
-
setStallThreshold
public void setStallThreshold(int error, int time)NOT IMPLEMENTED as the NXTMMX motor controller does not support this command.- Specified by:
setStallThresholdin interfaceRegulatedMotor- Parameters:
error- The error thresholdtime- The time that the error threshold needs to be exceeded for.
-
setAcceleration
public void setAcceleration(int acceleration)
Sets speed ramping is enabled/disabled for this motor. TheRegulatedMotorinterface 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 theaccelerationparameter to specify ramping state.Default at instantiation is ramping enabled.
- Specified by:
setAccelerationin interfaceRegulatedMotor- Parameters:
acceleration- >0 means NXTMMX internal ramping is enabled otherwise disabled- See Also:
MMXMotor.setRamping(boolean)
-
getLimitAngle
public int getLimitAngle()
Return the angle that this Motor is rotating to or last rotated to.- Specified by:
getLimitAnglein interfaceRegulatedMotor- Returns:
- angle in degrees. 0 if no rotate method has been intiated.
-
close
public void close()
Description copied from interface:RegulatedMotorClose the port, the port can not be used after this call.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceRegulatedMotor
-
synchronizeWith
public void synchronizeWith(RegulatedMotor[] syncList)
Description copied from interface:RegulatedMotorSpecify a set of motors that should be kept in synchronization with this one. The synchronization mechanism simply ensures that operations between a startSynchronization call and an endSynchronization call will all be executed at the same time (when the endSynchronization method is called). This is all that is needed to ensure that motors will operate in a synchronized fashion. The start/end methods can also be used to ensure that reads of the motor state will also be consistent.- Specified by:
synchronizeWithin interfaceRegulatedMotor- Parameters:
syncList- an array of motors to synchronize with.
-
startSynchronization
public void startSynchronization()
Description copied from interface:RegulatedMotorBegin a set of synchronized motor operations- Specified by:
startSynchronizationin interfaceRegulatedMotor
-
endSynchronization
public void endSynchronization()
Description copied from interface:RegulatedMotorComplete a set of synchronized motor operations.- Specified by:
endSynchronizationin interfaceRegulatedMotor
-
-