Skip to content

Longitudinal speed control with PID and feedforward, against a drivetrain lag and a road slope #429

Todo

Description

@ShisatoYano

Proposal

Add longitudinal speed control with PID and a feedforward term, and a simulation where it matters: the commanded acceleration reaches the vehicle through a first-order lag and against a driving resistance (a road slope), so the current proportional control can't hold the target speed.

a_cmd   = a_ff + K_p e_v + K_i ∫ e_v dt + K_d de_v/dt,   e_v = v_ref - v
a_ff    = dv_ref/dt + g sin(slope)                        (feedforward)
plant:  da_act/dt = (a_cmd - a_act) / tau,   dv/dt = a_act - g sin(slope)

Why

Every controller of Chapter 4 controls the speed with a = K_v (v_ref - v) (for example PurePursuitController._calculate_target_acceleration_mps2(), SPEED_PROPORTIONAL_GAIN = 1.0). In the kinematic model the commanded acceleration is applied exactly (State.update(accel_mps2, yaw_rate_rps, time_s)), so a P control has no steady-state error and PID would show nothing. With a lag and a slope, P leaves an error on the slope, I removes it, and the feedforward removes most of it before any error builds up. This is the longitudinal control taught with Pure Pursuit and Stanley in introductory courses. #376 is PID for the steering; this issue is the speed.

Expected change

  • src/components/control/speed_pid/speed_pid_controller.py: a SpeedPidController(kp, ki, kd, use_feedforward) with update(target_speed_mps, target_accel_mps2, speed_mps, slope_rad, time_s) -> float (the commanded acceleration). The derivative is the difference of the error between two calls divided by time_s; the integral is the sum of e_v * time_s
  • The plant stays in the simulation, not in State: the first-order lag (tau_s, for example 0.5 s) and the slope resistance are a small class in the simulation script that turns a_cmd into the acceleration passed to the vehicle. The vehicle model and the command interface will change in Phase 1: Command(accel, steer) and a swappable vehicle model #108; putting the plant into State now would collide with it. Write this in the docstrings
  • src/simulations/path_tracking/speed_pid_control/speed_pid_control.py: a straight course with a target speed that steps up and down, and a slope on part of it (only as a resistance; the drawing stays flat). Four vehicles or four runs: P (the current gain), PI, PID, PID with feedforward. Plot speed and the speed error against time in a separate figure after the run (GlobalXYVisualizer has one plot area; don't change it)
  • test/test_speed_pid_control.py (show_plot = False, then main()), and test/test_speed_pid_controller.py with a unit test that on a constant slope the PI controller's error goes to zero while P keeps an error of about g sin(slope) / K_p
  • The simulation in the Sections list of doc/path_tracking/index.md, next to the speed profile of Speed profile from the course's curvature, compared with a constant target speed #380 (the maintainer confirms the number)
  • Run python generate_pyrightconfig.py for the new folders

Comparing P, PI, PID and feedforward

In the PR description, a table of the steady-state error on the slope and the overshoot after the speed step for the four controllers, and one or two sentences on what changes when tau_s is doubled.

Out of scope

  • Engine, gear and brake models; anti-windup, unless the integral clearly winds up at the speed limits of State (then say why in the PR)
  • Changing State, FourWheelsVehicle or the existing controllers

References

How to contribute

Comment /claim on this issue to be assigned. Follow Steps 2–4 of HOWTOCONTRIBUTE.md, attach the GIF or plot and the table to the PR, and write Closes #<this issue> in the description.

Activity

  1. added
    enhancement
    help wanted
    on Dec 4, 2026
  2. leninworld commented on Dec 5, 2026

    @leninworld
    Contributor

    /claim

  3. github-actions commented on Dec 5, 2026

    @github-actions
    Contributor

    @leninworld This issue is now assigned to you. Thank you!

    • Open a pull request with Closes #429 in the description.
    • If you have already opened a pull request, edit its description (for example, add a line) to run the check again.
    • If neither a pull request nor a comment from you on this issue appears within 14 days, you are unassigned so that someone else can take it. You can claim it again later.

    See Claim an issue before you start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wanted

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions