com.qualcomm.robotcore.hardware

## Class DcMotorImpl

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

- All Implemented Interfaces:
    DcMotor, DcMotorSimple, HardwareDevice
  Direct Known Subclasses:
    DcMotorImplEx

      public class DcMotorImpl
      extends java.lang.Object
      implements DcMotor

  Control a DC Motor attached to a DC Motor Controller
  See Also:
    `DcMotorController`

- - ### 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
    Modifier and Type | Field and Description
    --- | ---
    `protected DcMotorController` | `controller`
    `protected DcMotorSimple.Direction` | `direction`
    `protected MotorConfigurationType` | `motorType`
    `protected int` | `portNumber`

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `adjustPosition(int position)`
    `protected double` | `adjustPower(double power)`
    `void` | `close()` Closes this device
    `java.lang.String` | `getConnectionInfo()` Get connection information about this device in a human readable format
    `DcMotorController` | `getController()` Get DC motor controller
    `int` | `getCurrentPosition()` Get the current encoder value, accommodating the configured directionality of the motor.
    `java.lang.String` | `getDeviceName()` Returns a string suitable for display to the user as to the type of device.
    `DcMotorSimple.Direction` | `getDirection()` Get the direction
    `HardwareDevice.Manufacturer` | `getManufacturer()` Returns an indication of the manufacturer of this device.
    `DcMotor.RunMode` | `getMode()` Get the current mode
    `MotorConfigurationType` | `getMotorType()` Returns the assigned type for this motor.
    `protected DcMotorSimple.Direction` | `getOperationalDirection()`
    `int` | `getPortNumber()` Get port number
    `double` | `getPower()` Get the current motor power
    `boolean` | `getPowerFloat()` Is motor power set to float?
    `int` | `getTargetPosition()` Get the current motor target position.
    `int` | `getVersion()` Version
    `DcMotor.ZeroPowerBehavior` | `getZeroPowerBehavior()` Returns the current behavior of the motor were a power level of zero to be applied.
    `protected void` | `internalSetMode(DcMotor.RunMode mode)`
    `protected void` | `internalSetPower(double power)`
    `protected void` | `internalSetTargetPosition(int position)`
    `boolean` | `isBusy()` Is the motor busy?
    `void` | `resetDeviceConfigurationForOpMode()` Resets the device's configuration to that which is expected at the beginning of an OpMode.
    `void` | `setDirection(DcMotorSimple.Direction direction)` Set the direction
    `void` | `setMode(DcMotor.RunMode mode)` Set the current mode
    `void` | `setMotorType(MotorConfigurationType motorType)` Sets the assigned type of this motor.
    `void` | `setPower(double power)` Set the current motor power
    `void` | `setPowerFloat()` Deprecated.
    `void` | `setTargetPosition(int position)` Set the motor target position, using an integer.
    `void` | `setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)` Sets the behavior of the motor when a power level of zero is applied.

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

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

- - ### Field Detail

    - #### controller

          protected DcMotorController controller

    - #### portNumber

          protected int portNumber

    - #### direction

          protected DcMotorSimple.Direction direction

    - #### motorType

          protected MotorConfigurationType motorType

  - ### Constructor Detail

    - #### DcMotorImpl

          public DcMotorImpl(DcMotorController controller,
                             int portNumber)

      Constructor
      Parameters:
        `controller` - DC motor controller this motor is attached to
        `portNumber` - portNumber position on the controller

    - #### DcMotorImpl

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

      Constructor
      Parameters:
        `controller` - DC motor controller this motor is attached to
        `portNumber` - portNumber port number on the controller
        `direction` - direction this motor should spin

    - #### DcMotorImpl

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

      Constructor
      Parameters:
        `controller` - DC motor controller this motor is attached to
        `portNumber` - portNumber port number on the controller
        `direction` - direction this motor should spin
        `motorType` - the type we know this motor to be

  - ### Method Detail

    - #### getManufacturer

          public HardwareDevice.Manufacturer getManufacturer()

      Description copied from interface: `HardwareDevice`
      Returns an indication of the manufacturer of this device.
      Specified by:
        `getManufacturer` in interface `HardwareDevice`
      Returns:
        the device's manufacturer

    - #### getDeviceName

          public java.lang.String getDeviceName()

      Description copied from interface: `HardwareDevice`
      Returns a string suitable for display to the user as to the type of device. Note that this is a device-type-specific name; it has nothing to do with the name by which a user might have configured the device in a robot configuration.
      Specified by:
        `getDeviceName` in interface `HardwareDevice`
      Returns:
        device manufacturer and name

    - #### getConnectionInfo

          public java.lang.String getConnectionInfo()

      Description copied from interface: `HardwareDevice`
      Get connection information about this device in a human readable format
      Specified by:
        `getConnectionInfo` in interface `HardwareDevice`
      Returns:
        connection info

    - #### getVersion

          public int getVersion()

      Description copied from interface: `HardwareDevice`
      Version
      Specified by:
        `getVersion` in interface `HardwareDevice`
      Returns:
        get the version of this device

    - #### resetDeviceConfigurationForOpMode

          public void resetDeviceConfigurationForOpMode()

      Description copied from interface: `HardwareDevice`
      Resets the device's configuration to that which is expected at the beginning of an OpMode. For example, motors will reset the their direction to 'forward'.
      Specified by:
        `resetDeviceConfigurationForOpMode` in interface `HardwareDevice`

    - #### close

          public void close()

      Description copied from interface: `HardwareDevice`
      Closes this device
      Specified by:
        `close` in interface `HardwareDevice`

    - #### getMotorType

          public MotorConfigurationType getMotorType()

      Description copied from interface: `DcMotor`
      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.
      Specified by:
        `getMotorType` in interface `DcMotor`
      Returns:
        the assigned type for this motor

    - #### setMotorType

          public void setMotorType(MotorConfigurationType motorType)

      Description copied from interface: `DcMotor`
      Sets the assigned type of this motor. Usage of this method is very rare.
      Specified by:
        `setMotorType` in interface `DcMotor`
      Parameters:
        `motorType` - the new assigned type for this motor
      See Also:
        `DcMotor.getMotorType()`

    - #### getController

          public DcMotorController getController()

      Get DC motor controller
      Specified by:
        `getController` in interface `DcMotor`
      Returns:
        controller
      See Also:
        `DcMotor.getPortNumber()`

    - #### setDirection

          public void setDirection(DcMotorSimple.Direction direction)

      Set the direction
      Specified by:
        `setDirection` in interface `DcMotorSimple`
      Parameters:
        `direction` - direction
      See Also:
        `DcMotorSimple.getDirection()`

    - #### getDirection

          public DcMotorSimple.Direction getDirection()

      Get the direction
      Specified by:
        `getDirection` in interface `DcMotorSimple`
      Returns:
        direction
      See Also:
        `DcMotorSimple.setDirection(Direction)`

    - #### getPortNumber

          public int getPortNumber()

      Get port number
      Specified by:
        `getPortNumber` in interface `DcMotor`
      Returns:
        portNumber
      See Also:
        `DcMotor.getController()`

    - #### setPower

          public void setPower(double power)

      Set the current motor power
      Specified by:
        `setPower` in interface `DcMotorSimple`
      Parameters:
        `power` - from -1.0 to 1.0
      See Also:
        `DcMotorSimple.getPower()`, `DcMotor.setMode(DcMotor.RunMode)`, `DcMotor.setPowerFloat()`

    - #### internalSetPower

          protected void internalSetPower(double power)

    - #### getPower

          public double getPower()

      Get the current motor power
      Specified by:
        `getPower` in interface `DcMotorSimple`
      Returns:
        scaled from -1.0 to 1.0
      See Also:
        `DcMotorSimple.setPower(double)`

    - #### isBusy

          public boolean isBusy()

      Is the motor busy?
      Specified by:
        `isBusy` in interface `DcMotor`
      Returns:
        true if the motor is busy
      See Also:
        `DcMotor.setTargetPosition(int)`

    - #### setZeroPowerBehavior

          public void setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)

      Description copied from interface: `DcMotor`
      Sets the behavior of the motor when a power level of zero is applied.
      Specified by:
        `setZeroPowerBehavior` in interface `DcMotor`
      Parameters:
        `zeroPowerBehavior` - the new behavior of the motor when a power level of zero is applied.
      See Also:
        `DcMotor.ZeroPowerBehavior`, `DcMotorSimple.setPower(double)`

    - #### getZeroPowerBehavior

          public DcMotor.ZeroPowerBehavior getZeroPowerBehavior()

      Description copied from interface: `DcMotor`
      Returns the current behavior of the motor were a power level of zero to be applied.
      Specified by:
        `getZeroPowerBehavior` in interface `DcMotor`
      Returns:
        the current behavior of the motor were a power level of zero to be applied.

    - #### setPowerFloat

          @Deprecated
          public void setPowerFloat()

      Deprecated.
      Allow motor to float
      Specified by:
        `setPowerFloat` in interface `DcMotor`
      See Also:
        `DcMotorSimple.setPower(double)`, `DcMotor.getPowerFloat()`, `DcMotor.setZeroPowerBehavior(ZeroPowerBehavior)`

    - #### getPowerFloat

          public boolean getPowerFloat()

      Is motor power set to float?
      Specified by:
        `getPowerFloat` in interface `DcMotor`
      Returns:
        true of motor is set to float
      See Also:
        `DcMotor.setPowerFloat()`

    - #### setTargetPosition

          public void setTargetPosition(int position)

      Set the motor target position, using an integer. If this motor has been set to REVERSE, the passed-in "position" value will be multiplied by -1.
      Specified by:
        `setTargetPosition` in interface `DcMotor`
      Parameters:
        `position` - range from Integer.MIN_VALUE to Integer.MAX_VALUE
      See Also:
        `DcMotor.getCurrentPosition()`, `DcMotor.setMode(RunMode)`, `DcMotor.RunMode.RUN_TO_POSITION`, `DcMotor.getTargetPosition()`, `DcMotor.isBusy()`

    - #### internalSetTargetPosition

          protected void internalSetTargetPosition(int position)

    - #### getTargetPosition

          public int getTargetPosition()

      Get the current motor target position. If this motor has been set to REVERSE, the returned "position" will be multiplied by -1.
      Specified by:
        `getTargetPosition` in interface `DcMotor`
      Returns:
        integer, unscaled
      See Also:
        `DcMotor.setTargetPosition(int)`

    - #### getCurrentPosition

          public int getCurrentPosition()

      Get the current encoder value, accommodating the configured directionality of the motor.
      Specified by:
        `getCurrentPosition` in interface `DcMotor`
      Returns:
        double indicating current position
      See Also:
        `DcMotor.getTargetPosition()`, `DcMotor.RunMode.STOP_AND_RESET_ENCODER`

    - #### adjustPosition

          protected int adjustPosition(int position)

    - #### adjustPower

          protected double adjustPower(double power)

    - #### getOperationalDirection

          protected DcMotorSimple.Direction getOperationalDirection()

    - #### setMode

          public void setMode(DcMotor.RunMode mode)

      Set the current mode
      Specified by:
        `setMode` in interface `DcMotor`
      Parameters:
        `mode` - run mode
      See Also:
        `DcMotor.RunMode`, `DcMotor.getMode()`

    - #### internalSetMode

          protected void internalSetMode(DcMotor.RunMode mode)

    - #### getMode

          public DcMotor.RunMode getMode()

      Get the current mode
      Specified by:
        `getMode` in interface `DcMotor`
      Returns:
        run mode
      See Also:
        `DcMotor.RunMode`, `DcMotor.setMode(RunMode)`