Skip to content

Control algorithm to control steering angle to navigate a vehicle around a track

License

Notifications You must be signed in to change notification settings

wolfgang-stefani/PID-Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PID-Controller

This software implements a PID controller in C++ to maneuver a vehicle around a track in a simulator. The simulator will provide the cross track error (CTE) and the velocity (mph) in order to compute the appropriate steering angles. The following clip shows the vehicle in the simulator controlled by the PID controller.

This is only for demonstration. The coefficients can be tuned to follow the intended trajectory more accurately resulting in a more comfortable and less shaky ride.


Fundamentals

A large number of different controllers exist to move robots and vehicles. The most fundamental is called PID (Proportional-Integral-Differential). It enables complex, changing accelerations and steering angles. The PID controller is an algorithm that calculates a value (for example a steering wheel angle) according to an error called CTE (see next section for an explanation).

PID is a controller with three coefficients. But first, let's have a look on two important terms before explaining the three components.

Cross Track Error (CTE)

  • distance between the vehicle´s actual trajectory and the intended trajectory

Systematic Bias

  • Systematic bias is a problem that often occurs in robotics. The problem is due to mechanics. Buying for example a vehicle, we think the steerable front wheels are 100% aligned. But in reality the wheels can be aligned a little bit at an angle. The systematic bias manifests itself in a steering drift. For humans this is not a big deal because we just countersteer intuitionally but in robotics this is a fact to be considered.

P-Controller

  • sets the steering angle in proportion to CTE (the coefficient tau_p is called "response strength"):

steering angle = -tau_p * cte

  • steers the vehicle towards the trajectory
  • using only P-Controller leads to overshooting and oscillating which is demonstrated in the following graph:

PD- Controller

  • steering angle is not just proportional to CTE but also to the time derivative of CTE:

steering angle = -tau_p * cte - tau_d * diff_cte

  • the derivative component countersteers the vehicle and helps not to overshoot the trajectoy and not to oscillate
  • The following graph demonstrates the behaviour of P- and PD-controller combined:

PID-Controller

  • this controller finally solves the problem of overshooting and systematic bias by adding one more term. Using a PID-Controller the steering angle is additionally proportional to the integral of CTE. It considers the systematic error and compensates it.

steering angle = -tau_p * cte - tau_d * diff_cte - tau_i * int_cte

Now it seems like PID is doing worse than PD but this is only because the graphs above assumed an ideal robot with no bias.

Twiddle PID-Controller

Below you can see the corresponding P-, PD- and PID-graphs using a robot with systematic bias. Now you can see that with a real robot with bias the PD-controller is actually not doing better than the PID-Controller.

The dashed line is the goal PID-Controller. We achieve this with a so-called twiddle PID controller (green line) with tuned parameters. Now the PID controller outshines the PD controller. Also, with twiddle the PID controller converges faster but we overshoot drastically at first. This overshoot can be reduced by tuning the twiddle parameters.

Implementation and Tuning coefficients

Manual tuning of PID coefficients for steering values. Please refer to the code lines 40 to 46 in main.cpp to see the different, tested values for the PID coefficients and retrace the approach to good values. In the following you can see what it would look like to drive with only P- or PD-Controller and the final result with a PID controller.

P-Controller

The vehicle drives along the trajectory with oscillations:

PD-Controller

The vehicle follows the trajectory with relatively low oscillations:

PID-Controller

The vehicle follows the trajectory quite well.

Due to overspeeding it shakes while taking turns. You can see this in the full clip on YouTube in which the car is driving a whole round: https://www.youtube.com/watch?v=1uSolAqVdQ0

Dependencies

Fellow students have put together a guide to Windows set-up for the project here if the environment you have set up for the Sensor Fusion projects does not work for this project. There's also an experimental patch for windows in this PR.

Basic Build Instructions

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

Tips for setting up your environment can be found here

Releases

No releases published

Packages

No packages published