Skip to content
iXcess edited this page Sep 25, 2021 · 4 revisions

Tuning Guide

To access the tuning constants which governs your vehicle, access selfdrive/car/<your_car_brand>/interface.py. Look for your vehicle, below is an example code snippet for PERODUA_MYVI:

tuningguide

PID tuning strategy

  • Vary one parameter at a time, by less than 10%. Parameters affect each other.
  • Use a well known test route with excellent lane markings, long straights, varying curvature, varying speeds.
  • Avoid instability
  • Undertuned is sloppy, late, weave
  • Overtuned is jerky, too early, over-correcting, oscillating
  • Find the lower and upper edges of stability, then use a performant moderate value.

Want to understand more about PID controllers? Click here

How the breakpoint and value lists work

When you see xBP and xV, that means that the speeds defined in the breakpoint list (xBP) correspond to the values in the value (xV) list.

So for example let's say xBP = [0., 5., 35.] (in m/s) and xV = [1.0, 1.5, 2.0]

When you are traveling 5 m/s 1.5 is the value that bukapilot uses, for 35 m/s 2.0 is the corresponding value. Speeds in between the defined speeds in xBP are linearly interpolated, so if you're halfway between 5 and 35 m/s the output will be halfway between 1.5 and 2.0. How this works in code: np.interp(20, [0., 5., 35.], [1.0, 1.5, 2.0]) = 1.75

Lateral Tuning

Notes on PID tuning parameters

  • lateralTuning.pid.kpV is the proportional gain for the lateral controller.
    • If turning overshoots the center at a high frequency, decrease it
    • If turning not enough, increase it
  • lateralTuning.pid.kiV is the integral gain for the lateral controller. The function is to correct the small error that the kpV cannot correct while it is already near the center.
    • Too high: it gets to center without oscillations, but it takes too long to center. If you hit a bump or give the wheel a quick nudge, it should oscillate 3 times before coming to steady-state. If the wheel oscillates forever (critically damped), then your kpV or kiV or both are too high.
    • Too low: You get a low frequency oscillation trying to get to the center
  • lateralTuning.pid.kf is the feedforward constant. It can be said as the constant required to hold your steering during a turn. It governs how smooth your turn is.
    • Too high: Your steering oversteers and might hug/overshoot towards the turning lane during a turn.
    • Too low: Your steering understeers and also hug/overshoot away from the turning lane during a turn.

Longitudinal Tuning

Tuning the longitudinal PI controller

The two main factors you can tune to get a different response out of the long PI loop are of course proportional and integral. To make the tuning process less complex, it's said to set the integral gain to all 0's so the only thing that's interacting with the output is proportional at first.

  • longitudinalTuning.pid.kpV is the proportional gain for the longitudinal controller.
  • When to increase proportional:
    1. If your car doesn't give enough gas or brake to reach the set cruise speed in a timely manner.
    2. If your car doesn't brake enough when you approach a stopped lead.
  • When to decrease proportional:
    1. If your car applies so much gas or brake trying to reach the desired speed that it doesn't feel smooth.
    2. If it doesn't feel smooth when reacting to a change in desired speed.

After you have it tuned so that it feels smooth enough either cruising without a lead, or with a lead that is always changing its speed, it's time to start tuning integral.

  • longitudinalTuning.pid.kiV is the integral gain for the longitudinal controller.

  • When to increase integral:

    1. If when the lead is decelerating/accelerating over a few seconds and the car doesn't give enough gas or brake to maintain a safe/reasonable distance
    2. If you're traveling up or down a hill and the car doesn't give enough gas or brake to maintain your desired speed.
  • When to decrease integral:

    1. If you start to experience overshoot (most easily identifiable on hills); ex. once you reach the crest of a hill and your car continues to apply gas when it should start to ease off.
  • gasMaxBP and gasMaxV:

    • gasMaxV represents the maximum percentage of gas (0 being no gas and 1 being 100% gas) allowed to be output by the PI loop. Since gasMaxBP = [0.] and gasMaxV = [0.5], the maximum gas allowed by the PI loop is 50% which is used at all speeds.