Skip to main content

Position Tuning with MotionMagicTorqueCurrentFOC

This is a simple guide on how to tune MotionMagicTorqueCurrentFOC:

Firstly, and most importantly, find your maximum and minimum setpoints!!!!!
Put these as preset position rotations in Phoenix Tuner. 
If you don't, your robot will break!

Signals:

Add the following signals to the plot:

  • Position
  • PID Position (Reference)
  • Velocity
  • PID Velocity (Reference Slope)

image.png

Create two groups to create uniform scales (feel free to change colors as necessary to increase visibility):

  1. Position & Position (Reference)
  2. Velocity & Velocity (Reference Slope)

image.png

Tuning:

Navigate to the configs menu using the wrench button,
For Gravity Type, if tuning an arm, select Arm_Cosine, otherwise select Elevator_Static.

Make sure your motors are working together:
To do this, move each motor in the mechanism separately with positive DutyCycleOut to find inversions.

Simulation:

In sim, we don't need to worry about kG and kS because gravity and static friction don't affect simulation tuning. Then, follow these general steps:

  1. Binary Search kA to get the slope of your Position line to match the Reference line
  2. Add kV to maintain the Position line after its peak to keep on matching the Reference
  3. Try and use kA and kV as much as you can to match the line and limit the amount of PID tuning
  4. Binary Search kP to reduce the error between the Position and Reference (try not to make it oscillate to much: you should only need a little)
  5. Lastly, add some kD to dampen out the oscillation made from kP
  6. You can tweak these gains to minimize the error between the Position and Reference

You can keep on doubling the Motion Magic Acceleration and Velocity to make the mechanism move faster as well

 
Real Life Tuning:
  1. Zero all PID gains.
  2. Increase kG to find the smallest possible kG that stops the arm from moving.
  3. Increase kG and find the largest possible kG that stops the arm from moving.
  4. Set kG to the middle of the two values.
  5. Set kS to half the difference between the two values.
  6. Set a setpoint relatively small (typically 0.1 mechanism rotations).
  7. Follow the steps above from the Simulation Tuning

 

 

 

 

  1. Increase kP until you notice significant overshoot.