Class 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
      void addListener​(RegulatedMotorListener listener)
      Adds a listener object that will be notified when rotation has started or stopped
      void close()
      Close the port, the port can not be used after this call.
      void endSynchronization()
      Complete a set of synchronized motor operations.
      void flt​(boolean immediateReturn)
      Set the motor into float mode.
      int getLimitAngle()
      Return the angle that this Motor is rotating to or last rotated to.
      float getMaxSpeed()
      Returns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.
      int getRotationSpeed()
      Return the current rotational speed calculated from the encoder position every 100 ms.
      int getSpeed()
      Return the current target speed.
      boolean isStalled()
      returns true if motor is stalled
      RegulatedMotorListener removeListener()
      Removes the RegulatedMotorListener from this class.
      void rotate​(int angle)
      Rotate by the requested number of degrees while blocking until completion.
      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.
      void rotateTo​(int limitAngle)
      Rotate to the target angle while blocking until completion.
      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.
      void setAcceleration​(int acceleration)
      Sets speed ramping is enabled/disabled for this motor.
      void setSpeed​(int speed)
      Sets desired motor speed, in degrees per second.
      void setStallThreshold​(int error, int time)
      NOT IMPLEMENTED as the NXTMMX motor controller does not support this command.
      void startSynchronization()
      Begin a set of synchronized motor operations
      void stop​(boolean immediateReturn)
      Causes motor to stop, pretty much instantaneously.
      void synchronizeWith​(RegulatedMotor[] syncList)
      Specify a set of motors that should be kept in synchronization with this one.
      void waitComplete()
      Wait until the current movement operation is complete (this can include the motor stalling).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 in setSpeed.
        Specified by:
        getRotationSpeed in interface Tachometer
        Returns:
        The current rotational speed in deg/sec
      • stop

        public void stop​(boolean immediateReturn)
        Description copied from interface: RegulatedMotor
        Causes 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:
        stop in interface RegulatedMotor
        Parameters:
        immediateReturn - if true do not wait for the motor to actually stop
      • flt

        public void flt​(boolean immediateReturn)
        Description copied from interface: RegulatedMotor
        Set the motor into float mode. This will stop the motor without braking and the position of the motor will not be maintained.
        Specified by:
        flt in interface RegulatedMotor
        Parameters:
        immediateReturn - If true do not wait for the motor to actually stop
      • waitComplete

        public void waitComplete()
        Description copied from interface: RegulatedMotor
        Wait until the current movement operation is complete (this can include the motor stalling).
        Specified by:
        waitComplete in interface RegulatedMotor
      • rotate

        public void rotate​(int angle)
        Rotate by the requested number of degrees while blocking until completion.
        Specified by:
        rotate in interface RegulatedMotor
        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:
        rotateTo in interface RegulatedMotor
        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:
        rotate in interface RegulatedMotor
        Parameters:
        degrees - number of degrees to rotate relative to the current position.
        immediateReturn - if true, do not wait for the move to complete. false will 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:
        rotateTo in interface RegulatedMotor
        Parameters:
        limitAngle - Angle [in degrees] to rotate to.
        immediateReturn - if true, do not wait for the move to complete. false will 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:
        setSpeed in interface RegulatedMotor
        Parameters:
        speed - Motor speed in degrees per second
        See Also:
        getSpeed(), MMXMotor.setPower(int)
      • getMaxSpeed

        public float getMaxSpeed()
        Description copied from interface: RegulatedMotor
        Returns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.
        Specified by:
        getMaxSpeed in interface RegulatedMotor
        Returns:
        the maximum speed of the Motor in degrees per second.
      • isStalled

        public boolean isStalled()
        Description copied from interface: RegulatedMotor
        returns true if motor is stalled
        Specified by:
        isStalled in interface RegulatedMotor
        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:
        setStallThreshold in interface RegulatedMotor
        Parameters:
        error - The error threshold
        time - 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. The 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.

        Specified by:
        setAcceleration in interface RegulatedMotor
        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:
        getLimitAngle in interface RegulatedMotor
        Returns:
        angle in degrees. 0 if no rotate method has been intiated.
      • close

        public void close()
        Description copied from interface: RegulatedMotor
        Close the port, the port can not be used after this call.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface RegulatedMotor
      • synchronizeWith

        public void synchronizeWith​(RegulatedMotor[] syncList)
        Description copied from interface: RegulatedMotor
        Specify 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:
        synchronizeWith in interface RegulatedMotor
        Parameters:
        syncList - an array of motors to synchronize with.