# Lab 04. PID Controller for Drone

Jump to: navigation, search

Lab 04. PID Controller for Drone

## Lab Objectives

The objective of this lab is to develop a PID controller for pose and altitude stabilizer for a quadcopter, and investigate the stability of the controller using a statistical analysis.

You are given the python code `ardrone_pilot.txt` (change extension to `.py`) that provides all primitives to subscribe to and publish ROS topics of the ARdrone. Note the presence of global state variable that provides up to date data collected from ROS topics of the ARDrone, like altitude, position, velocities, etc.
The code will make the drone takingoff, then hovering for 60 seconds using the PID controller to be developed, than landing automatically. After it lends, you need to collect results.
Observe that in lines 202-204, all values of the pose are logged to a fine defined in line 145. This file will contain the values of the positions and altitude that you will statistically analyze using Excel, to find average, standard deviation and coefficient of variation, in addition to plotting curves, as requested below.

## Video: How to Work Demo

The video below demonstrates how to run a simulation for a PID controller, collect log file, open it with Excel, plot curves, and performs statistics.

## Your Task

### P-Controller for Altitude

1. First, you will need to develop a P-controller for the altitude. In the `run()` function of the `AltitudeControlThread` thread, there is a missing code related to altitude control, namely, in `TASK1` and `TASK4` and `TASK5`.

Note that the P-Controller of the pose is already done for you, so do not modify it.

1. For the P-Controller you have two scenarios:
• Scenario 1: P-Controller for altitude with `kpz=0.000888`
• Scenario 2: P-Controller for altitude with `kpz=0.000111`
• Scenario 3: P-Controller for altitude with `kpz=0.055500`
1. Run the P-Controller for the three scenarios.
2. In every run, collect the data from log file and import it to an Excel file. Use the same Excel file where every sheet in the Excel file, corresponds to scenario.
3. After collecting data, plot all values of the altitude in one plot for all scenarios. Also, plot the reference altitude.
4. Calculate the average, standard deviation and coefficient of variation of the altitude between the instance the drone reaches the first close altitude value (+- 100 mm) to the instance it starts landing (state = 8)
5. Interpret the results found for the P-Controller and compare the three scenarios

### PID-Controller for Altitude

In the previous example, we did only a P-Controller for the altitude. Now, we will investigate the impact of the Integral and Derivative components of the PID controller.

1. First, implement the PID controller for the altitude. You need to calculate the derivative of the error and the sum of the error.
2. For the P-Controller you have two scenarios:
• Scenario 4: P-Controller for altitude with `kpz=0.000888` and `kiz=0.000000111` and `kdz=0.000000011`
• Scenario 5: P-Controller for altitude with `kpz=0.000111` and `kiz=0.000000111` and `kdz=0.000000011`
• Scenario 6: P-Controller for altitude with `kpz=0.000111` and `kiz=0.00000111`
1. Run the PID-Controller for the three scenarios.
2. In every run, collect the data from log file and import it to an Excel file. Use the same Excel file where every sheet in the Excel file, corresponds to scenario.
3. After collecting data, plot all values of the altitude in one plot for all scenarios. Also, plot the reference altitude.
4. Calculate the average, standard deviation and coefficient of variation of the altitude between the instance the drone reaches the first close altitude value (+- 100 mm) to the instance it starts landing (state = 8)
5. Interpret the results found for the PID-Controller and compare the three scenarios last scenario.
6. Compare the results with the P-Controllers results.
7. What is the best controller among all of them?

### P-Controller for Pose

See the code of the P-Controller of the pose. Explain the theoretical equations of this controller and how it works.

## What to Submit

You need to submit a word file properly written that respond clearly to all the question above. 2 points will be given for the quality of writing and explanation. You need to also to submit a working python code that allow to control the altitude of the drone. You will test your code in the next lecture

## Work strategy

This lab assignment should be done by a group of 2-3 students in each group. However, I will ask every student individually about his work. Students in the same group might have different grades.

## Deadline

This task must be submitted on Monday at 4:00 pm, by email.

## Grading

Will be considered as a Project 01 (20%). See Grading