Appendix A: Altitude Tuning
Contents
Appendix A: Altitude Tuning#
In this part, you will be transferring the altitude PID you created in part 1 onto your drone. You will then tune the PID gains on your drone as you did in the simulator.
Flying with Our PID#
When you first flew the drone, in the Duckietown stack, you were directly setting the PWM “stick” levels with the keyboard and mouse. This translates to moving the throttle, roll, and pitch sticks on an RC receiver to fly the drone. There is a PID running on the flight controller that interprets these stick commands as desired rolls, pitches, and yaws, and then controls the motor spinning to achieve this.
Now, you will instead fly with a higher level of autonomy and use our PID controller to fly with velocity and height control. You will use the camera to estimate velocity with Optical Flow, and the range sensor to estimate height. Then the PID controller will set the PWMs to achieve these targets: either a fixed velocity of 0 m/s in X and Y, or a fixed velocity based on what keys are pressed on the keyboard. We are doing position control for the height, so it adjusts the throttle to maintain a target height above the ground using an altitude sensor.
Bring Down the Containers#
First, bring down all the containers. Run docker ps -a
and the docker stop
on each container. Then reboot, and run docker update --restart=no my-container
for each container that automatically restarts. Reboot again. When you are done, docker ps -a
should show no containers running.
Update pidrone_pkg
#
Now update and rebuild the pidrone_pkg
container. Run git pull
in
pidrone_pkg
and then rake build
, rake create
and rake start
.
The build this time will be much faster, because it will not have to
download everything from scratch.
STOP HERE#
Please stop here for now. These instructions have not been tested with the new version of the drone.
You will now be using your altitude PID to control the height of the drone. To tune your altitude PID, you will first use the Ziegler-Nichols tuning method to generate an initial set of tuning parameters. You will then fine tune these parameters similar to how you tuned the drone in simulation.
To use your PID, you’ll be running student_pid_controller.py
instead of pid_controller.py
. This will allow your PID to run alongside our planar PIDs; your PID will be responsible for keeping the drone flying steady vertically.
Setup
Change directories to ~/catkin_ws/src
. Run git clone https://github.com/h2r/project-pid-implementation-yourGithubName.git
. In your repo, change “~/ws/
and run catkin_make --pkg project-pid-implementation-yourGitHubName
.
OR
Use the scp
command to transfer student_pid_class.py, student_pid_controller.py, and z_pid.yaml from the repo on your base station to the scripts folder of your drone (~/catkin_ws/src/pidrone_pkg/scripts/
). In the instructions below, instead of using rosrun
, you may use python
to execute your scripts.
Change directories into ~/catkin_ws/src/pidrone_pkg
and modify pi.screenrc to start up with your altitude pid by changing python pid_controller.py\n
to rosrun project-pid-implementation-yourGitHubName student_pid_controller.py\n
. Prepare your drone to fly and then navigate to `4 of the screen. Press ctrl-c to quit student_pid_controller.
In this screen (`4), modify ~/catkin_ws/src/project-pid-implementation-yourGitHubName/z_pid.yaml
by setting \(K\) to 1250 and the rest of the gain constants to 0. Now run rosrun project-pid-implementation-yourGitHubName student_pid_controller.py
to fly with your altitude PID.
Exercises
Fly your drone and observe its flight. Tune \(K_p\) by slowly increasing its value between flights until you can see the drone moving up and down with uniform oscillations. Each time you will need to quit the controller, edit ~/catkin_ws/src/project-pid-implementation-yourGitHubName/z_pid.yaml
, and then run rosrun project-pid-implementation-yourGitHubName student_pid_controller.py
again to use the new PID gains.
Record your final \(K_p\) value that causes uniform oscillations as \(K_u\), the ultimate gain.
Fly your drone and pause the altitude graph on the web interface when you see two peaks. Find the time difference between these two peaks and record this value as \(T_u\), the ultimate period.
Use your \(K_u\) and \(T_u\) values to compute \(K_p\), \(K_i\), and \(K_d\). Refer to the equations in the Ziegler-Nichols section in the introduction to this project. Record these values and change z_pid.yaml accordingly.
Fly your drone with the set of tuning values generated by the Ziegler-Nichols method. Note that the Ziegler-Nichols method should enable safe flight, but will probably not control your drone’s altitude very well! Empirically tune the gain constants in z_pid.yaml on your drone as you did in the simulator portion of this project. 2 Record your final tuning values.
Footnotes#
2 Use the graph on the web interface to observe the drone’s behavior as it oscillates around the 0.3m setpoint the drone’s ability to hover at the setpoint. When observing the drone itself, try to get eye-level with the drone to just focus on the the altitude and ignore the planar motion; it is easier to focus on one axis at a time when tuning the PIDs. The planar axes can be re-tuned after you tune your altitude pid if need be.