Workflow for students.
Hardware prerequisites:
- Make sure you are connected to the network (cable inserted and check if connected to Vicon in the settings).
- Insert a CrazyRadio into one of your USB-ports on your Laptop.
- Start your crazyflie. To know which one is the one you have been linked to, ask your teacher. The Crazyflie must be started on a flat surface, as the gyrosensor needs to initialize.
Software prerequisites:
- In the software side, everything has already been set up for the course, but
it would be helpful to check if the repository is in the last version, and
if the source code has been properly compiled. To do this, follow the next steps:
- Go to the next folder:
cd ~/work/D-FaLL-System/pps_ws
- Checkout master branch of the repository and pull:
git checkout master
git pull origin master
Note: to do this step, you will be asked a username and a password. Use the same credentials you use for your ETH account. Also, make sure you have an active account in gitlab: https://gitlab.ethz.ch/
- Compile the source code running
catkin_make
- Go to the next folder:
Start the student's GUI
-
Once all the prerequisites have been fulfilled, we can start the student's GUI by going to a terminal and typing:
roslaunch d_fall_pps Student.launch
Note: for this to work, the teacher's computer has to be connected to the network and the teacher's GUI has to be started before. Please wait until your teacher has already set up everything.
-
Once started, you will see something like this:
-
Connect to/Disconnect from Crazyflie: physically connects/disconnects our computer to the assigned crazyflie using the Crazyradio dongle.
- Crazyradio status: can take the values "Connected!", "Disconnected" or
"Connecting..."
- Below the disconnect button we see two lines of text. The first one
contains information about our StudentID number, and the Crazyflie we are
linked to. This is the Crazyflie we must connect to.
Below that, we can also see the Raw voltage line, which contains the instantaneous voltage of the battery of the Crazyflie, in Volts.
- In the right part, there are 3 buttons to control the flying state of our
Crazyflie, and a text label containing the current flying state. It is
important to know that we can only take off when we are in the state "Motors
OFF", and we can only land if we are NOT in the state "Motors OFF"
- In the middle-bottom part of the GUI there are two tabs: Safe and Custom
controller.
In the left part of these tabs, there is information about the current position of the Crazyflie, and also the difference between the current position and the current setpoint, useful for keeping track of the error of our controller.
In the right part of the tabs, there is information about the current setpoint, and boxes to edit the new setpoint. When we press the button "Set setpoint", we change the current setpoint with the information filled.
- The button called "Enable Controller" enables the selected
controller. The current enabled controller is the one which is highlighted in
green in the tab name.
- The button "Load YAML file" loads and refreshes the parameters
that are in the corresponding YAML file.
- Crazyradio status: can take the values "Connected!", "Disconnected" or
"Connecting..."
-
You can now play with the landing, take off and change of setpoint using the safe controller to get familiar with the system.
Note: there are different parameters in the file called
SafeController.yaml
, in the folder param (useroscd d_fall_pps/param
in a terminal to go there). These are the safe controller parameters and should NOT be changed. Take a look at the file and get familiar with the format used, since may have to write your own for the custom controller.
Creating your own custom controller!
In this part, we will learn how to design our own custom controller and actually deploy it and see it working in our Crazyflie. For this, there are a set of important files that should be taken into account.
Files of interest:
-
In
d_fall_pps/src
-
CustomControllerService.cpp
The file where students can implement their own controller. It provides already the ros service with the teacher. It can be used as a template.
-
CustomControllerService.cpp
-
In
d_fall_pps/param
-
ClientConfig.yaml
This file needs to be changed to define names for the custom controller. The safeController property shouldn't be changed!Usage:
customController: "SERVICENAME/TOPICNAME"
where SERVICENAME is the name of the cpp-file that contains the custom controller (e.g. the provided template CustomControllerService) and where TOPICNAME is the defined name for the topic which is defined insided the controller's code.
strictSafety: <bool>
By setting strictSafety to true you limit your custom controller from assuming certain angles before the safe controller takes over. Set it to false and the safe controller only takes over when the crazyflie flies out of its defined range.
angleMargin: <float>
This value can be used to change the acceptable angles for pitch and roll. angleMargin=1 means that your crazyflie could flip 90°. The safe controller might not recover from such angles. Therefore you should use values in the range of 0.4 to 0.7.
battery_threshold_while....
Sets the low battery thresholds at which the crazyflie will automatically land. Do not change these values.
-
-
In
d_fall_pps/
-
CMakeLists.txt
This file defines all important things that are needed for build process. You need this file, if you for example choose to add a new controller with a new name. You then need to add several lines in this file. The easiest way is to search for a file that exists and just add all the same things for your new file.
-
Steps to create a custom controller
-
Open the file
CustomControllerService.cpp
and go through it. You should see that the file is already filled with some code. This code is a simple LQR controller that is offered as a template for the student to start developing their own controller. Change the file as you wish with your own controller algorithm. The function partially shown below is the most important part of our this file:
In the template you can also see an example of how to use the
CustomController.yaml
to load parameters that you may want to change without having to compile or restart the system. Here, as an example, we pass some parameters that can be seen below:
-
Go to
cd ~/work/D-FaLL-System/pps_ws
and writecatkin_make
. -
Once everything has compiled without errors, run the next launch file:
roslaunch d_fall_pps Student.launch
. This will run the student's GUI. -
Make sure that your Crazyflie is turned ON and connect to it. Choose the tab called Custom Controller and click on the button Enable Custom Controller
-
Press the Take Off button and you should see your crazyflie taking OFF.
Note: for take off and landing, the crazyflie uses the safe controller. Once we finish taking off, if the custom controller was enabled, we automatically switch to it
-
If everything went correctly, now your Crazyflie is using your own controller!
Note: if your controller is unstable, or it does not compute a valid output, your crazyflie will start moving in a wrong way. Please be careful and take care, since the crazyflie can unexpectedly go and hit the ceiling, the wall, or other student. If your crazyflie goes out of the assigned zone, or if the pitch or roll go out of the safety margin (when strict safety is enabled), the safe controller will be automatically enabled to try to recover the crazyflie and bring it to the center of your zone.
-
If you decided to put some parameter in the
CustomController.yaml
file, you can now change it and press the Load CustomController YAML file button in the GUI. This way, you can try and see the effect of changing some parameters on the fly.