MATLAB Pixhawk Communication¶
In this demo you will learn two things
- Sending high-level commands from MATLAB to Pixhawk, using
- Getting live stream of images into MATLAB from ODROID which is mounted on a quadcopter.
As you can see from the previous figure, there are 4 main components to setup.
- Motion capture system.
- Quadcopter with Pixhawk flight controller.
- ODROID: embedded Linux computer.
- MATLAB enviornment.
Motion capture setup¶
Motion capture (or Mocap in short) is used to provide accurate positions and orientations in an indoor environment. The mocap setup we have in the lab is from Optitrack company. You can think of it as GPS system for indoor environment.
Mocap mainly consists of cameras, network switches, and a PC with a special software. Cameras capture images which contain special reflective markers. Those markers are used to track objects (rigid bodies) they are attached to. Then, images from all cameras are transmitted to the PC software (called Motive) through the network switches, in order to do further image processing.
Motive extracts useful information about captured rigid bodies such as position and orientation. Such information can be further transmitted through network to other PCs for further usage. Rigid bodies are defined by at least 3 reflective markers that are rigidly mounted on the object of interest.
For this tutorial, it is assumed that the Mocap is already calibrated.
What we need in this tutorial is to
- Open Motive project
- Define rigid bodies
- Configure streaming parameters in Motive
- Use the Streaming Application to send mocap info to Pixhawk
Follow the following steps in order.
- Open Motive software, and choose
Open Existing Project. Choose a recent project that represents the latest calibration settings.
- Close the
Camera Previewview, and leave the
Perspective Viewview for 3D viewing of objects.
- Place the object in the cage (e.g. quadcopter) with mounted markers (minimum 3 markers).
- Select markers in the
Perspective Viewand create a rigid body
- You can know your rigid body number from the
Rigid Body, after you select the rigid body in the
- Now, activate streaming over network as follows
- Connect the wireless serial module to the Mocap PC (e.g. XBee)
- Open Mocap streaming App.
- Select the proper Vehicle ID
- In the
Serial Connectiontab, select the proper serial port of the communication module from the
Port Namedrop menu. Set the
Baud Rateto 57600. Finally, click the
Connectbutton. If the connection is successful, it will show a status message in the
- In the
Mocap Connectiontab, leave the
Client IPto the defaults IPs (
127.0.0.1). Hit the
- If the connection is successful, you should see the defined rigid bodies in the
Received Bodieslist box.
- Select the one corresponds to the quadcopter. Then, check the
stream to Mavcheckbox.
- Now, your quad should be getting its position and orientation feedback from the Mocap system.
This tutorial assumes that the quadcopter is setup and equipped with a calibrated Pixhawk (or Pixracer) flight controller.
In this Demo, the quadcopter is assumed to have an ODROID on-board, two serial communication modules (e.g. XBee). One for the Mocap connection, and the other for MATLAB connection.
In this Demo, ODROID is used to capture real-time images and stream them over WiFi network to a MATLAB session. The streaming application is assumed to be installed on ODROID and ready to be used. Also, the ODROID is assumed to be setup to connect to a local WiFi network.
Check this guide to see how to install the streaming app on ODROID.
To run the application, follow the following steps in order
- Connect a compatible camera to ODROID
- Connect a compatible WiFi module to ODROID (use the ODROID WiFi adapter)
- Power on the ODROID
- From your laptop (which is connected to the same local WiFi network as the ODROID), open a terminal and remotely log-in to ODROID
ssh firstname.lastname@example.org password: odroid
odroid is the user account name.
192.168.1.113 is the ODROID’s IP address.
- Navigate to the app folder and run it
cd ~/Desktop/imgstream/Image_Live_Stream/opencv_stream/stream_cpp ./sender 192.168.1.112 10000
192.168.1.112 is your machine’s IP address.
10000 is the port that is going to be opened in your MATLAB. You can choose another port, but make sure it matches the one used in your MATLAB.
- Now, the ODROID is sending images to the specified IP and port.
In this Demo, MATLAB is used to
- Communicate with Pixhawk (or Pixracer) in order to send high-level commands. For example, position set-points, velocity set-points, or acceleration set-points. It can also receive feedback information from Pixhawk.
- Receive live-stream of images from ODROID.
You need to use the MATLAB files associated with this Demo. Please ask for your free copy.
We are going to use two main MATLAB classes in this Demo. One is called
MatMav, and the other is called
MatMav is a MATLAB class that is used to communicate with Pixhawk.
ImgStream is a MATLAB class that is use to receive live image stream from ODROID (or any Linux computer) over network.
Before you use the MATLAB files associated with this demo, you should setup your environment properly.
Before you use the MATLAB files associated with this demo, you should setup your environment properly. Namely, you need to associate your MATLAB with a C/C++ compiler, and install OpenCV.
Please follow the OpenCV installation as follows,
Google how to associate your MATLAB with a compiler.
- Download the MATLAB folder associated with this Demo.
- Open MATLAB and navigate to that folder.
- Run the
If all goes well, you should get the message
Setup is done. Now, you are ready to proceed with the experiment which is implemented in the
Demo1.m MATLAB file.
- Check the
Demo1.mfile to get familiar with