ASebastianRodriguez / SDCE_PID

PID control of Self Driving Car Course.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Udacity Self Driving Car Engineer Course

Project Nº 6: SDCE_PID

alt text

1) Project Summary:

In this project, you will apply the skills you have acquired in this course to design a PID controller to perform vehicle trajectory tracking. Given a trajectory as an array of locations, and a simulation environment (the vehicle with possible perturbations), you will design and code a PID controller and test its efficiency on the CARLA simulator used in the industry.

The project will provide the dynamic model of the vehicle as well as an approximate distribution of the possible perturbations. The code to use the simulation environment (CARLA) will be provided as well as a template in C++ for the controller.

The deliverable will be the code, explanations about how you chose the parameters, as well as a result of the simulation with analysis of the results.

Project Steps Overview:

  • Design the PID controller in C++.
  • Integrate the controller with the CARLA simulator.
  • Tune the parameters using a technique.
  • Explain a strategy to test the controller and perform the test.
  • Create plots to show how successful the controller is as well as the simulator video.
  • Talk about how the controller recovered/etc. Can be a sentence.

Project Dependencies Overview:

  • CARLA simulator in a workspace.
  • A C++ solver open sources and used in the industry.
  • Code to interact with the CARLA simulator.

2) Installation:

Run the following commands to install the starter code in the Udacity Workspace:

Clone the repository:

git clone https://github.com/udacity/nd013-c6-control-starter.git

Run Carla Simulator:

Open new window:

su - student // Will say permission denied, ignore and continue
cd /opt/carla-simulator/
SDL_VIDEODRIVER=offscreen ./CarlaUE4.sh -opengl

Compile and Run the Controller:

Open new window

cd nd013-c6-control-starter/project
./install-ubuntu.sh
cd pid_controller/
rm -rf rpclib
git clone https://github.com/rpclib/rpclib.git
cmake .
make (This last command compiles your c++ code, run it after every change in your code)

Testing:

To test your installation run the following commands.

cd nd013-c6-control-starter/project
./run_main_pid.sh This will silently fail ctrl + C to stop
./run_main_pid.sh (again) Go to desktop mode to see CARLA

If error bind is already in use, or address already being used

ps -aux | grep carla
kill id

3) Project Instructions:

In the previous project you built a path planner for the autonomous vehicle. Now you will build the steer and throttle controller so that the car follows the trajectory.
You will design and run the a PID controller as described in the previous course.
In the directory /pid_controller you will find the files pid_controller.cpp and pid_controller.h. This is where you will code your pid controller. The function pid is called in main.cpp.

Step 1: Build the PID controller object.

Complete the TODO in the pid_controller.h and pid_controller.cpp.

Run the simulator and see in the desktop mode the car in the CARLA simulator. Take a screenshot and add it to your report. The car should not move in the simulation.

Step 2: PID controller for throttle.

  1. In main.cpp, complete the TODO (step 2) to compute the error for the throttle pid. The error is the speed difference between the actual speed and the desired speed.
    Useful variables:
  • The last point of v_points vector contains the velocity computed by the path planner.
  • velocity contains the actual velocity.
  • The output of the controller should be inside [-1, 1].
  1. Comment your code to explain why did you computed the error this way.
  2. Tune the parameters of the pid until you get satisfying results (a perfect trajectory is not expected).

Step 3: PID controller for steer.

  1. In main.cpp, complete the TODO (step 3) to compute the error for the steer pid. The error is the angle difference between the actual steer and the desired steer to reach the planned position.

Useful variables:

  • The variable y_points and x_point gives the desired trajectory planned by the path_planner.
  • yaw gives the actual rotational angle of the car.
  • The output of the controller should be inside [-1.2, 1.2].
  • If needed, the position of the car is stored in the variables x_position, y_position and z_position.
  1. Comment your code to explain why did you computed the error this way.

  2. Tune the parameters of the pid until you get satisfying results (a perfect trajectory is not expected).

Step 4: Evaluate the PID efficiency.

The values of the error and the pid command are saved in thottle_data.txt and steer_data.txt. Plot the saved values using the command (in nd013-c6-control-refresh/project):

python3 plot_pid.py

You might need to install a few additional python modules:

pip3 install pandas
pip3 install matplotlib

4) Results:

FIGURE 1: Dodging the vehicle to the right.
alt text

FIGURE 2: Arriving at the last vehicle without oscillations.
alt text

FIGURE 3: Stopping at the end of the path.
alt text

FIGURE 4: Steering Error vs. Steering Output.
alt text

In the graphic of the FIGURE 4 can be seen that the error follows the output signal in an acceptable way.

FIGURE 5: Throttle Error vs. Throttle Output vs Brake Output.
alt text

In the graphic of FIGURE 5 we can see that we can be divided into 3 main parts: in the first part there is a damped oscillation, in the second part a high error is seen and in the third part where the vehicle accelerates continuously to go straight, the error decreases.

5) Answers:


a) Add the plots to your report and explain them (describe what you see):

Explanation has been added below each chart.


b) What is the effect of the PID according to the plots, how each part of the PID affects the control command?:

The effect is that, when using this control method, it is about reducing the error of a variable against a setpoint. This control method itself has been formulated in such a way as to be able to control variables using only 3 constants: Kp, Ki and Kd. The proportional value depends on the current error (only using this value would the system oscillate indefinitely), the integral depends on past errors (using this value additionally, the error decreases) and the derivative is a prediction of future errors (by adding this third value it gets faster to get to or away from the setpoint).


c) How would you design a way to automatically tune the PID parameters?:

In the course we learned the method called Twiddle to be able to automate a PID with discrete steps. There are also other methods, such as Ziegler-Nichols, to make these adjustments. Series of rules to tune PID based on an experimental study of multiple system responses (before step input, and studying the critical stability gain in the case of a system with proportional control).

d) PID controller is a model free controller, i.e. it does not use a model of the car. Could you explain the pros and cons of this type of controller?:

Pros:

  • Simple.
  • Efficient.
  • It is widely used in standard control.

Cons:
The cons can be divided into each of the parts of the equation of a PID type control:

  • P = Long settling time and Steady state error.
  • PD = Can amplify high frequency noise.
  • PI = Narrower range of stability.
  • PID = The biggest problem is when you have stochastic variables (non-continuous - changing over time), PID is not a good control method. In this case you have to go to more intelligent control systems.

e) (Optional) What would you do to improve the PID controller?:

Applying some of the existing algorithms to automate and achieve autotuning without the need to modify a multivariable system manually.

6) Manual procedure to tune a PID (include in the main.cpp file):

The procedure for tuning the PID loop is described below:

  • All constants are set to zero.
  • The proportional constant is increased until a response that is as close to the desired response as possible is obtained. At this point it is possible that over impulse or oscillations appear. The steady-state error is probably nonzero.
  • To correct the steady-state error, the integral constant must be adjusted. Overshoot and oscillations may increase.
  • To reduce overshoot and oscillations, the derivative constant is adjusted.

7) Corrections Notes:

Due to changes in the code I have made the following corrections:

  • Steering: I have slightly decreased the derivative constant so that the steering system does not oscillate as much.
  • Throttle: I have slightly increased the integral constant and decreased the derivative constant so that the accelerations are smoother.

About

PID control of Self Driving Car Course.


Languages

Language:C++ 100.0%