Class CompositeMotor

java.lang.Object
frc.robot.devices.motor.CompositeMotor
All Implemented Interfaces:
Motor, MotorIO

public final class CompositeMotor extends Object implements Motor
Motor adapter that forwards commands to multiple physical motors while presenting a single Motor interface.

Use this when two or more motors are mechanically coupled on the same mechanism (e.g., dual-motor shooter flywheels). One motor is designated the primary; its encoder feedback is used for position, velocity, and telemetry reporting. All other motors are followers that receive identical voltage and speed commands but can have independent configurations (inversion, current limits, gear ratio) defined in their own motor config.

This class lives in devices/motor/ so any subsystem that needs paired motors can reuse it. Because the adapter implements Motor, the subsystem hierarchy (AbstractMotorSubsystem, AbstractVelocitySubsystem) remains completely unaware of multi-motor wiring.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface frc.robot.devices.motor.MotorIO

    MotorIO.MotorIOInputs
  • Constructor Summary

    Constructors
    Constructor
    Description
    CompositeMotor(Motor primary, Motor... followers)
    Creates a composite motor from a primary motor and one or more followers.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the primary motor's measured position in radians.
    double
    Returns the primary motor's measured velocity in radians per second.
    edu.wpi.first.units.measure.Voltage
    Returns the voltage applied to the primary motor.
    void
    setEncoderPosition(double positionRadians)
    Overwrites the encoder position on the primary motor and all followers.
    void
    setVoltage(edu.wpi.first.units.measure.Voltage voltage)
    Sends a voltage command to the primary motor and all followers.
    void
    Stops the primary motor and all followers immediately.
    void
    Updates telemetry inputs from the primary motor's encoder and sensors.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CompositeMotor

      public CompositeMotor(Motor primary, Motor... followers)
      Creates a composite motor from a primary motor and one or more followers.

      Each motor instance should already be fully configured (CAN ID, inversion, current limits, etc.) before being passed here. The composite does not alter any motor configuration; it only forwards commands.

      Parameters:
      primary - motor whose encoder is authoritative for position and velocity readings
      followers - additional motors that mirror the primary's voltage and speed commands
  • Method Details

    • setVoltage

      public void setVoltage(edu.wpi.first.units.measure.Voltage voltage)
      Sends a voltage command to the primary motor and all followers.
      Specified by:
      setVoltage in interface Motor
      Parameters:
      voltage - desired output voltage
    • getPositionRadians

      public double getPositionRadians()
      Returns the primary motor's measured position in radians.
      Specified by:
      getPositionRadians in interface Motor
      Returns:
      mechanism position from the primary encoder
    • getVelocityRadiansPerSecond

      public double getVelocityRadiansPerSecond()
      Returns the primary motor's measured velocity in radians per second.
      Specified by:
      getVelocityRadiansPerSecond in interface Motor
      Returns:
      mechanism velocity from the primary encoder
    • setEncoderPosition

      public void setEncoderPosition(double positionRadians)
      Overwrites the encoder position on the primary motor and all followers.
      Specified by:
      setEncoderPosition in interface Motor
      Parameters:
      positionRadians - new encoder position in mechanism radians
    • getVoltage

      public edu.wpi.first.units.measure.Voltage getVoltage()
      Returns the voltage applied to the primary motor.
      Specified by:
      getVoltage in interface Motor
      Returns:
      primary motor's applied voltage
    • stop

      public void stop()
      Stops the primary motor and all followers immediately.
      Specified by:
      stop in interface Motor
    • updateInputs

      public void updateInputs(MotorIO.MotorIOInputs inputs)
      Updates telemetry inputs from the primary motor's encoder and sensors.

      Only the primary motor's readings are captured because both motors are mechanically coupled and share the same mechanism state. Follower health (current draw, temperature) can be monitored separately if needed by accessing follower motors directly.

      Specified by:
      updateInputs in interface MotorIO
      Parameters:
      inputs - mutable inputs container to fill for logging