How to control the speed of a TalonFX motor when using the ControlMode Position?

Hello all!
I have been trying to control my robot using the ControlMode Position. I am using a TalonFX motor, using its built in Encoder. I am using ControlMode Position in order to make the motors move a specific amount, using ticks.
However, when I run the code, the motor moves incredibly fast, and I want to change that. Is there a way to control the speed of the motor, while using this ControlMode?

Thanks in advance!

You have encountered the chief problem with PID to position, when you give it a new setpoint you dump a ton of error onto the control loop and it freaks out a little bit. No good.

What you are looking for is a control mode called motion magic, which will generate a trapezoidal motion profile which means you will get smooth acceleration, cruise, and then smooth deceleration to your setpoint given user defined max acceleration and cruise velocity.

Highly recommend further reading here


There’s some configs that you’ll want to look at in addition to MotionMagic to avoid this situation, most notably the ones that limit the ramp rate and the one that limits the peak output of the motor.

MotionMagic is almost certainly what you want to be doing here, though. I would highly recommend making the most of it if you are using Falcons.

Sure! PID parameters can control that. So, remember that if a controller (based on PID algorithm) determines that the power needs to be more than 1, it will be clamped to 1.
You can also specify max power your PID will produce and it can be less than 1. That will make it slower as well. You can also use trapezoid profiles with MotionMagic as well.

Here is an example of configuring angle motor for PID in our swerve with TalonSRX:

And here is where we tell it to go to a specific position (via Motion Magic; Position will be almost the same, but you actually need less configuration parameters to make Position work than MotionMagic)