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 DutyCycle to find inversions.

 

  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. Increase kP until you notice significant overshoot.


  8. Increase kD until the overshoot stops happening.

  9. Repeat steps 7 and 8 until increasing kD results in more oscillation, or until the system oscillates on its way to the setpoint. If oscillation on the way to setpoint is seen, decrease kD until it stops. Then reduce kP until any remaining overshoot stops. The goal is to maximize kP and kD to minimize the travel time.

  10. Verify gains work for other setpoints as well.

 

If tuning a turret, start by finding kS by setting a small setpoint and finding the highest value that doesn't move the mechanism. Then continue from step 7 onwards.