4. Software setup
Note: Throughout this document, components will be numbered corresponding to the order list. This is to help you identify the component or part that you are working with.
4.1. QGroundControl setup
QGroundControl is a program that provides flight control and mission planning for any MAVLink enabled drone. It provides configuration for ArduPilot andPX4 Propowered vehicles. QGroundControl is very easy to use.
4.1.1 Install Qgroundcontrol
Install QGroundControl for your operating system. This software is not to be installed on the on-board computer (Raspberry Pi B+) but rather a main computer. It would be prefered that your main computer was running Windows 10as the RCBenchmark Tracking lab software is only available for Windows 10.
4.1.2 Update PixHawk Firmware
We are currently using EKF2 for position estimation. Please flash the firmware to the latest version.
Note: You can check for other firmware versions here. It should not be necessary in general
4.1.3 Calibrating the Pixhawk flight controller
Note: The Pixhawk does not need to be installed to the drone frame in order to calibrate. This video may help in the calibration process.
The calibration setup of the Quadcopter will provide information to the Pixhawk so that the drone flies as expected. In the Vehicle setuppage of QGroundControl, there are tabs for Frame, Sensors, Radio, Flight Modes, Power, Safety and more. The calibration is straight forward, just follow the onscreen instructions on QGroundControl. During the calibration, the program will ask you to restart the Pixhawk multiple times.
You must have a USB connection between your computer and the Pixhawk. You will be required to disconnect and then reconnect the cable many times throughout the calibration.TIP: There is a reboot option available under the Parameters tab > Tools (top left) > Reboot vehicle.
Throughout the calibration, QGroundControl will ask you for the orientation of the flight controller (Pixhawk) relative to the front of the drone. If you followed our procedure setup, the orientation angle should be 0 degrees. Refer to the following diagram if different.
Select theGeneric 250 quad frameas seen in the following screenshot. This can differ if using a different drone frame than the one we recommended.
Complete the transmitter (Remote controller) calibration. Check that SA, SB, S1 and S2 work.
Then check the flight modes for your drone. You should have one channel assigned for toggling stabilized mode, and you should have another channel for your kill switch.
Complete the calibration for the Compass, Gyroscope, Accelerometer and Level Horizon.
188.8.131.52 Power/ ESCs
In the power tab, scroll down to ESC PWM Minimum and Maximum Calibration and follow the instructions listed.
|Battery parameters||(Varies depending on battery)|
|Number of cells (in series)||4|
|Full voltage (per cell)||3.7 V|
|Empty voltage (per cell)||3.5 V|
These parameters will differ depending on your battery.
184.108.40.206 Parameter setup for motion capture
In the Parameters tab, set the following parameters. TIP: There is a parameter 🔍 search bar available.
|MPC_THR_HOVER||35%||This should depend on your battery and quadcopter|
|CBRK_USB_CHK||197848||To enable flight when connected via USB. This is useful to test the spin of your motors (without propellers attached).|
|EKF2_AID_MASK||24||Set Vision use|
|EKF2_HGT_MODE||Vision||Vision use for height|
|EKF2_EV_NOISE||0.01||Noise level of vision estimate|
|EKF2_EV_DELAY||20ms||Delay of vision estimate|
|MIS_TAKEOFF_ ALT||1||This is a recommended take of altitude of 1m|
|MPC_TKO_SPEED||1||Recommended take off speed.|
|SYS_COMPANION||Companion link (Baud = 921600, 8N1)||Companion computer. This is critical in communicating between the pixhawk and raspberry pi. The baud rate needs to be the same on the Raspi & the pixhawk.|
You also want to change the roll sensitivity three notches to the right of the center.
4.2 Raspiberry Pi setup
4.2.1 Install Raspbian onto Raspberry Pi
- Use a PC with a SD card slot (not raspberry pi)
- Insert the microSD card (#3) and confirm the minimum specification of 16GB+ (to ensure storage space) and Class 10 (to ensure speed and reliability)
- Download and install etcher.io
- Download Raspbian image (RASPBIAN STRETCH WITH DESKTOP). Unzip. Flash the .iso to the SD card using Etcher.io.
- Insert the SD card in the Raspberry Pi, connect it to a monitor using HDMI and then power it using the provided microUSB power adapter.
Note: You will receive the following screen if the OS is not bootable which can be caused by incompatible OS but also insufficient power to the raspberry PI or faulty micro SD card.
4.3 Enable Wifi
The raspberry pi b+ comes with the wifi disable. To enable the wifi, open up the terminal and enter the following command
Under Network Options, select the N2 Wi-Fi, you will receive a prompt to enter the SSID and passphrase for the wifi. The operating system may also ask you to set your location/ timezone.
4.4 Activate SSH
SSH allow you to login to the computer remotely. This means that you can access the terminal of the Raspberry Pi from another computer on the same network (or even the internet). Enter the following codes of line into the terminal of the Raspberry Pi.
sudo apt-get update
sudo apt-get upgrade
If the unable to fetch some archives, you may have to run sudo apt-get update again before trying again to run apt-get upgrade. This may have to be repeated a couple times before a successful upgrade.
Enable ssh by entering the command
then enable SSH under interfacing options.
Also deactivate serial login shell and activate hardware serial interface, under underinterface options.The hardware serial is used later for communicating with the Pixhawk.
4.5 Installing necessary scripts/ software
4.5.1 RCBenchmark tracking software
Your virtual environment is now activated. Every package you install will only be available if execute the activate script with the command source activate. If you use a python development environment, you may be able to specify which virtualenv you are using.
Download the scripts to receive the position information from the RCbenchmark Tracking Lab.
git checkout development
If you install the scripts a while ago, there may be update. To download the most recent version, go the the Transport_Protocol folder in command line and type:
At this point, it is a good idea to learn how dronekit works. Check out their documentation. With Dronekit, you will be able to retrieve information from the Pixhawk autopilot such as
Attitude (Yaw, Pitch, Roll)
Autopilot software version and more….
sudo pip install dronekit
Install pyserial for serial communication
sudo pip install pyserial
Install Dronekit-sitl (Software in the loop) aka simulation
sudo pip install dronekit-sitl
Install screen, a terminal multiplexer
sudo apt-get install screen
Additional dependencies that Dronekit may require
sudo apt-get install python-pip python-dev python-numpy python-opencv python-serial python-pyparsing python-wxgtk2.8
Download Dronekit examples from
Depending on the connection between the Pixhawk flight controller and the Raspberry Pi, we will need to edit the connection string in the example codes. Set the connection string to the following depending on the connection type. If you have already made the serial connection (section 3.5) than use the serial port connection string.
|Connection type||Connection string|
|Linux computer connected to the vehicle via USB||/dev/ttyUSB0|
|Linux Raspberry pi computer connected to the vehicle via USB||/dev/ttyACM0|
|Linux computer connected to the vehicle via Serial port (Raspberry Pi example)||/dev/ttyS0 (also setbaud=921600)|
|SITL connected to the vehicle via UDP||127.0.0.1:14550|
|SITL connected to the vehicle via TCP||tcp:127.0.0.1:5760|
|OSX computer connected to the vehicle via USB||dev/cu.usbmodem1|
|Windows computer connected to the vehicle via USB (in this case on COM14)||com14|
|Windows computer connected to the vehicle using a 3DR Telemetry Radio on COM14||com14 (also setbaud=57600)|
For our serial connection, we will use the following line of code for the connection
vehicle = connect(‘/dev/ttyS0’, baud = 921600, wait_ready = None)
Otherwise, for a USB connection, use
vehicle = connect(‘/dev/ttyACM0’, baud = 921600, wait_ready = None)
Lets test out the connection, save the following file as test.py. To run the test.py example code, while in the directory of the code, type the following line of code into the terminal.
sudo python test.py
You should see similar results if successful.
Now we want to allow the drone to communicate with QGroundControl software on the ground station. MAVProxy will be used to forward traffic. Install Mavproxy following these instructions for installation on a Debian based system. If the build wheel for the Mavproxy installation fails, run
sudo apt-get install libxml2-dev libxslt-dev
then try again, for in order to install some C-based dependencies on your Raspberry Pi.
Launch Mavproxy in on the Raspberry Pi, with the following commands, based on how your Pixhawk is connected to your Raspberry Pi.
For USB connection, use the command
mavproxy.py --master=/dev/ttyACM0 --out=udpbcast:192.168.1.255:14550
For serial connection, use the command
mavproxy.py --master=/dev/ttyS0 --out=udpbcast:192.168.1.255:14550 --baudrate=921600
then launch QgroundControl. In the Comm link section, click Add and choose UDP.
Now, in order to auto-launch the scripts in terminal on boot, you need to create a shell executable file.
If you want to automate the launch of the script at startup, create a filelaunch_mavlink.shon the desktop with the lines:
screen -r -m -L ~/Desktop/mavproxy.log mavproxy --master=/dev/ttyS0 --out=udpbcast:192.168.1.255:14550 --baudrate=921600
save the file as launch_mavlink.sh
To make them executable, run the following command at Desktop (since both the files reside at the desktop)
sudo chmod +x launch_mavlink.sh
Now that both the file is executable, you need to go to a folder called autostart. To do that enter the following commands.
This will take you to the autostart folder, you need to create a .desktop file so that the script runs in a terminal on launch. Create a file using the following commands:
sudo nano mavproxy.desktop
This should open up the nano editor, please enter the below displayed script.
Exec=lxterminal -e ~/Desktop/launch_mavlink.sh
Save the file by pressing Ctl+X, then press Y and Enter. Now, reboot the Pi to ensure that the script auto-launches on boot.
- You should now see mavproxy running (and position forward too, if you are using the Otus Tracker). Check QGroundControl on your ground station. A link to your vehicle should have been established, similar to the one through USB.
4.6 Prepare to stream position information to the Quadcopter
- Check that the Raspberry Pi and the computer with the RCbenchmark Tracking Lab are on the same network
- Launch the RCbenchmark Tracking Lab. Verify that the Otus is tracking.
- Go in the Server tab. Type in the address of the Raspberry Pi (this can be found by inputting hostname -I in the terminal of the Raspberry Pi). The default port is 5400. However, you may have to set this port to 5401, as port 5400 on the Raspberry Pi may be occupied with the MAVproxy link
- Launch the server from the RCbenchmark Tracking lab.
4.7 Check that the position information is forwarded from the drone to the PX4
The next step is to forward the position from the Raspberry Pi to the PX4. To do this, you need to launch the script:
In this script, you may have to change the address to which the position is sent. In the script, find the line:
vehicle = connect('/dev/ttyS0', wait_ready=True)
where ttyS0 is the serial port and ttyACM0 would be the USB port. Note that you may experience link timeouts when using these ports while mavproxy is running- this is because the connection is already in use by mavproxy, and you should instead connect to mavproxy instead of the pixhawk directly. 127.0.0.1:14551 is the localhost loopback address. Setwait_ready = None if you are experiencing issues with establishing a link.
Once you are connected with the Serial port and you launched the script RCB_mavlink_forward_USB.py, you can check that the position is correctly received with Qgroundcontrol. Check the axis orientation.
If you are having trouble connecting to the correct IP, instead try launching the script RCB_pose_forward.py. Then, in the RCBenchmark Tracking Lab, you can set the IP to192.168.1.255, as you will not need to send the datagram to a specific computer.
With mavproxy active in a separate terminal, you should see the altitude information in QGroundControl corresponding to the altitude of the vehicle.
4.7.1 Auto-launching position forwarding script
If you are using the Otus Tracker for motion capture, please create the a file called launch_poseforward.sh on the desktop with the following contents. (If you do not have an Otus Tracker, skip the part which deals with position forward)
screen -L ~/Desktop/pose.log ~/TransportProtocol/UDP/Python/RCB_pose_forward.py
The above created file runs the script again incase the script is exited due to a connection timeout or any other error. This ensures that the on-board computer is always running position forwarding script.
Give the file execute permissions by entering the following command. Assuming that your working directory is currently Desktop.
sudo chmod +x launch_poseforward.sh
In order to run this auto-launch the script on boot, create another .desktop file in autostart folder as you have done for the mavproxy.sh with a new name and enter the appropriate location of the file under the Exec declaration.
4.8 Programing the LCD Display
Once the OLED/LCD display is connected to the Raspberry Pi, you need to do the following to ensure that the serial ports are open for connecting with the screen automatically
- Connect the Raspberry Pi to a monitor and keyboard.
- Open a terminal and type the following
Use the down arrows and navigate to Interfacing Options then press enter. Navigate to P5 I2C, hit enter.
Enable I2C and when given an option to reboot, hit yes.
After the system boots up, run the following command to check if the i2c interface is enabled.
This should return /dev/i2c-1 which represents that the interface is activated.
Now, you need to install the following package to Linux
sudo apt-get install -y i2c-tools
Now, we need to check the address of the device on the address bus, this can be returned by a method of the i2c-tools package installed. Enter the following command
i2cdetect -y 1
This give the following output, as depicted in the image below. Take a note of the address.
We are currently using luma.oled, luma.core packages and Pillow packages to communicate with the LCD/OLED display. You can clone the repository from here and install setup,py to automatically install all the necessary packages and dependencies.
- Or you can directly install these packages using the python package installer (pip) by entering the following commands:
pip install luma.core
pip install luma.oled
pip install Pillow
After you have installed all the necessary packages, make sure that you have the latest version of the RCbenchmarks repository.
git clone https:https://gitlab.com/TytoRobotics/Transport_Protocol.git
git checkout Transport___Protocol-V2
This branch has the LCD.py script which is used to display error messages on the OLED/LCD display.
In case you do not have git install, you could just download the zip file and extract the contents.
To launch the script on launch, please create a .desktop file as you have created for mavproxy and position forwarding scripts in the steps above.
Now, the Raspberry Pi is equipped and linked with the screen to display error messages and user defined texts.
4.8.1 Displaying your message on the LCD screen
Currently the luma.oled library recreates the whole screen in order to display. To display your message on the screen please follow the steps below:
- Connect the Pi to a monitor,keyboard and mouse. Click on the file LCD on the desktop. OR
SSH to your Raspberry pi and enter the following commands.
cd path to the LCD folder from cloned from Transport_protocol.git
sudo nano LCD.py
Open the file LCD.py using any editor and go to line 38.
Notice that the draw.text method has been commented in code using '#' symbol.
Remove the '#' symbol and enter your message between the parentheses.
Save the program and exit. ( if you have SSHed your way into the program then, press ctl + X and then press Y to save and exit)
Reboot the pi, your message should be displayed on the LCD/OLED screen.
The LCD screen program uses simple logic for easy manipulation and flexibility. Feel free to make changes to the code according to your requirements to make use of the screen.
4.8.2 Deleting the old log files on launch
Since the LCD.py reads the log files for real time error reporting, it is necessary to delete the old files for the next consecutive launch.
For automating the delete operation of these files, please follow the following steps.
- Connect the Raspberry Pi to a monitor,keyboard and a mouse.
- Open LXterminal by pressing Cntl + Alt + T and type the following:
Once in etc folder edit the rc.local file by typing the following command:
sudo nano rc.local
rc.local is one of the programs which is run on boot up, this ensures that the old log files are deleted before the start of the position forwarding scripts.
Now, add the following 2 lines just before exit 0 in the file.
sudo rm /home/pi/Desktop/mavproxy.log &
sudo rm /home/pi/Desktop/pose.log &
Press Cntl + X, then Y to save and exit.
Now the Raspberry Pi is configured to delete the old logs on boot.
4.9 Steam, RCBenchmark Tracking lab + Otus tracker
Begin by installing the RCBenchmark Tracking Lab software for your main computer running Windows 10. Follow these instructions.
4.10 Backup the SD card
MicroSD cards have a tendency to become corrupt. You can create a image of the microSD card so you can restore a new sd card to the same state. Follow the procedure here. The (.img) should be around 14 - 16 GB in size.