Class MotorDevice

java.lang.Object
com.cdarobotics.cdalib.devices.Device
com.cdarobotics.cdalib.devices.actuators.MotorDevice
Direct Known Subclasses:
PositionMotorDevice, VelocityMotorDevice

public class MotorDevice extends Device
A Device wrapping a DcMotorEx. Power commands are cached and only written to hardware in update(), and only when the value has changed — this collapses redundant bus writes so setting the same power every loop costs nothing.

Configuration and read setters return this for fluent chaining.

  • Constructor Details

    • MotorDevice

      public MotorDevice(com.qualcomm.robotcore.hardware.DcMotorEx motor)
      Wraps an already-resolved motor.
    • MotorDevice

      public MotorDevice(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Resolves the motor from the hardware map by configured name.
  • Method Details

    • setPower

      public MotorDevice setPower(double power)
      Sets the power to command on the next update(). Range [-1.0, 1.0].
    • setPowerWriteThreshold

      public MotorDevice setPowerWriteThreshold(double threshold)
      Sets the minimum power change (relative to the value last written to hardware) that triggers an actual write in update(). Larger values collapse more redundant Lynx writes — cutting loop time when the command is steady — at the cost of coarser resolution. Set to 0 for exact writes (every change flushed). Defaults to 0.005.
    • getCurrentPower

      public double getCurrentPower()
      Returns:
      the last commanded power (not necessarily yet flushed to hardware).
    • getCurrentPosition

      public int getCurrentPosition()
      Returns:
      the encoder position, in ticks.
    • getCurrentVelocity

      public double getCurrentVelocity()
      Returns:
      the current velocity, in ticks per second.
    • getCurrent

      public double getCurrent(org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit)
      Returns:
      the motor current draw in the given unit.
    • setDirection

      public MotorDevice setDirection(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction)
      Sets the motor's rotation direction.
    • setZeroPowerBehavior

      public MotorDevice setZeroPowerBehavior(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior behavior)
      Sets what the motor does at zero power — BRAKE or FLOAT.
    • setMode

      public MotorDevice setMode(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode)
      Sets the run mode (e.g. RUN_USING_ENCODER, RUN_TO_POSITION).
    • getMotor

      public com.qualcomm.robotcore.hardware.DcMotorEx getMotor()
      Returns:
      the wrapped SDK motor, for operations not exposed here.
    • update

      public void update()
      Description copied from class: Device
      Flush pending writes to, or refresh cached reads from, the underlying hardware.
      Specified by:
      update in class Device