How to set vortex motor speed base on RPM

Hi, I am trying to set the speed of a vortex motor based on RPM instead of percentage. I have tried different ways to do this, but none work as well as I want. Does anyone know how to achieve this?

The REVLib docs have a good overview for all the different control types. Have you tried referencing those?

They also have a few example projects.

I tried it, and it doesn’t work. I set the RPM target to 1000, but it only reaches 200 RPM. By the way, I am using the Spark Flex. Is it supposed to work? Because the example uses Spark Max

Everything that works on a CANSparkMax should also work on a CANSparkFlex object. So you can almost directly reference the SPARK MAX example mentioned above.

It sounds like you might need to tweak your kP, kI and kD values. Can you post a graph of your setpoint and measured velocity over time?

Screenshot (23).pdf (117.5 KB)

this is the graph. the target is 2000 and it only reaches around 600

It indeed seems like the code is working, but your PID constants are tuned incorrectly.

There are multiple guides on PID tuning available. I think the WPILib docs have a few, but since you are using SPARK Flex controllers, I’ll link the one from the REV documentation.

Edit: if you are unfamiliar with PID control, it might also be worth it to read the introductory pages on closed-loop control.

1 Like