Raspberry pi and ardupilot

3,435 views
Skip to first unread message

legoiv hck

unread,
Nov 22, 2013, 6:48:06 AM11/22/13
to drones-...@googlegroups.com
Hi, i am trying to control the arducopter with a raspberry pi, and i dont really know how to, so if any of you has get to pass data from raspberry to APM 2 i would be very thankful to get a clue on how.
thanks

Monroe King

unread,
Nov 22, 2013, 7:08:47 AM11/22/13
to drones-...@googlegroups.com
There is a RPi group at DIY Drones I'd start there. Also a secrch there will turn up lots of good starting places. Then you can ask for more specific help :)

Randy Mackay

unread,
Nov 22, 2013, 7:25:58 AM11/22/13
to drones-...@googlegroups.com

     I'd guess that you'll end up using mavlink to allow the RPi to send messages into the APM/PX4.  Tridge certainly did it for the outback challenge..he used a beagle board though I think as the upper controller.  I think he has even mentioned that at some point he wanted to build a wiki page (or at least provide the content) to make it more clear how to do this but ... he's already got a lot on his plate.

-Randy



--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


legoiv hck

unread,
Nov 22, 2013, 7:29:16 AM11/22/13
to drones-...@googlegroups.com
yes i have seen it, but i saw that it was a group of multirotors controlled by raspberry, what i am looking for is to comunicate rb with APM 2 so it is not exactly what i need

legoiv hck

unread,
Nov 22, 2013, 7:51:55 AM11/22/13
to drones-...@googlegroups.com, Randy Mackay
I can't find any documentation of what you are saying, i have searched on tridge's posts without success, can you give to me a hint ?

Chris Gough

unread,
Nov 23, 2013, 3:22:15 AM11/23/13
to drones-...@googlegroups.com, drones-...@googlegroups.com, Randy Mackay
If you want MAVProxy on the rpi doing stuff in the airframe, check out this script which simulates the MAVProxy instance in the plane:

It uses/depends on this mavinit script

https://github.com/tridge/cuav/blob/master/cuav/tests/ctest/mavinit.scr

To run that simulation, you need some pgm images and a flight log. CanberraUAV's log and images from the OBC 2012 flight log are in the public domain (see Tridge's post) but rather large. Or, just look at that script as a starting point.

Chris Gough

Michael Darling

unread,
Nov 23, 2013, 5:10:12 PM11/23/13
to drones-...@googlegroups.com
Is the Raspberry Pi on board the aircraft?  Is your question about how to set up the serial communication over the UART ports on the APM?

I am using a BeagleBone Black embedded Linux computer to do some vision processing on board an aircraft. More specifically, I am doing "leader-follower" formation flight using computer vision to localize the follower. I have the BeagleBone capturing video images, processing them to determine the relative position and orientation of the leader, then passing the state information to the ArduPilot. My custom ArduPlane software then uses that information to control the aircraft.  Since I needed to make some modifications to the ArduPlane firmware anyways, I decided to use my own message protocol for handling the serial comms.

Depending on what you are trying to do, I might be able to help you or you might be able to borrow from what I have already done. Can you provide a little bit more background on what you are trying to do?

-Mike

Phillip Smith

unread,
Nov 23, 2013, 6:09:46 PM11/23/13
to drones-...@googlegroups.com
I've flown a Raspi before, I just used a USB FTDI adapter like https://www.sparkfun.com/products/9716.  I connected it directly to the telem port on the APM and used ser2net to make the serial port into a TCP/IP port on the raspi.


--
Message has been deleted

legoiv hck

unread,
Nov 23, 2013, 7:04:59 PM11/23/13
to drones-...@googlegroups.com
Michael Darling yes the raspberry pi is onboard, i am trying to implement a depth camera to do some obstacle avoidance. I thought about using MAVLink for the comunication but i have seen that it would not be the most appropiate protocol for just passing a few variables. So would be really nice to know how did you manage the wiring between the two computers because i am not sure on how to do it.
 
Well I think that if you can help me a bit, it would be extremly useful.

And by the way, could you tell me a bit more about your project, 'cause i have been thinking on doing some things that seem to be very related to this project. 

legoiv hck

unread,
Nov 29, 2013, 6:23:10 AM11/29/13
to drones-...@googlegroups.com

Ok, I have decided to use i2c to communicate the raspberry and ardupilot, i can manage the raspberry part, but I am not sure on how to implement it on the ardupilot. 

I think that the ardupilot is already using a i2c to communicate with the gps and compass, is that right? And so, how do you think that I should do it, if I connect on the same bus I think it would be kind a tricky 'cause I don't know how should I do the wiring, or may be a better choice would be making a other bus but does the ardupilot have others tx, rx?

 I appreciate any ideas. 

Randy Mackay

unread,
Nov 30, 2013, 1:14:09 AM11/30/13
to drones-...@googlegroups.com
Legoiv,

     I2C allows connecting a large number of devices (normally sensors) to the bus.  The compass code could be used as a model to figure out how to communicate on the I2c bus for the APM or Pixhawk.  https://github.com/diydrones/ardupilot/blob/master/libraries/AP_Compass/AP_Compass_HMC5843.cpp

     The problem with using I2C is that the APM/Pixhawk would need to be the master and poll the raspberry pi for updates.  If the RPI is going to be the upper controller (i.e. making higher level decisions) then it acting as a slave (in terms of the i2c communication) might not be best.

     Both the APM2 and the PX4/Pixhawk have an extra UART besides the GPS and Telemetry UARTs that could be used.
             http://copter.ardupilot.com/wiki/common-apm25-and-26-overview/
             http://copter.ardupilot.com/wiki/common-px4fmu-overview/
     The details to do that are not documented anywhere at this point I'm afraid.

-Randy



--

legoiv hck

unread,
Nov 30, 2013, 8:33:49 AM11/30/13
to drones-...@googlegroups.com, Randy Mackay
I think you are right, i would need to create a new i2c bus, but i am not sure on how. If there is anyone that think that could give me a hand, it would be very useful, and we might be able to create a wiki page on that.

Chris Gough

unread,
Nov 30, 2013, 8:37:51 AM11/30/13
to drones-...@googlegroups.com
Remind me again, why you don't want to use serial communication (MavLink) between your companion computer and the autopilot? 

Chris Gough

Curtis Olson

unread,
Nov 30, 2013, 9:02:28 AM11/30/13
to drones-...@googlegroups.com
I wrote this a while back in response to some of the things I discovered while trying to make the APM talk to a linux computer (in my case a gumstix.)

http://gallinazo.flightgear.org/uas/ardupilot/hacking-the-apm2-part-2-fun-with-baud-rates/

There are some interesting things going on (which I hadn't ever realized before) with clock rates, dividers, and what baud rates the APM can actually do.

The arduino can do the following baud rates: 1,000,000, 500,000, 333,333, 250,000, 200,000, 166,666, 142,857, 125,000, 111,111, 100,000, 90,909, … etc.

The historical standard baud rates supported by linux are: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115,200, 230,400, etc. 

It turns out that 111,111 baud and 115,200 baud are close enough to talk pretty reliably.  But if you want to go faster, the next step up on the linux side is 230,400 baud and the 250,000 baud on the arduino side just doesn't align close enough for reliable communication.

You might think that you are telling the arduino to talk at 115,200 baud or 230,400 baud, but trace your way through the arduino baud setting code and you'll see that it is taking your request and mapping to the closest rate it can support.

For my work I did choose serial communication between the linux/gumstix computer and the APM2.  I picked 115,200 baud as the fastest baud both sides could simultaneously use (and then tried to optimize the content/efficiency of my messages.)  I rewrote the APM2 firmware to simply collect the sensor data and fire it out the serial port as fast as possible.  And then also receive control/servo commands back from the linux host.  I was able to achieve 100hz low-latency bi-directional communication with the APM2 which wasn't quite what as fast as I was hoping for, but it has proven to be quite functional.

There are many good ways to do things of course ... this is just one way that I am reporting which has worked well for my projects.

Thanks,

Curt.

legoiv hck

unread,
Nov 30, 2013, 10:17:43 AM11/30/13
to drones-...@googlegroups.com
well, i think that mavlink would be not the most appropiate protocol just for passing a few variables. And i would need to install it on the raspberry. In the other hand i2c is more efficient, and much easyer to implement on the pi. So unless that creating a other bus is a really dificult job, i guess the best option is i2c. If you have any other idea, I'll be happy to hear.

legoiv hck

unread,
Nov 30, 2013, 11:05:34 AM11/30/13
to drones-...@googlegroups.com
wow, I'm kind of lost. What i am trying to do is to get the apm receiving a few variables from the pi at a rate of about 30HZ, I am just looking at the easyer way to do it.

legoiv hck

unread,
Nov 30, 2013, 2:17:39 PM11/30/13
to drones-...@googlegroups.com
check out the bottom part where it shows how to comunicate pi and APM, my only concern is:
am I gonna have problems if using "hal.uartA->" and 3DR telemetry module ?

Michael Darling

unread,
Dec 3, 2013, 4:36:48 PM12/3/13
to drones-...@googlegroups.com
Oops!  I forgot to have email updates sent to me.  I was messaged by someone else with a nearly identical question about setting up the serial communication, so I'll paste my reply here.  But first, I'll explain a little bit more about what I am doing exactly.

My thesis in a nutshell:
I'm trying to achieve "close" formation flight of two UAVs using vision-based localization. The two hand launched RC airplanes will fly in a leader-follower configuration. My leader is equipped with an APM autopilot which will command a steady, repeatable flight pattern (such as large circles or figure-eights) and five very high intensity LEDs to make the feature detection more manageable, while the follower will be carrying a USB webcam and BeagleBone Black for video processing. I am using OpenCV (a collection of open source computer vision libraries) to implement the Efficient Perspective-n-Point algorithm to estimate the relative position and orientation of the leader with respect to the follower. This information (a 6-element vector <dx, dy, dz, droll, ditch, dhdg>) gets passed over serial to the autopilot onboard the follower which is then used by the modified ArduPlane firmware for navigation. As much as possible, I tried to preserve the existing cascaded PID control scheme of the APM so I am implementing a sort of "virtual waypoint" approach in which the current waypoint is constantly being moved to the leader's position. Since that was insufficient in HIL simulations, I am also taking advantage of orientation information by augmenting the bearing command with the relative roll and heading between the two vehicles (in a way, this acts like derivative information to help "predict" where the leader is going).


How to set up serial comms between BBB and APM
My code is up on Github but I'll warn you that its not very well maintained (I'm mostly using Git to backup my own work -- I'm not collaborating with anyone).  However there are two particular files that might be helpful to you: "BBBSerial.h" and "BBBSerial.cpp".  (https://github.com/mdarling39/LinuxVision/blob/Working_Branch/BBBSerial.h and https://github.com/mdarling39/LinuxVision/blob/Working_Branch/BBBSerial.cpp).

Those files define a "BBBSerial" class that I am using to send a 6 element vector (I think I'm taking doubles and typecasting them to single-precision floats before sending them over serial).  I made up my own protocol that sends "DATA" as start bytes to signal the beginning of a message, the data itself, and then a checksum that is computed using an exclusive OR on each byte. I think the most relevant information for you would be the header files I am including and the commands I am using to open, set-up, send/recieve, and close the serial port.

I don't think it is as relevant, but if you want to see what the ArduPilot is doing, I am doing my relative navigation in a header-only file that is also up on Github: (https://github.com/mdarling39/APM-Vision/blob/GroundStation/ArduPlane/RelNAV.h).  There is a lot of other stuff going on in that file, but the "update()" method is where you will find the serial communication.  (rNAVSerial is a pointer to the Serial2 object used in the ArduPlane firmware. To use that port, you will need to add some male header pins to the UART2 connectors. (photos attached. The UART2 pins are at the top-center of the images)  I don't believe there is anything else that needs to be done to enable UART2 like solder bridging, but I'm not certain since a previous student installed the pins for his own thesis. Also, make sure that you grab a logic level converter from Sparkfun (https://www.sparkfun.com/products/8745) since the APM serial have a V+ of 5V while the BBB uses a V+ of 3.3V. (A photo of my setup is also attached)

In BBBSerial.cpp I also left myself some comments on what I had to do to enable the UART ports on the BeagleBone.  Specifically:

To enable UART1 on BBB:
These instructions describe how to enable UART 1 on startup
Reference:

     mkdir /mnt/boot
   mount /dev/mmcblk0p1 /mnt/boot
   nano /mnt/boot/uEnv.txt

add this to the end of the single line of uEnv.txt:

   #Enable UART1 on Boot
   optargs=capemgr.enable_partno=BB-UART1

If you're working with the Raspberry Pi, you may need to follow a different procedure, but I'd guess that its similar.

I hope that at least helps you to get stared.  Let me know if you have any other questions.  I'm not expert on any of this (just been learning as I go) but I'd be happy to help out as much as I am able.
-Mike

Inline image 1
Inline image 2
Inline image 3

legoiv hck

unread,
Dec 11, 2013, 1:06:10 PM12/11/13
to drones-...@googlegroups.com
Thanks alot, this is really helpful.
I am having tourble on viewing the images, i dont know if you could try again to post them.
I think this is a really usefull info and that might be interesting to document it and make it availabe to anyone that might need it.

Michael Darling

unread,
Dec 11, 2013, 3:54:49 PM12/11/13
to drones-...@googlegroups.com
Thanks legoiv!  I will consider putting together some kind of How-to when I find some spare time if I can find an appropriate place to post it.

I'm able to see the images.  Did you try clicking the [...] that appears under my message?  Somehow the second half of my message got interpreted as a "quote" by Google. Can anyone else confirm the ability to view the images I posted?


--
You received this message because you are subscribed to a topic in the Google Groups "drones-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drones-discuss/KbgEQw-Bjbc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drones-discus...@googlegroups.com.

legoiv hck

unread,
Dec 11, 2013, 6:57:52 PM12/11/13
to drones-...@googlegroups.com
I can see the frame of the image but those are in blank.
maybe you could send me a mail, and would have less problesms with it ?

Aakash Dawadee

unread,
Jan 8, 2014, 11:24:58 PM1/8/14
to drones-...@googlegroups.com
Hi Legoiv and Michael,
             I read all your conversations. I am doing similar work to you guys. Michael, I am also having trouble viewing those images. Could you please repost them. Thanks guys.

Julian Bourillon

unread,
Feb 10, 2014, 5:18:26 AM2/10/14
to drones-...@googlegroups.com
Hello,

I'm currently working on a personal project to setup obstacle avoidance and maybe 3D mapping to control my ardupilot quadcopter.
I want to use the Raspberry PI as a "brain + RC signal emulator", taking decisions then sending PWM signals via the GPIO  to control the Ardupilot. (rPI.GPIO via python to send PWM signals)

I've been able to send some PWM signals to the APM board but I'm unable to "arm" the quad.

Below the process I have followed :

- calibrate the Radio signal using APM planner and my Turnigy 9R Radio
- write down the min/max values for each channel (between 1000 and 2000us for the burst, signal frequency 50Hz)
- plug GPIO 25/24/23/18 to input channel 4/3/2/1 on the APM (After checking witch channel is throtle, which one is Pitch... etc)
- Code a simple python script to send PWM signals (THR down, YAW right for 4 seconds, sleep(4))

Did one of you consider this way to proceed to control the quad?
Do you think that sending PWM signals via python scripts is a good idea?
Any idea why I can't arm my arducopter using this procedure?

Many thanks

http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it to send PWM signals

http://ghowen.me/build-your-own-quadcopter-autopilot/ to see PWM signals coming in the APM board

Sorry for my english...

Dan N

unread,
Feb 10, 2014, 3:06:17 PM2/10/14
to drones-...@googlegroups.com
I have done this with Arduino, .netduino. and FEZ boards, it is a good approach.
 
Check to see if you can arm, with straight signal from receiver, after that, your just going to have to scope the signal your sending.
 
I suggest using PPM, instead of PWM, using the convertor 3DR sells (cause I know it works), then you don't need to sync your signals.

Michael Darling

unread,
Feb 10, 2014, 11:41:58 PM2/10/14
to drones-...@googlegroups.com
Hi Julian,

I'm probably not the most equipped to answer your question but if I understand right you are passing PWM signals to the ArduPilots inputs?  Does that leave you with the ability to switch back to Manual mode in the case that your RPi doesn't work like you think it will?

For my application, I'm sending a vector of doubles over a UART port.  That way the information passed to the autopilot is only used in the flight mode I created.  If something goes haywire, I'm able to switch back to Manual with no problems.

When you say you aren't able to "arm" the quadcopter, do you mean that the APM board, itself isn't completing the initialization process and arming or is the ESC (ESCs?) not arming?  If its the ESCs, they are probably seeing too high of a PWM value when they first receive power.

Again, I'm probably not your best resource, but those might be some things to consider.


--

Riccardo Felici

unread,
Nov 6, 2014, 6:00:51 AM11/6/14
to drones-...@googlegroups.com

Dear micheal,

I fail to display the images you posted, is there a way to see them?

thanks
Reply all
Reply to author
Forward
0 new messages