# Lab 04. PID Controller for Drone

Lab 04. PID Controller for Drone

## Contents

## 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

- 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.

- 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`

- Run the P-Controller for the three scenarios.
- 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.** - After collecting data, plot all values of the altitude in one plot for all scenarios. Also, plot the reference altitude.
- 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)
- 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.

- First, implement the PID controller for the altitude. You need to calculate the derivative of the error and the sum of the error.
- 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`

- Run the PID-Controller for the three scenarios.
- 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.** - After collecting data, plot all values of the altitude in one plot for all scenarios. Also, plot the reference altitude.
- 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)
- Interpret the results found for the PID-Controller and compare the three scenarios last scenario.
- Compare the results with the P-Controllers results.
- 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