com.qualcomm.robotcore.hardware

## Class DcMotorImplEx

- java.lang.Object
- - com.qualcomm.robotcore.hardware.DcMotorImpl
  - - com.qualcomm.robotcore.hardware.DcMotorImplEx

- All Implemented Interfaces:
    DcMotor, DcMotorEx, DcMotorSimple, HardwareDevice

      public class DcMotorImplEx
      extends DcMotorImpl
      implements DcMotorEx

  `DcMotorImplEx` is a motor that supports the `DcMotorEx` interface in addition to simply `DcMotor`.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.DcMotor

      `DcMotor.RunMode, DcMotor.ZeroPowerBehavior`

    - ### Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.DcMotorSimple

      `DcMotorSimple.Direction`

    - ### Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice

      `HardwareDevice.Manufacturer`

  - ### Field Summary

    - ### Fields inherited from class com.qualcomm.robotcore.hardware.DcMotorImpl

      `controller, direction, motorType, portNumber`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DcMotorImplEx(DcMotorController controller, int portNumber)`
    `DcMotorImplEx(DcMotorController controller, int portNumber, DcMotorSimple.Direction direction)`
    `DcMotorImplEx(DcMotorController controller, int portNumber, DcMotorSimple.Direction direction, MotorConfigurationType motorType)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected double` | `adjustAngularRate(double angularRate)`
    `PIDCoefficients` | `getPIDCoefficients(DcMotor.RunMode mode)` Returns the PID control coefficients used when running in the indicated mode on this motor.
    `PIDFCoefficients` | `getPIDFCoefficients(DcMotor.RunMode mode)` Returns the PIDF control coefficients used when running in the indicated mode on this motor.
    `int` | `getTargetPositionTolerance()` Returns the current target positioning tolerance of this motor
    `double` | `getVelocity()` Returns the current velocity of the motor, in ticks per second
    `double` | `getVelocity(AngleUnit unit)` Returns the current velocity of the motor, in angular units per second
    `protected void` | `internalSetTargetPosition(int position)`
    `boolean` | `isMotorEnabled()` Returns whether this motor is energized
    `void` | `setMotorDisable()` Individually de-energizes this particular motor
    `void` | `setMotorEnable()` Individually energizes this particular motor
    `void` | `setPIDCoefficients(DcMotor.RunMode mode, PIDCoefficients pidCoefficients)` Sets the PID control coefficients for one of the PID modes of this motor.
    `void` | `setPIDFCoefficients(DcMotor.RunMode mode, PIDFCoefficients pidfCoefficients)` `DcMotorEx.setPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode, com.qualcomm.robotcore.hardware.PIDFCoefficients)` is a superset enhancement to `DcMotorEx.setPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode, com.qualcomm.robotcore.hardware.PIDCoefficients)`.
    `void` | `setPositionPIDFCoefficients(double p)` A shorthand for setting the PIDF coefficients for the `DcMotor.RunMode.RUN_TO_POSITION` mode.
    `void` | `setTargetPositionTolerance(int tolerance)` Sets the target positioning tolerance of this motor
    `void` | `setVelocity(double angularRate)` Sets the velocity of the motor
    `void` | `setVelocity(double angularRate, AngleUnit unit)` Sets the velocity of the motor
    `void` | `setVelocityPIDFCoefficients(double p, double i, double d, double f)` A shorthand for setting the PIDF coefficients for the `DcMotor.RunMode.RUN_USING_ENCODER` mode.

    - ### Methods inherited from class com.qualcomm.robotcore.hardware.DcMotorImpl

      `adjustPosition, adjustPower, close, getConnectionInfo, getController, getCurrentPosition, getDeviceName, getDirection, getManufacturer, getMode, getMotorType, getOperationalDirection, getPortNumber, getPower, getPowerFloat, getTargetPosition, getVersion, getZeroPowerBehavior, internalSetMode, internalSetPower, isBusy, resetDeviceConfigurationForOpMode, setDirection, setMode, setMotorType, setPower, setPowerFloat, setTargetPosition, setZeroPowerBehavior`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.qualcomm.robotcore.hardware.DcMotor

      `getController, getCurrentPosition, getMode, getMotorType, getPortNumber, getPowerFloat, getTargetPosition, getZeroPowerBehavior, isBusy, setMode, setMotorType, setPowerFloat, setTargetPosition, setZeroPowerBehavior`

    - ### Methods inherited from interface com.qualcomm.robotcore.hardware.DcMotorSimple

      `getDirection, getPower, setDirection, setPower`

    - ### Methods inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice

      `close, getConnectionInfo, getDeviceName, getManufacturer, getVersion, resetDeviceConfigurationForOpMode`

- - ### Constructor Detail

    - #### DcMotorImplEx

          public DcMotorImplEx(DcMotorController controller,
                               int portNumber)

    - #### DcMotorImplEx

          public DcMotorImplEx(DcMotorController controller,
                               int portNumber,
                               DcMotorSimple.Direction direction)

    - #### DcMotorImplEx

          public DcMotorImplEx(DcMotorController controller,
                               int portNumber,
                               DcMotorSimple.Direction direction,
                               MotorConfigurationType motorType)

  - ### Method Detail

    - #### setMotorEnable

          public void setMotorEnable()

      Description copied from interface: `DcMotorEx`
      Individually energizes this particular motor
      Specified by:
        `setMotorEnable` in interface `DcMotorEx`
      See Also:
        `DcMotorEx.setMotorDisable()`, `DcMotorEx.isMotorEnabled()`

    - #### setMotorDisable

          public void setMotorDisable()

      Description copied from interface: `DcMotorEx`
      Individually de-energizes this particular motor
      Specified by:
        `setMotorDisable` in interface `DcMotorEx`
      See Also:
        `DcMotorEx.setMotorEnable()`, `DcMotorEx.isMotorEnabled()`

    - #### isMotorEnabled

          public boolean isMotorEnabled()

      Description copied from interface: `DcMotorEx`
      Returns whether this motor is energized
      Specified by:
        `isMotorEnabled` in interface `DcMotorEx`
      See Also:
        `DcMotorEx.setMotorEnable()`, `DcMotorEx.setMotorDisable()`

    - #### setVelocity

          public void setVelocity(double angularRate)

      Description copied from interface: `DcMotorEx`
      Sets the velocity of the motor
      Specified by:
        `setVelocity` in interface `DcMotorEx`
      Parameters:
        `angularRate` - the desired ticks per second

    - #### setVelocity

          public void setVelocity(double angularRate,
                                  AngleUnit unit)

      Description copied from interface: `DcMotorEx`
      Sets the velocity of the motor
      Specified by:
        `setVelocity` in interface `DcMotorEx`
      Parameters:
        `angularRate` - the desired angular rate, in units per second
        `unit` - the units in which angularRate is expressed
      See Also:
        `DcMotorEx.getVelocity(AngleUnit)`

    - #### getVelocity

          public double getVelocity()

      Description copied from interface: `DcMotorEx`
      Returns the current velocity of the motor, in ticks per second
      Specified by:
        `getVelocity` in interface `DcMotorEx`
      Returns:
        the current velocity of the motor

    - #### getVelocity

          public double getVelocity(AngleUnit unit)

      Description copied from interface: `DcMotorEx`
      Returns the current velocity of the motor, in angular units per second
      Specified by:
        `getVelocity` in interface `DcMotorEx`
      Parameters:
        `unit` - the units in which the angular rate is desired
      Returns:
        the current velocity of the motor
      See Also:
        `DcMotorEx.setVelocity(double, AngleUnit)`

    - #### adjustAngularRate

          protected double adjustAngularRate(double angularRate)

    - #### setPIDCoefficients

          public void setPIDCoefficients(DcMotor.RunMode mode,
                                         PIDCoefficients pidCoefficients)

      Description copied from interface: `DcMotorEx`
      Sets the PID control coefficients for one of the PID modes of this motor. Note that in some controller implementations, setting the PID coefficients for one mode on a motor might affect other modes on that motor, or might affect the PID coefficients used by other motors on the same controller (this is not true on the REV Expansion Hub).
      Specified by:
        `setPIDCoefficients` in interface `DcMotorEx`
      Parameters:
        `mode` - either `RunMode#RUN_USING_ENCODER` or `RunMode#RUN_TO_POSITION`
        `pidCoefficients` - the new coefficients to use when in that mode on this motor
      See Also:
        `#getPIDCoefficients(RunMode)`

    - #### setPIDFCoefficients

          public void setPIDFCoefficients(DcMotor.RunMode mode,
                                          PIDFCoefficients pidfCoefficients)

      Description copied from interface: `DcMotorEx`
      `DcMotorEx.setPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode, com.qualcomm.robotcore.hardware.PIDFCoefficients)` is a superset enhancement to `DcMotorEx.setPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode, com.qualcomm.robotcore.hardware.PIDCoefficients)`. In addition to the proportional, integral, and derivative coefficients previously supported, a feed-forward coefficient may also be specified. Further, a selection of motor control algorithms is offered: the originally-shipped Legacy PID algorithm, and a PIDF algorithm which avails itself of the feed-forward coefficient. Note that the feed-forward coefficient is not used by the Legacy PID algorithm; thus, the feed-forward coefficient must be indicated as zero if the Legacy PID algorithm is used. Also: the internal implementation of these algorithms may be different: it is not the case that the use of PIDF with the F term as zero necessarily exhibits exactly the same behavior as the use of the LegacyPID algorithm, though in practice they will be quite close. Readers are reminded that `DcMotor.RunMode.RUN_TO_POSITION` mode makes use of both the coefficients set for RUN_TO_POSITION and the coefficients set for RUN_WITH_ENCODER, due to the fact that internally the RUN_TO_POSITION logic calculates an on-the-fly velocity goal on each control cycle, then (logically) runs the RUN_WITH_ENCODER logic. Because of that double- layering, only the proportional ('p') coefficient makes logical sense for use in the RUN_TO_POSITION coefficients.
      Specified by:
        `setPIDFCoefficients` in interface `DcMotorEx`
      See Also:
        `DcMotorEx.setVelocityPIDFCoefficients(double, double, double, double)`, `DcMotorEx.setPositionPIDFCoefficients(double)`, `#getPIDFCoefficients(RunMode)`

    - #### setVelocityPIDFCoefficients

          public void setVelocityPIDFCoefficients(double p,
                                                  double i,
                                                  double d,
                                                  double f)

      Description copied from interface: `DcMotorEx`
      A shorthand for setting the PIDF coefficients for the `DcMotor.RunMode.RUN_USING_ENCODER` mode. `MotorControlAlgorithm.PIDF` is used.
      Specified by:
        `setVelocityPIDFCoefficients` in interface `DcMotorEx`
      See Also:
        `#setPIDFCoefficients(RunMode, PIDFCoefficients)`

    - #### setPositionPIDFCoefficients

          public void setPositionPIDFCoefficients(double p)

      Description copied from interface: `DcMotorEx`
      A shorthand for setting the PIDF coefficients for the `DcMotor.RunMode.RUN_TO_POSITION` mode. `MotorControlAlgorithm.PIDF` is used. Readers are reminded that `DcMotor.RunMode.RUN_TO_POSITION` mode makes use of both the coefficients set for RUN_TO_POSITION and the coefficients set for RUN_WITH_ENCODER, due to the fact that internally the RUN_TO_POSITION logic calculates an on-the-fly velocity goal on each control cycle, then (logically) runs the RUN_WITH_ENCODER logic. Because of that double- layering, only the proportional ('p') coefficient makes logical sense for use in the RUN_TO_POSITION coefficients.
      Specified by:
        `setPositionPIDFCoefficients` in interface `DcMotorEx`
      See Also:
        `DcMotorEx.setVelocityPIDFCoefficients(double, double, double, double)`, `#setPIDFCoefficients(RunMode, PIDFCoefficients)`

    - #### getPIDCoefficients

          public PIDCoefficients getPIDCoefficients(DcMotor.RunMode mode)

      Description copied from interface: `DcMotorEx`
      Returns the PID control coefficients used when running in the indicated mode on this motor.
      Specified by:
        `getPIDCoefficients` in interface `DcMotorEx`
      Parameters:
        `mode` - either `RunMode#RUN_USING_ENCODER` or `RunMode#RUN_TO_POSITION`
      Returns:
        the PID control coefficients used when running in the indicated mode on this motor

    - #### getPIDFCoefficients

          public PIDFCoefficients getPIDFCoefficients(DcMotor.RunMode mode)

      Description copied from interface: `DcMotorEx`
      Returns the PIDF control coefficients used when running in the indicated mode on this motor.
      Specified by:
        `getPIDFCoefficients` in interface `DcMotorEx`
      Parameters:
        `mode` - either `RunMode#RUN_USING_ENCODER` or `RunMode#RUN_TO_POSITION`
      Returns:
        the PIDF control coefficients used when running in the indicated mode on this motor
      See Also:
        `#setPIDFCoefficients(RunMode, PIDFCoefficients)`

    - #### getTargetPositionTolerance

          public int getTargetPositionTolerance()

      Description copied from interface: `DcMotorEx`
      Returns the current target positioning tolerance of this motor
      Specified by:
        `getTargetPositionTolerance` in interface `DcMotorEx`
      Returns:
        the current target positioning tolerance of this motor

    - #### setTargetPositionTolerance

          public void setTargetPositionTolerance(int tolerance)

      Description copied from interface: `DcMotorEx`
      Sets the target positioning tolerance of this motor
      Specified by:
        `setTargetPositionTolerance` in interface `DcMotorEx`
      Parameters:
        `tolerance` - the desired tolerance, in encoder ticks
      See Also:
        `DcMotor.setTargetPosition(int)`

    - #### internalSetTargetPosition

          protected void internalSetTargetPosition(int position)

      Overrides:
        `internalSetTargetPosition` in class `DcMotorImpl`