Uav Raspberry Pi Tutorial Without Videos
Uav Raspberry Pi Tutorial Without Videos
Uav Raspberry Pi Tutorial Without Videos
6
Communication and Control
March 3, 2015
Outline
1. Introduction
2. Basic Knowledge
3. Establishing Connection between RPi and APM
4. Setting up ROS on RPi
5. Using ROS for APM Communication
6. Writing your own Programs
7. Performing Tests
8. Troubleshooting Tips
1. Introduction
This tutorial aims to teach the following:
Connection of the APM 2.6 to the Raspberry Pi through UART0.
Using ROS (Robot Operating System) to communicate with the APM.
Creating and running programs with ROS to control the APM.
Emphasis will be put on sections where other tutorials are not available.
Forewarning
The methods explained in this tutorial are only one of many ways
to achieve the same results.
Programming will always lead to new errors and problems, so time
and patience will be required.
Achieving the final result of this tutorial will most likely take longer
than a week, or possibly a month, if you are new to programming.
Most things on this tutorial was found through Google.
My Methods
My methods were done in the following conditions:
Raspberry Pi Model B+ with a 32 GB microSD card running Raspbian
APM 2.6 with ArduCopter v3.2.1
ROS Indigo installed from source
Most communication with the Raspberry Pi was done through SSH
by an Ethernet Cable from a Laptop running Windows 7 using PuTTy.
2. Basic Knowledge
Programming Tip:
Dont skip the tutorials.
Understanding the concepts will help you solve errors, so
properly go through tutorials without relying on copyand-paste.
Here are things you should know for this tutorial:
Raspberry Pi
Learn the basics of the Raspberry Pi and get it set-up
with Raspbian.
http://www.raspberrypi.org/help/quick-start-guide/
Understand how to use the command line (Unix Shell)
on the Raspberry Pi to manipulate and navigate through
the system.
Dont rely on a Desktop, since going
through it with the Shell will help you understand the
code more and make you a better programmer.
http://linuxcommand.org/lc3_learning_the_shell.php
Programming
Be able to understand both basic Python and C++. Most
programs written for Linux based systems (like the Raspberry Pi)
will run on either Python or C++. Python will be needed to read
those programs, and C++ will be used for the programs we write.
http://www.learnpython.org/
http://www.cplusplus.com/doc/tutorial/
You will also need to learn how to use a text editor in the
command window on the Raspberry Pi. There are many choices.
(I use Vim.)
Type vimtutor into the Linux Command Terminal.
APM 2.6
You should already be able to manually fly your UAV
with the APM. I used Mission Planner for all of my APM
tuning. All information related to the APM can be found
through the wiki.
http://copter.ardupilot.com/
You should also understand a little of how the APM 2.6
code works and how it communicates with the ground
station using MAVLink, which we will be using as the
main means of communicating between the Raspberry
Pi and APM.
http://qgroundcontrol.org/mavlink/start
3. Establishing Connection
This tutorial was used in order to connect the Raspberry Pi with the APM.
http
://dev.ardupilot.com/wiki/companion-computers/raspberry-pi-via-mavlink/
The tutorial shows a Pixhawk, but the same can be done with the APM 2.6
by using the open Telemetry Port shown on its top. (Next slide)
The Raspberry Pi pins can be found in more detail here:
http://elinux.org/RPi_Low-level_peripherals
Telemetry
Port
3. Establishing Connection
In a simpler explanation, connect it this way:
APM 2.6
Raspberry Pi
Open
Open
3. Establishing Connection
Important Note:
The Telemetry Port (UART0) on the APM and the USB Port uses the
same serial port for connection, so there is a MUX (Multiplexer) that
disables the Telemetry Port if the USB is connected. So,
you need a battery/power supply to power the APM without
using a USB cable in order to use the UART0 Port and
connect to the Raspberry Pi.
Once you are connected, follow through the rest of the tutorial in
order to check the connection using MAVProxy. You should see a
connection.
[Extra note: We will replace this program with mavros later on.]
Other Alternatives
Using the Telemetry Port (UART0) makes the APM lose the
ability to send signals back to the Ground Station during
flight with a transmitter. However, it is still able to receive
signals from a RC transmitter.
If you would like to keep the Telemetry Port to connect to
a Ground Station during flight, then you might want to try
connecting using the UART2 Port on the APM (which may
require soldering). I have not done this myself and more
information can be found by looking on the DIYDrones
Forum: http://
source /home/pi/catkin_ws/devel/setup.bash
I automatically source all of my workspaces on start-up by adding it to the end of my .bashrc file.
This command publishes the given message {channels: [ 0, 0, 1800, 0, 0, 0, 0, 0]} that is of
message type mavros/OverrideRCIn into the topic mavros/rc/override and latches -l the
message so that it stays.
This causes all channels to be controller by the RC transmitter, but overrides
the third channel Throttle and sets it to a value of 1800. This should make
the UAV motors spin faster (if its armed). Disarm to stop the motors.
You can see which channels correlate to which radio signal from the RC by
reading the topic mavros/rc/in and connecting an RC transmitter to the APM.
Playing around with the joysticks should change the values of channel
accordingly.
It is important that you understand how publishing messages and subscribing
to topics work before creating your own program.
This is an example of a
Callback.
7. Performing Tests
Always perform tests without propellers first for safety.
After you compile your code in your workspace
(following tutorial), you should be able to execute it
through rosrun.
It will be helpful to use ROS_INFO functions to be able to
see the status of the program through the command
window.
7. Performing Tests
In order to test the program with propellers and in flight, you will
have to make your program start without using the command line.
This can be done through an external button on the Raspberry Pi,
or by having your program start running automatically on boot-up.
To make it start on boot-up, follow these directions:
http://
www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start
-up.html
MAKE SURE YOUR SCRIPT ENDS PROPERLY. You may make your
Raspberry Pi unbootable (break) if you do not.
[Now would be a good time to backup all of your files and
data.]
7. Performing Tests
This is what my script looks like.
You will first need to source your ROS files.
Then make sure to add your bin files into your path
file. (This is because of errors with PIP)
Then you will need to have a start) and stop) functions
for your boot-up program.
The & is for running the program in the background,
allowing the script to END. (really important!)
sleep 30(ms) gives the program time to finish.
aero_test is the name of my program.
7. Performing Tests
A good way to test if your program is booting properly is
to check through an external monitor (no SSH). This will
show you if the program ends, and how long it take for
it to boot.
If it takes too long to boot because it is looking for a
network, comment out the ip addresses in
/boot/cmdline.txt .
(This means you cant SSH anymore)
Add this pound symbol here
to uncomment the ip
addresses.
7. Performing Tests
If everything was done correctly with no problems, you should be
able to fly your UAV autonomously with a simple program.
It takes 2 Minutes from turning on my Raspberry Pi for my
program to start running.
Make sure that your program does not do anything dangerous,
and always make sure that your program can be terminated using
the RC Transmitter at any time for safety.
Autonomous Flight is dangerous, so please be safe!
The Raspberry Pi only copies what a RC Transmitter can do. So
properly tune your UAV before flight for better results.
8. Troubleshooting Tips
If you get an error message, copy and paste the error
message into google. You might find a solution.
If your code does not compile, keep fixing it until it does.
Do small checks using comments.
Programming is not hard, it just takes a long time. Keep
googling and looking for a solution. Have patience.
If you have problems with ROS, look at the ROS wiki page.
If you have problems with the Raspberry Pi, google the
problem. Hundreds of people on earth use the RPi, so
someone should be able to find a solution.
End
If you have any questions,
you may contact me at
austinpuk@gmail.com
I am not a professional, but I will try my best to help.
March 3, 2015