0% found this document useful (0 votes)
145 views12 pages

Communicating With Raspberry Pi Via Mavlink

This document provides instructions for connecting a Raspberry Pi to a Pixhawk flight controller using MAVLink to enable additional tasks like image recognition. It describes connecting the devices, setting up the Raspberry Pi with an APSync image, configuring the Pixhawk's serial ports, connecting to the Raspberry Pi remotely, installing required software packages, disabling the serial port's OS control, testing the connection, and configuring MAVProxy to run on startup to log telemetry data and parameters from the Pixhawk.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views12 pages

Communicating With Raspberry Pi Via Mavlink

This document provides instructions for connecting a Raspberry Pi to a Pixhawk flight controller using MAVLink to enable additional tasks like image recognition. It describes connecting the devices, setting up the Raspberry Pi with an APSync image, configuring the Pixhawk's serial ports, connecting to the Raspberry Pi remotely, installing required software packages, disabling the serial port's OS control, testing the connection, and configuring MAVProxy to run on startup to log telemetry data and parameters from the Pixhawk.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Communicating with Raspberry Pi via MAVLink

Saif Aldeen Saad Obayes Al-Kadhim


MIEEE
Saifaldeen.Saad@ieee.org
saifalseedi@gmail.com

Abstract
This paper explains how to connect and configure a Raspberry Pi so that it is able to
communicate with a Pixhawk flight controller using the MAVLink protocol over a serial
connection. This can be used to perform additional tasks such as image recognition which
simply cannot be done by the Pixhawk due to the memory requirements for storing images.

Key Words: Raspberry Pi, flight controller, MAVLink, Pixhawk.

1. Connecting the Pixhawk and Raspberry Pi


Connect the Pixhawk’s TELEM2 port to the Raspberry Pi Ground, TX and RX pins as shown
in the image above. More details on the individual Raspberry Pi pin functions can be
found here. The Raspberry Pi can be powered by connecting the red V+ cable to the +5V pin
(as shown above) or from USB in (for example, using a separate 5V BEC hooked up to the
USB power). Powering via USB is recommended as it is typically safer - because the input is
regulated. If powering via USB, do not also connect the +5V pin as shown (still connect
common ground).

Figure 1 Connecting Pixhawak with Raspberry Pi

Electronic copy available at: https://ssrn.com/abstract=3318130


1.1 Setup the Raspberry Pi

The easiest way to setup the Raspberry Pi is to flash one of the existing :ref:`APSync <apsync-
intro>` images:

1. purchase a formatted 8GB or 16GB SD card (16GB is better because some 8GB cards
will not be quite large enough to fit the image) and insert into your laptop/desktop
computer's SD card slot
2. download the latest image from firmware.ardupilot.org. Look for the file starting with
"apsync-Raspberry Pi".
3. extract the image. On Windows you may use 7-zip.
4. For Windows download and install Win32DiskImager and follow the instructions
here.
5. For Linux follow these instructions.
6. For Mac follow these instructions.

When extracting the contents of the compressed file on Mac you may get into an infinite loop
of extraction (.xz to .cpgz and vice versa) using the default Archiver. In order to correctly
extract the .img file you will need to use the Unarchive (http://unarchiver.c3.cx/unarchiver).

1.2 Setting up the Pixhawk

Connect to the Pixhawk with a ground station (i.e. Mission Planner) and set the following
parameters:

1. :ref:`SERIAL2_PROTOCOL <copter:SERIAL2_PROTOCOL>` = 1 (the default) to


enable MAVLink on the serial port.
2. :ref:`SERIAL2_BAUD <copter:SERIAL2_BAUD>` = 921 so the Pixhawk can
communicate with the Raspberry Pi at 921600 baud.
3. :ref:`LOG_BACKEND_TYPE <copter:LOG_BACKEND_TYPE>` = 3 if you are
using APSync to stream the dataflash log files to the Raspberry Pi.

1.3 Connecting to Raspberry Pi with an SSH/Telnet client

These steps assume that you have set-up your Raspberry Pi so that it is running Raspbian.
These instructions are not required if you are using APSync as described above.To avoid the
requirement to plug a keyboard, mouse and HDMI screen into your Raspberry Pi it is
convenient to be able to connect from your Desktop/Laptop computer to your Raspberry Pi
using an SSH/Telnet client such as PuTTY.

1. Connect the Raspberry Pi to your local network by one of the following methods:

o Connecting an Ethernet LAN cable from the Raspberry Pi board to your


Ethernet router, or

Electronic copy available at: https://ssrn.com/abstract=3318130


o Use a USB dongle to connect your Raspberry Pi to the local wireless network,
or

o Connect the Ethernet LAN cable between the Raspberry Pi and your
desktop/laptop computer. Open the control panel's Network and Sharing
Center, click on the network connection through which your desktop/laptop is
connected to the internet, select properties and then in the sharing tab, select
"Allow other networks to connect through this computer's Internet connection"

Figure 2 Connect the Ethernet LAN cable between the Raspberry Pi and desktop or laptop computer

2. Determine the Raspberry Pi IP address:

o If you have access to the Raspberry Pi terminal screen (i.e.you have a screen,
keyboard, mouse connected) you can use the /sbin/ifconfig command.
o If your Ethernet router has a web interface it may show you the IP address of
all connected devices.

Electronic copy available at: https://ssrn.com/abstract=3318130


Figure 3 Determine the Raspberry Pi IP address

3. Connect with Putty:

If all goes well you should be presented with the regular login prompt to which you
can enter the username/password which defaults to pi/raspberry

Figure 4 Putty software configurations.

Electronic copy available at: https://ssrn.com/abstract=3318130


1.4 Install the required packages on the Raspberry Pi

Log into the Raspberry Pi board (default username password is pi/raspberry) and check that its
connection to the internet is working:

ping google.com

OR

ping 173.194.126.196

If the first fails but the second succeeds, then there is a problem with the DNS server that your
Raspberry Pi is attempting to use. Please edit the /etc/resolv.conf file and add the IP address of
a nearby DNS server. During the creation of this wiki, the first two parts of the desktop
machine's IP address plus ".1.1" worked. To stop other processes from later updating this file
you may wish to run the chattr +i /etc/resolv.conf command (this can be undone later with
chattr -i /etc/resolv.conf). That sets the "immutable" bit on resolv.conf to prevent other
software from updating it.

After the internet connection is confirmed to be working install these packages:

sudo apt-get update #Update the list of packages in the software center

sudo apt-get install screen python-wxgtk2.8 python-matplotlib python-opencv python-pip python-numpy


python-dev libxml2-dev libxslt-dev

sudo pip install future

sudo pip install pymavlink

sudo pip install mavproxy

The packages are :ref:`mostly the same as when setting up SITL <setting-up-sitl-on-
windows>`. Reply Reply 'y' when prompted re additional disk space.

1.5 Disable the OS control of the serial port

Use the Raspberry Pi configuration utility for this.

Type:
sudo raspi-config

And in the utility, select "Advanced Options":

RasPiConfiguration Utility: Serial Settings: Advanced Options

And then "Serial" to disable OS use of the serial connection:

Reboot the Raspberry Pi when you are done.

Electronic copy available at: https://ssrn.com/abstract=3318130


Figure 5 Raspberry Pi configuration utility

2. Testing the connection

To test the Raspberry Pi and Pixhawk are able to communicate with each other first ensure the
Raspberry Pi and Pixhawk are powered, then in a console on the Raspberry Pi type:

sudo -s

mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --aircraft MyCopter

On newer versions of Raspberry Pi 3 the uart serial connection may be disable by default. In
order to enable serial connection on the Raspberry Pi edit /boot/config.txt and set
enable_uart=1. the build-in serial port is /dev/ttyS0.
Once MAVProxy has started you should be able to type in the following command to display
the ARMING_CHECK parameters value
param show ARMING_CHECK

param set ARMING_CHECK 0

arm throttle

If you get an error about not being able to find log files or if this example otherwise doesn't run
properly, make sure that you haven't accidentally assigned these files to another username, such
as Root.

Entering the following at the Linux command line will ensure that all files belong to the
standard Pi login account:

sudo chown -R pi /home/pi

Electronic copy available at: https://ssrn.com/abstract=3318130


Figure 6 Testing the connection

3. Configure MAVProxy to always run

To setup MAVProxy to start whenever the Raspberry Pi is restarted open a terminal window
and edit the /etc/rc.local file, adding the following lines just before the final "exit 0" line:

date

echo $PATH

PATH=$PATH:/bin:/sbin:/usr/bin:/usr/local/bin

Electronic copy available at: https://ssrn.com/abstract=3318130


export PATH

cd /home/pi

screen -d -m -s /bin/bash mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --aircraft


MyCopter

) > /tmp/rc.log 2>&1

exit 0

Whenever the Raspberry Pi connects to the Pixhawk, three files will be created in the
/home/pi/MyCopter/logs/YYYY-MM-DD directory:

 mav.parm : a text file with all the parameter values from the Pixhawk
 flight.tlog : a telemetry log including the vehicles altitude, attitude, etc which can be
opened using the mission planner (and a number of other tools)
 flight.tlog.raw : all the data in the .tlog mentioned above plus any other serial data
received from the Pixhawk which might include non-MAVLink formatted messages
like startup strings or debug output

If you wish to connect to the MAVProxy application that has been automatically started you
can log into the Raspberry Pi and type:

sudo screen -x

To learn more about using MAVProxy please read the MAVProxy documentation.

It is also worth noting that MAVProxy can do a lot more than just provide access to your
Pixhawk. By writing python extension modules for MAVProxy you can add sophisticated
autonomous behaviour to your vehicle. A MAVProxy module has access to all of the sensor
information that your Pixhawk has, and can control all aspects of the flight. To get started with
MAVProxy modules please have a look at the existing modules in the MAVProxy source code.

4. Installing DroneKit on Raspberry Pi

The most up-to-date instructions for Installing DroneKit on Linux are in the DroneKit-Python
documentation. This information is a summary, and might go out of date.

To install DroneKit-Python dependencies (most of which will already be present from when
you installed MAVProxy) and set DroneKit to load when MAVProxy starts:

sudo apt-get install python-pip python-dev python-numpy python-opencv python-serial


python-pyparsing python-wxgtk2.8 libxml2-dev libxslt-dev

sudo pip install droneapi

echo "module load droneapi.module.api" >> ~/.mavinit.scr

Then open the MAVProxy terminal in the location where your DroneKit script is located and
start an example:

Electronic copy available at: https://ssrn.com/abstract=3318130


MANUAL> api start vehicle_state.py

If you get a warning that droneapi module has not loaded, you can do so manually in
MAVProxy:

MANUAL> module load droneapi.module.api

5. Connecting with the Mission Planner

The Pixhawk will respond to MAVLink commands received through Telemetry 1 and
Telemetry 2 ports (see image at top of this page) meaning that both the Raspberry Pi and the
regular ground station (i.e. Mission planner, etc) can be connected. In addition it is possible to
connect the Mission Planner to the MAVProxy application running on the Raspberry
Pi :ref:`similar to how it is done for SITL <setting-up-sitl-on-
windows_connecting_with_the_mission_planner>`.

Primarily this means adding an --out <ipaddress>:14550 to the MAVProxy startup command
with the being the address of the PC running the mission planner. On windows the ipconfig can
be used to determine that IP address. On the computer used to write this wiki page the
MAVProxy command became:

mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --out 192.168.137.1:14550 --aircraft


MyCopter

Connecting with the mission planner is shown below:

Figure 7 the mission planner dashboard

Electronic copy available at: https://ssrn.com/abstract=3318130


References:
1. Saif Aldeen Saad Obayes Al-Kadhim, and et al., Prototype Wireless Controller System
based on Raspberry Pi and Arduino for Engraving Machine, UKSim-AMSS 19th
International Conference on Modelling & Simulation, DOI: 10.1109/UKSim.2017.20.
2. Saif Aldeen Saad Obayes Al-Kadhim, Industrial Workshop Based on Internet of
Things: Automated Manufacturing Systems Technology, Noor Publishing (August 1,
2017), ISBN-10: 3330965754, ISBN-13: 978-3330965751.
3. Saif Aldeen Saad Obayes Al-Kadhim, and et al., CNC Machine Based on Embedded
Wireless and Internet of Things for Workshop Development Article in IJCDS Journal
Volume 6(Issue 4):205 · July 2017, DOI: 10.12785/ijcds/060406.

View publication stats Electronic copy available at: https://ssrn.com/abstract=3318130


Saif Aldeen Saad Obayes Alkadhim
M.Sc. Electromechanical Engineering
(e-mail: Saifaldeen.Saad@ieee.org).
Saif Aldeen Saad Obayes: Born in Babylon (1984). earned his BSc in Electrical
Engineering from Babylon University (2006), Higher Diploma in Power System technology
from College of Electrical and Electronic Technology (2010), MSc degrees in
ElectroMechanical System Engineering from University of Technology (2016), Baghdad,
Iraq.
More than 8 years’ experiences in ElectroMechanical systems. Interested in Internet of
Things, CAD/CAM system, Industry Management and E-governments.
Senior researcher. Participated in IEEE ROBOTICS AND AUTOMATION SOCIETY, IEEE
Industrial Electronics Society, IEEE YOUNG PROFESSIONALS, IEEE Biometrics Council, IEEE
Nanotechnology Council, IEEE Sensors Council and IEEE Systems Council.

1. Saif Aldeen Saad Obayes Al-Kadhim, and et al., Prototype Wireless Controller System
based on Raspberry Pi and Arduino for Engraving Machine, UKSim-AMSS 19th
International Conference on Modelling & Simulation, DOI: 10.1109/UKSim.2017.20.
2. Saif Aldeen Saad Obayes Al-Kadhim, Industrial Workshop Based on Internet of
Things : Automated Manufacturing Systems Technology, Noor Publishing (August 1,
2017), ISBN-10: 3330965754, ISBN-13: 978-3330965751.
3. Saif Aldeen Saad Obayes Al-Kadhim, and et al., CNC Machine Based on Embedded
Wireless and Internet of Things for Workshop Development Article in IJCDS Journal
Volume 6(Issue 4):205 · July 2017, DOI: 10.12785/ijcds/060406.
4. Al-Saedi, Ibtesam RK, Farag Mahel Mohammed, and Saif Aldeen Saad Obayes. "CNC Machine
Based on Embedded Wireless and Internet of Things for Workshop Development." International
Journal of Computing and Digital Systems 6.4 (2017): 205-213.

5. I. R. K. Al-Saedi, F. M. Mohammed and Saif Aldeen Saad Obayes Al-Kadhim, "CNC machine
based on embedded wireless and Internet of Things for workshop development," 2017
International Conference on Control, Automation and Diagnosis (ICCAD), Hammamet,
2017, pp. 439-444.
doi:10.1109/CADIAG.2017.8075699.
6. Saif Aldeen Saad Obayes Al-Kadhim, I. R. K. Al-Saedi and F. M. Mohammed, "Prototype
Wireless Controller System Based on Raspberry Pi and Arduino for Engraving
Machine," 2017 UKSim-AMSS 19th International Conference on Computer Modelling &
Simulation (UKSim), Cambridge, 2017, pp. 69-74. doi: 10.1109/UKSim.2017.20.
7. Obayes, Saif Aldeen Saad, Ibtesam RK Al-Saedi, and Farag Mahel Mohammed. "Prototype
Wireless Controller System based on Raspberry Pi and Arduino for Engraving
Machine." Computer Modelling & Simulation (UKSim), 2017 UKSim-AMSS 19th International
Conference on. IEEE, 2017.
8. Obayes, Saif Aldeen Saad, Ibtesam R. K. Al-Saedi, and Basil Jabir Shanshool, " Microstrip
Grid Antenna Array for 5G Mobile Devices," Journal of Communications, vol. 13, no. 5,
pp. 225-229, 2018. Doi: 10.12720/jcm.13.5.225-229.
9. Obayes, Saif Aldeen Saad. Simulation of Multi-Machine Transient Stability. Diss. College
of Electrical and Electronics Techniques, Middle Technical University, 2010.
10. Obayes, Saif Aldeen Saad. Analog Speech Scrambling by Using Wavelet Transform. Diss.
University of Babylon, 2006.
11. Obayes, Saif Aldeen Saad. Application of Computer Numerical Control Machine Based
on Internet of Things System. Diss. University of Technology, 2017.
12. Obayes, Saif Aldeen Saad, Ibtesam RK Al-Saedi, and Basil Jabir Shanshool. "Microstrip Grid
Antenna Array for 5G Mobile Devices." JCM 13.5 (2018): 225-229.
13. Al-Kadhim, Saif Aldeen Saad Obayes. "CNC Machine Based on Embedded Wireless and Internet
of Things for Workshop Development."
Electronic
Electronic IJCDS
copyavailable
copy available 6.4 (2017): 205.
at:at:https://ssrn.com/abstract=3318130
https://ssrn.com/abstract=3318154
14. Obayes, Saif Aldeen Saad. "Solar Cell Parameter Extraction From Data using MATLAB and
Simulink."
15. Al-Kadhim, Saif Aldeen Saad Obayes. "Communicating with Raspberry Pi via MAVLink."
16. Obayes, Saif Aldeen Saad, Sarah Kadhim Aboud. "LIGHT SENSOR TO SWITCH ON A LIGHT
OR ANY DEVICE LDR.".Tequneical report
17. Obayes, Saif Aldeen Saad, Sarah Kadhim Aboud. (2017). LIGHT SENSOR TO SWITCH ON A
LIGHT OR ANY DEVICE LDR. Project: IoT and Smart System Retrieved from Researchgate
database. DOI:10.13140/RG.2.2.34584.49928.

10

View publication stats

View publication stats Electroniccopy


Electronic copyavailable
availableat:at:https://ssrn.com/abstract=3318130
https://ssrn.com/abstract=3318154

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy