We have used PID control for positional control in the past. We like the smoothness of motion magic but do now know how to tune the various parameters.
We have read the documentation for motion magic but want to know what the process is for getting the various values. Particularly KS, KV, KA
Also what is different for getting Expo KA and Expo KV
I don’t know if this is the right way, but we start with kS by switching to VoltageOut mode and finding the voltage that just barely starts moving the mechanism.
Then, we start with a kV of .12, because that would be 12V to get it to run at 100rps. You can adjust that according to your situation.
I’m not sure about kA, but I’d probably start with .01 like the example in the docs and adjust it if it seems like the acceleration is too slow, too fast, etc.
Then PID to adjust error. I’d probably start with a P of 1 and go from there.
What’s really nice about phoenix 6 is that everything is unit aware now, and the gains have some physical meanings behind them.
Make sure you check whether you’re running in MotionMagicVoltage or MotionMagicDutyCycle mode when you make the control request. Voltage means you’ll want things to output in the range of -12 to 12ish, while duty cycle should be in the range of -1 to 1. I’d recommend voltage as it’s more robust to battery voltage changes.
As @celttechie says, the best way to find Ks is by seeing the lowest voltage needed to just barely start to move.
Kv is also not hard to find empirically. Run the system at a constant amount of power (lets say 10 volts), and measure the velocity in rotations per second (rps)
Divide your output (10) by the measured velocity to get Kv.
This is a little imprecise but its good enough if you have PID correcting for it after.
Ka is for acceleration, so you need to measure how much power is needed to achieve a certain acceleration, this is trickier.
Again, enable the motor at some static voltage level (10 volts lets say) and graph the measured velocity over time.
Try to zoom in on the graph and find an area where the speed was increasing at a steady rate (this is difficult if the acceleration is high).
Estimate the slope of the graph by checking 2 points along this flat increase and dividing the difference in velocity over the difference in time between the points.
Divide your applied output (10 volts) by this measured acceleration.
I highly recommend using CTRE’s Tuner X to run these tests and take these measurements. It will let you change the gains quickly, test the motor, and graph the responses.
Expo Ka and Kv shouldn’t be different for measurement purposes, but as the docs you linked explain, since the system uses these gains to calculate the motion magic setpoints, you may want to increase them to artificially slow down the profile from the maximum possible velocity and acceleration of the system.