Skip to content

Repository files navigation

PID Controls

The project implements a PID controller in C++ to maneuver the vehicle around the track.


PID controller

PID architecture

PID controller generates a steering value (actuating signal) to input "SYSTEM", which is a simulator in the project. in feedback control, The simulator will provide the cross-track error (CTE) and so on to simulate Senser data. So I can find how far off the vehicle is from where I want it to be. So the cross-track Error (CTE) is an error term that is the distance between vehicle position and centerline position. If the steering value is accurate. the error term would be zero. So the target is how do I take this CTE and convert it into a suitable steering value.

PID

Using the CTE at the present moment to decide How much "α" are going to rotate . For example If the CTE is 10m and I set P-controller τ as 0.1 . then I can get the steer speed is 1 rad/s. So A second later, the steering value would be 1 rad , So I can get α = 1 * 180 / π

So the "α" is proportional to The CTE. In the project, I directly design P-Controller as Kp * p_error

But here a problem. the Vehicle does not stop when it reaches the centerline. The speed of a vehicle can be decomposed into horizontal and vertical speeds. PID So the vehicle is overshoot. When the vehicle tried to fix the overshoot, it would create a Vy in the opposite direction. So the Vy is never to be zero.

PID

We need a controller to respond to how fast the Vehicle's closing in on the goal. So a derivative is a better way to measure the rate of change of the error that is how fast the error is growing or shrinking. For example, if the vehicle is running quickly and fast approaching the centerline. this means that the error is quickly decreasing, That decreasing error has a negative rate of change, which will produce a negative value. That negative value will be added to our controller's output. Therefore lowering the steering value. preventing the Vehicle from overshooting. In the project, I take current CTE minus the Prevouise CTE Kd *(cte - p_error)

PID When there was a bias in the system, we had better use past CTE data to correct the system bias. So the Integral controller will do calculate all the CTE Subtract from the steering value. In the project, I took Ki * ∑ cte.

There are three branches each contribute some amount to the overall output of the controller and there are three parameters to weigh each controller contribution. So the finial controller output is -Kp *p_error - Ki* i_error - Kd * d_error

The next step is tuning the parameters Kp Ki Kd

PID paramaters tuning

PID tuning

PID tuning guide

PID tuning

  • step 1: pid_a.Init(0.1, 0.001, 1); First I set initial value as Kp = 0.1 Ki = 0.01 Kd = 1. Because Kp, Ki, Kd is inversely proportional to T. The vehicle ran out of the left lane . So I increased Kp to decrease T-rise.

  • step 2: pid_a.Init(0.2, 0.001, 1) The T-rise is better then before. So I increased a small value.

  • step 3: pid_a.Init(0.25, 0.001, 2) The vehicle oscillated , I increased Kd to decrease overshoot.

  • step 4: pid_a.Init(0.25, 0.001, 3) The Oscillating situation is not better, I need to continue to increase the Kd.

  • step 5: pid_a.Init(0.25, 0.001, 4) When the vehicle runs through a fast curve lane, goes out of the lane. I increased Kd to deal with strong changes in future data

  • step 6: pid_a.Init(0.25,0.001, 5);
    The vehicle oscillate wiht weakening intensity, I increased Kd to decrease overshoot

  • step 7: pid_a.Init(0.25, 0.001, 5.5); The vehicle was slightly overshooting. I increased Kd to a small value.

  • step 8: pid_a.Init(0.25, 0.001, 5.75); The vehicle went off the track on the second lap, I increased Kd to decrease overshoot.

  • step 9: pid_a.Init(0.25, 0.001, 6.0); The controller works well with these parameters. No further Twiddle algorithm was required, and the Twiddle algorithm was not very efficient in this project.

Build

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.

The environment can be found here

Licensing, Authors, and Acknowledgements

Built With

Versioning

Authors

License

  • This project is licensed under the MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages