Setting up live video streaming from Raspberry Pi:
After quite a bit of researching, I decided that using UV4L would be the best software for my purposes, which involved sending live video streaming to a laptop from the Raspberry Pi on the drone over WAN.
Globally speaking the UV4L software falls in a sort of “middleware“ category. It consists of a series of highly configurable drivers, an optional Streaming Server component providing a RESTful API for custom development and various extensions for the server that cooperate together. The Streaming Server also provides the basic web UI for the end-users to try or use all the key functionalities directly. For maximum efficiency, each instance of UV4L runs as a single, independent system process which exploits the underlying hardware natively (whenever possible). Here is a more detailed list of features.
As suggested by this website, I executed
curl http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc | sudo apt-key add –
and then added
deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ jessie main
to /etc/apt/sources.list .
Next, after updating my Pi, I installed uv4l and uv4l-raspicam using
sudo apt-get install uv4l uv4l-raspicam
In order to be able to send live video over WAN, the installation of 2 more drivers was required:
sudo apt-get install uv4l-webrtc
sudo apt-get install uv4l-xmpp-bridge
openssl genrsa -out selfsign.key 2048 && openssl req -new -x509 -key selfsign.key -out selfsign.crt -sha256
is also important in order to configure secure HTTPS in the Streaming Server.
Downloading the xmpp-bridge driver makes it possible to broadcast both live audio and video contents from the Raspberry Pi 2 to all the participants or viewers joining a room of a Jitsi Meetconference on the Web. Furthermore, no browser and no GUI will have to be used on the Raspberry Pi. It will be automatically started once the installation has finished or when the system boots.
Setting up communication between Raspberry Pi and Pixhawk 2
After spending almost a month on debugging errors, I was finally able to send commands from Raspberry Pi 3 to Pixhawk 2.1 via MAVLink. I used Raspbian Jessie along with 64 GB card.
Firstly, it is important to set up the Pixhawk 2 for communication via Mavlink. In order to do so, I used mission planner as suggested by this website. Then the following parameters were edited:
- SERIAL2_PROTOCOL = 1 (the default) to enable MAVLink on the serial port.
- SERIAL2_BAUD = 576 so the Pixhawk can communicate with the RPi at 57600 baud.
- LOG_BACKEND_TYPE = 3 if you are using APSync to stream the dataflash log files to the RPi
After restarting the Pixhawk, make the following connections:
- Pixhawk Rx (Telem 1) –> Raspberry Pi Tx
- Pixhawk Tx (Telem 1) –> Raspberry Pi Rx
- Pixhawk Ground (Telem 1) –> Raspberry Ground
- Pixhawk VCC_5V (Telem 1) –> Raspberry 5V
Also, connect the Pixhawk to an 11.1 V battery to power both the Pixhawk and the Raspberry PI.
Then, execute the following commands to install mavlink:
sudo apt-get update #Update the list of packages in the software center
sudo apt-get install screen python-wxgtk2.8 python-matplotlib python-opencv python-pip python-numpy python-dev libxml2-dev libxslt-dev python-lxml
sudo pip install future
sudo pip install pymavlink
sudo pip install mavproxy
Next, in the Raspberry Pi Software Configuration Tool (accessed by sudo raspi-config), go to Interfacing options and disable “serial login shell” and enable “serial interface”.
to /boot/config.txt and reboot the Raspberry Pi.
Now you can execute
mavproxy.py –master=/dev/ttyAMA0 –baudrate 57600 –aircraft MyCopter
to connect to the Pixhawk 2.
The connection can be tested out using commands such as
param show ARMING_CHECK
param set ARMING_CHECK 0
Controlling the rotors using a python script running on Raspberry Pi
In order to enable artificial intelligence on the drone, I decided to use DroneKit.
Installation of drone kit is simple and requires execution of the following command:
pip install dronekit
If you don’t have pip already installed, use the following commands to install it first:
sudo apt-get install python-pip python-dev
Several sample programs have been provided on the website itself, but small changes must be made in order to successfully execute them.
vehicle = connect(‘tcp:127.0.0.1:5760’, wait_ready=True)
must be replaced with
vehicle = connect(args.connect, baud=57600, wait_ready=True)
in order to tell Raspberry Pi which port to connect to and which baud rate to communicate at.
Additionally, while executing the python script, the command must be executed so:
python filename.py –connect connectionPort
Hence, if the filename were takeoff_and_land and the connectionPort were the default ttyAMA0, the command would like this:
python takeoff_and_land.py –connect dev/ttyAMA0