Communicating With Raspberry Pi Via MAVLink
Communicating With Raspberry Pi Via MAVLink
Communicating With Raspberry Pi Via MAVLink
net/publication/323683430
CITATIONS READS
0 7,199
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Saif Aldeen Saad Alkadhim on 10 March 2018.
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.
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).
Connect to the Pixhawk with a ground station (i.e. Mission Planner) and set the following
parameters:
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 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
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.
Figure 3 Determine the Raspberry Pi IP address
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
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.
sudo apt-get update #Update the list of packages in the software center
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.
Type:
sudo raspi-config
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
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
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:
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
export PATH
cd /home/pi
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.
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:
Then open the MAVProxy terminal in the location where your DroneKit script is located and
start an example:
MANUAL> api start vehicle_state.py
If you get a warning that droneapi module has not loaded, you can do so manually in
MAVProxy:
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: