Motor Control
There are several control modes used to drive a motor. The control mode used will depend on the application. The modes fall into two larger categories Open-Loop and Closed-Loop. Open-Loop control is often used with feedforward to set an arbitrary amount of power to drive the motor. Closed-Loop modes will alter the motor power based on sensor feedback.

The following picture shows the most commonly used Phoenix control modes. Each control mode is represented by a data structure class that gets applied to the motor when requested. The DutyCycleOut and VoltageOut modes are would be used with direct input from a game controller. VoltageOut can also be used with a PID loop that was implemented in the user program.
The PositionVoltage and VelocityVoltage requests will run the PID loop inside of the Pheonix controller. One of four Slots can be choosen that hold the PID gain values. A FeedForward value can also be submitted with the control request.

Open Loop Modes
Open-Loop modes are usually used in combination with a game controller. The setup is very simple since there's no feedback sensor required. A percentage power output is sent to the motor using the DutyCycleOut class. Percentage power is the proportion of supply voltage to apply in fractional units between -1 and +1. See Open Loop Control in the Phoenix6 documentation.
Closed Loop Modes
On the roboRIO robot the motor controllers will implement the necessary PID loops, so we don't have to use the WPILib PID controllers as we did on the Romi. We still have to write a few lines of code to specify the control mode and a setpoint target, but the motor controller will mostly do the rest. The following Closed-Loop modes can be used with the Talon FX and SPX motors. For more details see the Phoenix6 Closed Loop Control documentation.
-
Position - The Position Closed-Loop control mode can be used to abruptly servo to and maintain a target position. Mainly used for mechanisms like elevators and arms that are subject to gravitational forces. See Position Closed-Loop Control in the Phoenix6 documentation.
-
Velocity - Velocity Closed-Loop logic is used to maintain a target velocity. Often used for mechanisms like flywheels that need to be kept at a constant speed. It's also used for the drivetrain where a continuous stream of velocity setpoints are sent drive a desired trajectory. In this mode the controller will try and maintain the velocity regardless of the torque put on the motor. See Velocity Closed-Loop Control in the Phoenix6 documentation.
-
Motion Magic - Motion Magic is a control mode for Talon SRX that provides the benefits of Motion Profiling without needing to generate motion profile trajectory points. When using Motion Magic, Talon SRX / Victor SPX will move to a set target position using a motion profile, while honoring the user specified acceleration, maximum velocity (cruise velocity), and optional S-Curve smoothing. See Motion Magic in the Phoenix6 documentation.
-
Continuous Mechanism Wrap - A continuous mechanism is a mechanism with unlimited travel in any direction, and whose rotational position can be represented with multiple unique position values. Some examples of continuous mechanisms are swerve drive steer mechanisms or turrets (without cable management). See Continuous Mechanism Wrap in the Phoenix6 documentation.
The sensors used for closed-loop control are designated during motor configuration. The most common sensor used with the FalconFX/SRX controller is the RotorSensor, formally referred to as the Integrated Sensor, which is an encoder that is physically attached to the motor. We only need to pass in the Control-Mode and setpoint in order to run our closed loop.

Setting PID Gain Values
All of the built-in Closed Loop Control modes require PID values configured into the motor controller. You can set up multiple PID gain values and put them into memory slots within the Talon's motor controller. You can then assign the gain values from a selected slot when you make the control request to the motor. There are four slots to choose from, so you can configure up to four sets of PID gain values.

The following code sets up the PID values for Slot0 of the drivetrain's front wheels. The PID values should be determined by experimentation.
We can switch between the PID slots in our code when we make the velocity request to the motor. Most Closed Loop Control requests also allow you to add a FeedForward value.
// create a velocity closed-loop request, voltage output, slot 0 configs
var request = new VelocityVoltage(0).withSlot(0);
// set velocity to 8 rps, add 0.5 V to overcome gravity
talonFX.setControl(request.withVelocity(8).withFeedForward(0.5));
See Closed-Loop Gain Slots in the Phoenix6 documentation for details.
Status Signals
Signals represent live data reported by a device; these can be yaw, position, etc. To make use of the live data, users need to know the value, timestamp, latency, units, and error condition of the data. See Status Signals for a detailed explaination.
Hardware Attached Simulation
CANivore supports hardware-attached simulation when used in an FRC robot program. This allows a CANivore to be used with real devices from a PC. See Hardware Attached Simulation in the Phoenix 6 documentation. The devices must be independently powered since the USB cable will not supply enough power.

References
-
Talon FX/SRX Sensors - Phoenix documentation.