3689713468?profile=original

In this short blog series I'm outlining the hardware and software of The Groundhog, my entry into the recent MAAXX-Europe autonomous drone competition held at the University of the West of England, Bristol.

Connecting the Raspberry Pi 3 to the Pixhawk took quite some working out, so I am hoping that by publishing my own step by step checklist, it may help others save a little time.

Code


All code is posted to my GitHub repository.

Connecting the Pi to the Pixhawk


I have previously blogged on how to connect a Pixhawk (running arducopter) to a Raspberry Pi 2 using the UART interface.  The hardware connection is identical for the Raspberry Pi 3.  However, there are some critical differences in setting up the Pi and in the code required to make the connection.

Configuring the Pi


Here is my installation checklist for installing Dronekit on the Pi and making the connection between the Pi and Pixhawk.

Start with Pixel installed on the Pi3 and do basic Pi configuration and updates:

Install Jessie Pixel
sudo raspi-config
Expand filesystem
Disable serial for OS
Reboot
sudo apt-get update


Now start to set up the development environment:

sudo easy_install pip
sudo apt-get install python-dev
sudo apt-get install screen python-wxgtk2.8 python-matplotlib python-opencv python-numpy libxml2-dev libxslt-dev


Install pymavlink and mavproxy to provide comms protocols between the Pi and Pixhawk.

sudo pip install pymavlink 
sudo pip install mavproxy


Install Dronekit and libraries to simplify control of the Pixhawk.

sudo pip install dronekit
git clone http://github.com/dronekit/dronekit-python.git


Now sort out the clash on RPi3 between our need to use the UART and it's use by the Bluetooth interface.  There are several versions of this config change about but this was the one that worked for me.

In RPI, add 2 lines at the end of /boot/config.txt (it will disable bluetooth and you can use /dev/ttyAMA0 to make the connection):

enable_uart=1
dtoverlay=pi3-disable-bt


So now we switch to the Pixhawk, connected to a PC using Mission Planner.  The version needs to be at least 3.4.0 which allows for GUIDED_NOGPS mode.  We also need to make sure Telem2 is properly configured, which we do from the Full Parameters list.

Check pixhawk firmware is 3.4.0
Check Serial 2 parameters:
SERIAL2_PROTOCOL '1'
SERIAL2_BAUD '57'
BRD_SER2_RTSCTS '0'


Now we can make the physical connection between the Pi and Pixhawk and test it out.

Note on power:  At this point, I had the RPi and Pixhawk independently powered, so the 5V connection between the two units was disconnected.  As long as they have a common ground, all is good.

Make physical connection

Test connection.  On the Pi:
sudo -s
mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --aircraft MyCopter
param show ARMING_CHECK
watch HEARTBEAT (You should see mavlink heartbeat messages going both ways, every second)
Cntl - c
Reboot RPi


If you can see heartbeat messages during the test, like those below, all is good!

> HEARTBEAT {type : 6, autopilot : 8, base_mode : 0, custom_mode : 0, system_status : 0, mavlink_version : 3}
< HEARTBEAT {type : 6, autopilot : 8, base_mode : 0, custom_mode : 0, system_status : 0, mavlink_version : 3}
< HEARTBEAT {type : 13, autopilot : 3, base_mode : 81, custom_mode : 0, system_status : 3, mavlink_version : 3}

Setting up the Software in the Loop Simulator (SITL)


Beyond making the basic connection work, I found the SITL crucial to allow the developing software to be frequently tested.  Basically, the RPi needs something to connect to on the desk, and that cannot be the Pixhawk itself.

As a rudimentary test-environment to make sure the control commands are in the right ball-park, I found the SITL to be great.  Any more than that might be being a little optimistic.  I confess there is much configuration possible of the SITL itself which I have not played with (that's my excuse!).  But for example, don't expect the SITL to replicate anything approaching the inertia of a 3Kg hexacopter travelling at 40mph.

I installed the SITL on a PC, connected to the Pi3 through a standard home network.  The ardupilot site has instructions for the build and installation here, which worked after several attempts.  However all the issues were down to me not following the instructions precisely.

See more posts at mikeisted.com

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • I posted this some while ago when I was using a Pi2 myself. Fig 18 shows the code segment.  Of course you do not need to worry about the bluetooth with a Pi2.

    I switched to a Pi3 using Dronekit to try to simply things somewhat.  With the above configuration my full connection code using Dronekit is: (forgive the lack of indents):

    #--------------------------SET UP CONNECTION TO VEHICLE----------------------------------

    # Parse the arguments
    parser = argparse.ArgumentParser(description='Commands vehicle using vehicle.simple_goto.')
    parser.add_argument('--connect',
    help="Vehicle connection target string. If not specified, SITL automatically started and used.")
    args = parser.parse_args()

    connection_string = args.connect

    # Connect to the physical UAV or to the simulator on the network
    if not connection_string:
    print ('Connecting to pixhawk.')
    vehicle = connect('/dev/serial0', baud=57600, wait_ready= True)
    else:
    print ('Connecting to vehicle on: %s' % connection_string)
    vehicle = connect(connection_string, wait_ready=True)

    03. MRes in UAV Co-operative Mapping. Getting Control of the Flight Management Computer
      Project Recap: My Masters project within the Bristol Robotics Laboratory is to design a system of UAVs that can be deployed in groups to co-operati…
  • thanx for this guide since most people find connecting pi with pixhawk challenging despite lot of support on ardupilot.org and that's is specially true with Pi3. great you highlighted the disabling of Bluetooth on Pi3. I am using Pi2 but still my Pi2 is not able to detect ttyAMA0 serial port so I am suing ttyUSB0 for connecting Pixhawk to Pi. although my connection is working fine but I would like to know why my Pi2 is not able to detect port ttyAMA0. I have disabled the console's control over the serial port and I do not have a Bluetooth on Pi2.

    ArduPilot Open Source Autopilot
    The most advanced open source autopilot for use by both professionals and hobbyist. Supports multi-copters, planes, rovers, boats, helicopters, ante…
This reply was deleted.