com.qualcomm.robotcore.hardware

## Interface DcMotor

- All Superinterfaces:
    DcMotorSimple, HardwareDevice
  All Known Subinterfaces:
    DcMotorEx
  All Known Implementing Classes:
    DcMotorImpl, DcMotorImplEx

      public interface DcMotor
      extends DcMotorSimple

  DcMotor interface provides access to full-featured motor functionality.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `DcMotor.RunMode` The run mode of a motor `DcMotor.RunMode` controls how the motor interprets the it's parameter settings passed through power- and encoder-related methods.
    `static class` | `DcMotor.ZeroPowerBehavior` ZeroPowerBehavior provides an indication as to a motor's behavior when a power level of zero is applied.

    - ### 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`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `DcMotorController` | `getController()` Returns the underlying motor controller on which this motor is situated.
    `int` | `getCurrentPosition()` Returns the current reading of the encoder for this motor.
    `DcMotor.RunMode` | `getMode()` Returns the current run mode for this motor
    `MotorConfigurationType` | `getMotorType()` Returns the assigned type for this motor.
    `int` | `getPortNumber()` Returns the port number on the underlying motor controller on which this motor is situated.
    `boolean` | `getPowerFloat()` Returns whether the motor is currently in a float power level.
    `int` | `getTargetPosition()` Returns the current target encoder position for this motor.
    `DcMotor.ZeroPowerBehavior` | `getZeroPowerBehavior()` Returns the current behavior of the motor were a power level of zero to be applied.
    `boolean` | `isBusy()` Returns true if the motor is currently advancing or retreating to a target position.
    `void` | `setMode(DcMotor.RunMode mode)` Sets the current run mode for this motor
    `void` | `setMotorType(MotorConfigurationType motorType)` Sets the assigned type of this motor.
    `void` | `setPowerFloat()` Deprecated. This method is deprecated in favor of direct use of `setZeroPowerBehavior()` and `setPower()`.
    `void` | `setTargetPosition(int position)` Sets the desired encoder target position to which the motor should advance or retreat and then actively hold thereat.
    `void` | `setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)` Sets the behavior of the motor when a power level of zero is applied.

    - ### 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`

- - ### Method Detail

    - #### getMotorType

          MotorConfigurationType getMotorType()

      Returns the assigned type for this motor. If no particular motor type has been configured, then `MotorConfigurationType#getUnspecifiedMotorType()` will be returned. Note that the motor type for a given motor is initially assigned in the robot configuration user interface, though it may subsequently be modified using methods herein.
      Returns:
        the assigned type for this motor

    - #### setMotorType

          void setMotorType(MotorConfigurationType motorType)

      Sets the assigned type of this motor. Usage of this method is very rare.
      Parameters:
        `motorType` - the new assigned type for this motor
      See Also:
        `getMotorType()`

    - #### getController

          DcMotorController getController()

      Returns the underlying motor controller on which this motor is situated.
      Returns:
        the underlying motor controller on which this motor is situated.
      See Also:
        `getPortNumber()`

    - #### getPortNumber

          int getPortNumber()

      Returns the port number on the underlying motor controller on which this motor is situated.
      Returns:
        the port number on the underlying motor controller on which this motor is situated.
      See Also:
        `getController()`

    - #### setZeroPowerBehavior

          void setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)

      Sets the behavior of the motor when a power level of zero is applied.
      Parameters:
        `zeroPowerBehavior` - the new behavior of the motor when a power level of zero is applied.
      See Also:
        `DcMotor.ZeroPowerBehavior`, `DcMotorSimple.setPower(double)`

    - #### getZeroPowerBehavior

          DcMotor.ZeroPowerBehavior getZeroPowerBehavior()

      Returns the current behavior of the motor were a power level of zero to be applied.
      Returns:
        the current behavior of the motor were a power level of zero to be applied.

    - #### setPowerFloat

          @Deprecated
          void setPowerFloat()

      Deprecated. This method is deprecated in favor of direct use of `setZeroPowerBehavior()` and `setPower()`.
      Sets the zero power behavior of the motor to `FLOAT`, then applies zero power to that motor.

      Note that the change of the zero power behavior to `FLOAT` remains in effect even following the return of this method. This is a breaking change in behavior from previous releases of the SDK. Consider, for example, the following code sequence:

               motor.setZeroPowerBehavior(ZeroPowerBehavior.BRAKE); // method not available in previous releases
               motor.setPowerFloat();
               motor.setPower(0.0);

      Starting from this release, this sequence of code will leave the motor floating. Previously, the motor would have been left braked.

      See Also:
        `DcMotorSimple.setPower(double)`, `getPowerFloat()`, `setZeroPowerBehavior(ZeroPowerBehavior)`

    - #### getPowerFloat

          boolean getPowerFloat()

      Returns whether the motor is currently in a float power level.
      Returns:
        whether the motor is currently in a float power level.
      See Also:
        `setPowerFloat()`

    - #### setTargetPosition

          void setTargetPosition(int position)

      Sets the desired encoder target position to which the motor should advance or retreat and then actively hold thereat. This behavior is similar to the operation of a servo. The maximum speed at which this advance or retreat occurs is governed by the power level currently set on the motor. While the motor is advancing or retreating to the desired taget position, `isBusy()` will return true.

      Note that adjustment to a target position is only effective when the motor is in `RUN_TO_POSITION` RunMode. Note further that, clearly, the motor must be equipped with an encoder in order for this mode to function properly.

      Parameters:
        `position` - the desired encoder target position
      See Also:
        `getCurrentPosition()`, `setMode(RunMode)`, `DcMotor.RunMode.RUN_TO_POSITION`, `getTargetPosition()`, `isBusy()`

    - #### getTargetPosition

          int getTargetPosition()

      Returns the current target encoder position for this motor.
      Returns:
        the current target encoder position for this motor.
      See Also:
        `setTargetPosition(int)`

    - #### isBusy

          boolean isBusy()

      Returns true if the motor is currently advancing or retreating to a target position.
      Returns:
        true if the motor is currently advancing or retreating to a target position.
      See Also:
        `setTargetPosition(int)`

    - #### getCurrentPosition

          int getCurrentPosition()

      Returns the current reading of the encoder for this motor. The units for this reading, that is, the number of ticks per revolution, are specific to the motor/encoder in question, and thus are not specified here.
      Returns:
        the current reading of the encoder for this motor
      See Also:
        `getTargetPosition()`, `DcMotor.RunMode.STOP_AND_RESET_ENCODER`

    - #### setMode

          void setMode(DcMotor.RunMode mode)

      Sets the current run mode for this motor
      Parameters:
        `mode` - the new current run mode for this motor
      See Also:
        `DcMotor.RunMode`, `getMode()`

    - #### getMode

          DcMotor.RunMode getMode()

      Returns the current run mode for this motor
      Returns:
        the current run mode for this motor
      See Also:
        `DcMotor.RunMode`, `setMode(RunMode)`