Old OP PID tuning guide

This is from opc.ai back when it was around. RIP Oppey.

• Feel free to use your own parameters if you have some that are already working, but it’s also fun to start from “scratch” and experiment to learn the full impact of each change.

• Start with Kp = 0.25

• Start with Ki = 0.03 (Set low on purpose)

• Start with Kf = 0.00003 (Set low on purpose)

• Start with steerActuatorDelay = 0.1 (unless someone else has already found a closer value for your car)

• Start with steerRatio = factory spec

• Start with steerRateCost = 0.5

• Start with tireStiffness values of whatever you have stock in interfaces.py. Honda civic defaults are around 200000.

Drive on a straight road with OP engaged.

Kp will be the first parameter that we adjust, starting from Kp = 0.25

• If OP is oscillating back and forth around center, it will either be a slow or fast oscillation depending on how high/low your Kp is. We’re looking for a small amount of slow-ish oscillation.

• Increase Kp to 0.5, then decrease to 0.1. Choose the “best” one and split the difference between it and 0.25. Set Kp to the new value in the middle.

• You’re looking for no fast wobble around center. You want a lazy wobble around center, or ideally a fairly solid hold on center without any abrupt movements.

• Choose the best of 0.25, the extreme value, and the new “split difference” value. Split the difference again in the best direction and continue this process until Kp is optimized.

• You may need to re-tune this at slow speeds (10mph) and fast speeds (60+mph) and possibly even use speed-dependent Kp values as mentioned in the “Background” section above.

• If there are high winds or the road has significant camber then you may experience the car drifting to one side and OP adjusting the wheel only in one direction (always adjusts to the right, etc). This is okay. Keep focused on back AND forth oscillations of the wheel take take you across the center of the lane (slow or fast).

• Don’t drive yourself too crazy on this, as we still need to tune steerActuatorDelay to get the best performance.

Adjust steerActuatorDelay:

• steerActuatorDelay adjusts the starting orientation of the car which is fed into the MPC in order to account for the delay between the measurements and the response to a commanded output. The delaycurvature_factorsteerRatio product needs to match the response of your car.

• steerActuatorDelay should be adjusted in the range of 0.025 to 0.200 in 0.025 increments (0.025 – 0.050 – 0.075 – 0.100 – 0.125, etc)

• Find the setting that provides the least amount of wobble around center. You should see a dramatic difference between 0.025 and 0.200, and somewhere in-between should be a “best” setting.

• Some truly bad MDPS systems may even need delays above 0.200?

Adjust Kp slightly up and down to see if you can further optimize it now that the ActuatorDelay is set.

Adjust Ki to help with constant offsets like wind, cambered roads, etc.

• Increase Ki to 0.2, then try 0.1, 0.05, etc. Find the value just before it begins to do a slow overshoot, correct, overshoot, correct pattern.

• Again, you’re looking for no movement around center or a very slow and gentle movement around center.

Now try taking some turns and adjust Kf.  

• First make sure that OP is properly identifying the lane lines in the turn you are attempting to take. Not just the green path, but the actual lane lines on each side as well.

• If you’re having an issue initiating and holding turns, try increasing Kf. 0.00006 is the typical value used, and somewhere between 0.00003 and 0.00010 will probably be appropriate.

• If you increase Kf to help in turns, you may need to decrease Kp slightly if oscillations have increased. If you have increased Kf too much then it may not be possible to compensate with Kp changes.

• There is a balancing act between Kf/Kp/Ki that you are trying to find.

Camera Offset:

• If the car is too far right in the lane, try decreasing camera offset from the stock value of 0.06 to something like 0.03 or 0.0.

• If the car is too far left in the lane, try increasing camera offset by 0.03 at a time.

Adjusting tireStiffness changes the curvature_factor used in the MPC.

• Feel free to play with the tireStiffness values. The stock Honda civic values are around 200,000. Yours may be slightly higher or lower.

• Values between 50000 – 300000 are probably worth playing with.

• While tuning, try to keep them at the same value as generally they end up pretty close to each other anyway (within 5-10%)

Adjusting steerRateCost will affect how eager the car is to make sudden direction changes.

• steerRateCost around 0.7-1.0 will feel very sluggish and unwilling to make direction changes.

• steerRateCost around 0.5 is a nice median.

• steerRateCost around 0.3 or less will feel extremely darty as the lane has minor deviations or the path changes.

Adjusting steerRatio:

• steerRatio will have a large impact due to it essentially scaling Kf/Kp/Ki together (steerRatio is multiplied by the MPC’s calculated steering angle delta, and this result is then multiplied by the gains).

• Changing steerRatio will require scaling Kf/Kp/Ki as well in order to regain the tuned performance. It will be a dramatic change.

• I don’t bother changing steerRatio from spec once Kp and Kf have been tuned since the only other minor impact on lateral control it has is on the VehicleModel slip factor / curvature_factor calculation which is then fed into the MPC & the actuator delay orientation calculation.

• My advice: leave it alone

latPidDeadzone shouldn’t need to be messed with (defaults to 0).  

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s