Modified 2020-11-04 by Sean Hastings
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.
Modified 2022-10-18 by Stefanie Tellex
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 positio control for the height, so it adjusts the throttle to maintain a target height above the ground using an altitude sensor.
Modified 2022-10-18 by Stefanie Tellex
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.
Modified 2022-10-18 by Stefanie Tellex
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.
Modified 2022-11-02 by Stefanie Tellex
Follow the instructions in the operations manual in order to fly here.
Make sure this works before trying to tune your own PID.
Modified 2022-11-02 by Stefanie Tellex
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 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 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.
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.