Giter VIP home page Giter VIP logo

auto-car-02-estimation-and-control-04-pid-steering-control's Introduction

README

Technical Report for Lane Keeping through PID Controller


Lane Keeping through PID

The goals of this project are the following:

  • Implement the discrete PID controller.
  • Tune controller's parameters so as to keep the car in the center of lane.

Implementation


Initialization

In this project, two PID controllers, one for steering and another for throttle, are used.

Considering the above use case, controller's initializer is modified as follows:

/*
 * Initialize PID.
 */
void PID::Init(double ref, double Kp, double Ki, double Kd, double alpha) {
  // Set reference value:
  (*this).ref = ref;
  // Set controller params:
  (*this).Kp = Kp;
  (*this).Ki = Ki;
  (*this).Kd = Kd;

  // Set exponential decay for integral error:
  (*this).alpha = alpha;
  i_error = 0.0;

  totalError = 0.0;
}
  1. Reference point should be set during initialization. This helps the implementation of fixed speed cruise controller.

  2. alpha is used for exponential decay of integral error. This helps to reduce the out of turn oscillation of steering controller.

Control Calculation

This follows the procedure in the tutorial, but exponential decay is used for integral error calculation.

After this modification, the integral error equals approximately to the mean value of the last (1 - alpha)^(-1) observed errors.

This can greatly reduce the out of turn oscillation of typical PID steering controller

/*
 * Update the PID error variables given actual value.
 */
void PID::UpdateError(double actual) {
  // a. Proportional part:
  p_error = ref - actual;
  // Initialize PID state:
  if (!is_initialized) {
    p_error_last = p_error;

    is_initialized = true;
  }
  // b. Differential part:
  d_error = p_error - p_error_last;
  p_error_last = p_error;
  // c. Integral part:
  i_error = alpha * i_error + (1.0 - alpha) * p_error;

  // Generate control:
  control = Kp * p_error + Kd * d_error + Ki * i_error;

  // Update stats:
  totalError += pow(p_error, 2);
}

Reflection


Describe the effect each of the P, I, D components had in the controller

Each component's effect is as follows:

  1. P part: This part generates the instant responsive part of steering value. It counterbalances the non-zero CTE value so as to make the car return to the center of lane.
  2. D part: This part generates the predictive part of steering value. When it sees a continuously increasing trend in observed error, as in the case when the car is entering a turn, extra steering will be generated to facilitate the turing of vehicle.
  3. I part: This part generates the compensatory part of steering value. When the car is inside a long turn, it needs a constant steering value so as to keep turning stably. This cannot be generated by PD parts, which need existing error for control signal generation.

Describe how the final hyperparameters were chosen.

Twiddle is a fancy algorithm for automatic PID parameter turning.

However, since in this project simulator needs human attention during testing process in case of either driving out of road or bumping into ledges and no autonomous API is available. Here manual turning is used.

I tuned the controller as follows:

  1. First, set both Ki & Kd to zero. Increase Kp till the car shows slight oscillation when it in the center of lane. After Kp is selected, obvious steering lag will be observed when the car is inside the turn. Next Kd is added to generate predictive steering for this scenario.
  2. After that, keep Ki as zero and increase Kd until a satisfactory lane entering behavior is observed. After Kp & Kd is determined, there is still constant actuation when the car is inside a long turn.
  3. Finally, add a little integral part by starting with a small Ki and increase it gently until satisfactory lane keeping behavior is observed inside long turn.

The final params for steering controller is as follows (constant speed ~= 15):

Parameter Value
Kp 0.1250
Ki 0.0005
Kd 0.0625

auto-car-02-estimation-and-control-04-pid-steering-control's People

Contributors

alexgecontrol avatar baumanab avatar davidobando avatar domluna avatar htuennermann avatar swwelch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.