MotorController Integration

Phoenix 6 motor controller classes such as TalonFX (Java, C++, Python) implement many APIs from the MotorController (Java, C++) interface. This allows Phoenix 6 motor controllers to more easily be used in WPILib drivetrain classes such as DifferentialDrive.

// instantiate motor controllers
final TalonFX m_motorLeft = new TalonFX(0);
final TalonFX m_motorRight = new TalonFX(1);

// create DifferentialDrive object for robot control
final DifferentialDrive m_diffDrive = new DifferentialDrive(
   m_motorLeft::set, m_motorRight::set
);

// instantiate joystick
final XboxController m_driverJoy = new XboxController(0);

public void teleopPeriodic() {
   var forward = -m_driverJoy.getLeftY();
   var rot = -m_driverJoy.getRightX();

   m_diffDrive.arcadeDrive(forward, rot);
}
void Robot::TeleopPeriodic() {
   auto forward = -m_driverJoy.GetLeftY();
   auto rot = -m_driverJoy.GetRightX();

   m_diffDrive.ArcadeDrive(forward, rot);
}
// instantiate motor controllers
hardware::TalonFX m_motorLeft{0};
hardware::TalonFX m_motorRight{1};

// create differentialdrive object for robot control
frc::DifferentialDrive m_diffDrive{
   [this](double output) { m_motorLeft.Set(output); },
   [this](double output) { m_motorRight.Set(output); }
};

// instantiate joystick
frc::XboxController m_driverJoy{0};
def __init__(self):
   # instantiate motor controllers
   self.motor_left = hardware.TalonFX(0)
   self.motor_right = hardware.TalonFX(1)

   # create DifferentialDrive object for robot control
   self.diff_drive = wpilib.drive.DifferentialDrive(
      self.motor_left.set, self.motor_right.set
   )

   # instantiate joystick
   self.driver_joy = wpilib.XboxController(0)

def teleopPeriodic(self):
   forward = -self.driver_joy.getLeftY()
   rot = -self.driver_joy.getRightX()

   self.diff_drive.arcadeDrive(forward, rot)

Motor Safety

CTR Electronics supported actuators implement WPILib Motor Safety. In additional to the normal enable signal of CTR Electronics actuators, Motor Safety will automatically disable the device according to the WPILib Motor Safety implementation.

Simulation

It’s recommended that users set supply voltage to RobotController.getBatteryVoltage() (Java, C++) to take advantage of WPILib’s BatterySim (Java, C++) API. Additionally, the simulated device state is shown in the simulation Other Devices menu.

Simulation other devices menu