In my submission for the NXP Hovergames 2 competition, I struggled to find resources that made the process of connecting a Raspberry Pi to the RDDRONE-FMUK66 clear (I wasted a lot of time on it). So this project is my effort to communicate what worked, and some of what didn't work, when connecting. I used a raspberry pi zero w, but I would imagine that this would work on most of the later models of pi's. This process will probably also work for connecting to a different flight controller, such as a Pixhawk.
I've also added a brief section on setting up an ad hoc network on the raspberry pi.
Initial SetupBegin by flashing the FMU with the PX4 firmware image. This is described very well, for the Hovergames Drone Kit in the NXP gitbook. It is also useful to set up either a Linux virtual environment, or use a Linux machine, and follow the gitbook to install PX4 development tools and build PX4. You'll also want to install a simulator, like jMav sim. This is all out of scope for this guide, but I found it simplest to just use NXP's preconfigured virtual machine.
Next write the Raspbian OS image to an SD card and enable ssh. Make sure you are able to connect.
Now, fire up your FMU and connect through QGroundcontrol. In Settings > Parameters, set MAV_2_CONFIG to TELEM 2.
Physical ConnectionsPower:
To start with, there needs to be a method for power the raspberry pi off of the drone battery. I used the DROK 90010 5V DC buck converter, with the input side connected to the battery output via the drone's power distribution board, and the output connected to the raspberry pi. I soldered jumper wires to pins 4 (5V in) and 6 (Gnd), which could then be connected with WAGOs or wire nuts to the buck converter. You could also just solder the converter's output directly to the GPIO pins.
Serial Connection:
I opted to connect to the telem2 port on the FMU via one of the raspberry pi's UARTs. To do so, take a JST-GH 4 pin connector (with wires, cut and stripped on the non-connector end), and solder the correct FMU serial pins to pins 8 (Tx), 10 (Rx), and 9 (Gnd) on the raspberry pi (Tx on the pi goes to Rx on the FMU, and vice versa). Refer to the NXP gitbook for pinouts of the telem2 port.
- Pin 1 is VCC,
- Pin 2 is Tx
- Pin3 is Rx
- Pin 4 is Gnd
When looking top down at the FMU, with the PWM ports pointed toward you, pin 1 (VCC) is on the left side of the telem2 port. Don't connect to the VCC pin on the FMU - the pi will not get sufficient power from the FMU, and with the buck converter connected, connecting the VCC pin could fry something. It is probably best to cut the wire that is connected to pin 1 (VCC).
Software and MAVSDK-pythonFirst disable Linux serial console and disable bluetooth by adding
dtoverlay=disable-bt
to the end of /boot/config.txt
. Then run
sudo systemctl disable hciuart
MAVSDK-python
You no longer need to install mavsdk-server separately, or build everything manually. All you need to do is run:
pip3 install --user --upgrade mavsdk
Then
any time you call await drone.connect use the following for your connection line (note the reference in the system address):
await drone.connect(system_address="serial:///dev/serial0:921600")
Make sure your connectors are attached, power up the drone, and try connecting using any of the mavsdk-python examples (probably the ones that only arm the drone, or read telemetry data.
--Brief Note on USB connection--
I didn't try it, but refer to this github issue, where the following code is referenced for connecting through USB:
await drone.connect(system_address="serial:///dev/ttyUSB0:921600")
Potential IssuesConnecting
I ran into problems, when connecting to the drone via mavsdk-python, with the following block of code (included in many of the examples):
async for state in drone.core.connection_state():
if state.is_connected:
print(f"Drone discovered with UUID: {state.uuid}")
break
I don't really have an explanation for it, but this very often created an error on connection. After removing it and just having
print("Waiting for drone to connect...")
await drone.connect(system_address="serial:///dev/serial0:921600")
seemed to work well, and I had no issues.
The simulator is not the same as the real thing!
Be careful of takeoff speeds, altitudes, landing speeds, etc. In reality, the drone did not behave exactly as expected. Trusting it to do some maneuvers, such as landing, without first tweaking the code slowly and having a good method to take over, can lead to crashes
--Ad Hoc Network--
It may be useful, as it was for me, to set up an ad hoc network on the raspberry pi. This will allow you to connect to it remotely when in the field. Keep in mind that once the ad hoc network is up and running, the pi will not have internet access, and it is difficult to escape to return to normal interfacing without being able to connect to the ad hoc network - so make sure your computer can! Otherwise, you may have to re-write the Raspbian OS. Do the following to set it up.
cd /etc/network
Back-up the original interfaces file
sudo cp interfaces interfaces.orig
create a new interfaces.adhoc file
sudo cp interfaces interfaces.adhoc
open it with a text editor
sudo nano interfaces.adhoc
and replace the code with the following:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet static
address 10.2.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid PiAdHocNetwork
wireless-mode ad-hoc
To enable the ad hoc network, run
sudo cp interfaces.adhoc interfaces
and also run
sudo systemctl stop dhcpcd.service
Reboot. After that, you should be able to connect to the adhoc network and ssh in like normal. To return to normal wifi connectivity, do the following:
sudo cp interfaces.orig interfaces
and run
sudo systemctl start dhcpcd.service
then reboot.
Comments
Please log in or sign up to comment.