Package lejos.hardware.device.tetrix
Class TetrixRegulatedMotor
- java.lang.Object
-
- lejos.hardware.device.tetrix.TetrixMotor
-
- lejos.hardware.device.tetrix.TetrixEncoderMotor
-
- lejos.hardware.device.tetrix.TetrixRegulatedMotor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,BaseMotor,DCMotor,Encoder,RegulatedMotor,Tachometer
public class TetrixRegulatedMotor extends TetrixEncoderMotor implements RegulatedMotor
Tetrix DC motor abstraction with encoder support that implementsRegulatedMotor. The Tetrix motor must have an encoder installed and connected to the controller for the methods in this class to work. If an encoder is not installed, use theclass instead.TetrixMotorUse
to retrieve aTetrixMotorController.getRegulatedMotor(int)TetrixRegulatedMotorinstance.- Author:
- Kirk P. Thompson
-
-
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.floatgetMaxSpeed()NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.intgetRotationSpeed()Return the current rotational speed calculated from the encoder position every 100 ms.intgetSpeed()Return the speed value calculated from the actual power value as:booleanisStalled()NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.RegulatedMotorListenerremoveListener()Removes the RegulatedMotorListener from this class.voidrotate(int angle)Rotate by the requested number of degrees while blocking until completion.voidrotateTo(int limitAngle)Rotate to the target angle while blocking until completion.voidsetAcceleration(int acceleration)NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.voidsetRegulate(boolean regulate)OVERRIDDEN TO NOT ALLOW CHANGE OF REGULATED STATE as theTetrixRegulatedMotorclass must use regulation.voidsetSpeed(int speed)Sets desired motor speed, in degrees per second.voidsetStallThreshold(int error, int time)NOT IMPLEMENTED as the TEXTRIX 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.tetrix.TetrixEncoderMotor
getLimitAngle, getTachoCount, resetTachoCount, rotate, rotateTo
-
Methods inherited from class lejos.hardware.device.tetrix.TetrixMotor
backward, flt, forward, getPower, isMoving, setPower, setReverse, 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
-
Methods inherited from interface lejos.robotics.RegulatedMotor
getLimitAngle, rotate, rotateTo
-
-
-
-
Method Detail
-
setRegulate
public void setRegulate(boolean regulate)
OVERRIDDEN TO NOT ALLOW CHANGE OF REGULATED STATE as theTetrixRegulatedMotorclass must use regulation. Motors are always in regulated mode when using theTetrixRegulatedMotorclass.- Overrides:
setRegulatein classTetrixEncoderMotor- Parameters:
regulate- Ignored
-
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.
-
setSpeed
public void setSpeed(int speed)
Sets desired motor speed, in degrees per second. Since the TETRIX Motor Controller only has power adjustment, the power value is derived from the passedspeedvalue as:
power = Math.round((speed - 0.5553f) * 0.102247398f);
and as such, the actual speed value will not be exact.The maximum reliably sustainable velocity for the TETRIX DC Gear motor P/N 739023 (which was used as the test case for creating this class) is 154 RPM => 924 degs/sec.
- Specified by:
setSpeedin interfaceRegulatedMotor- Parameters:
speed- value in degrees/sec- See Also:
getSpeed()
-
getSpeed
public int getSpeed()
Return the speed value calculated from the actual power value as:
speed = Math.round(9.7802f * super.getPower() + 0.5553f);
and as such, the actual speed value may not be what was set withsetSpeed.- Specified by:
getSpeedin interfaceRegulatedMotor- Returns:
- The speed value (converted from power value) in degrees/sec
- See Also:
setSpeed(int)
-
getMaxSpeed
public float getMaxSpeed()
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.- Specified by:
getMaxSpeedin interfaceRegulatedMotor- Returns:
- Always 924 degrees/sec
-
isStalled
public boolean isStalled()
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.- Specified by:
isStalledin interfaceRegulatedMotor- Returns:
- Always
false
-
setStallThreshold
public void setStallThreshold(int error, int time)NOT IMPLEMENTED as the TEXTRIX 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)
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.- Specified by:
setAccelerationin interfaceRegulatedMotor- Parameters:
acceleration- Ignored
-
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
-
-