Anda di halaman 1dari 14

Adding an RP LiDAR onto the DJI Matrice 100

Drone to Implement Obstacle Avoidance

Brian Cruz1, Olu Roy2, Adam Wathieu3, Kamel Saidi4
19 June 2017


1 Wheaton High School

2 Marriots Ridge High School
3 Winston Churchill High School
4 National Institute of Standards of Technology

Table of Contents

List of Necessary Items 3

Introduction 4
Setup 5
Raspberry Pi 5
Raspberry Pi Network 6
Matrice 100 Drone 7
Mounting 9
3D Printing Configurations 9
Testing 12
Code Documentation 13
GitHub Repository 13
Important/Useful Files 13
Heading 13
Showcase 14

List of Necessary Items

• DJI M100 Drone
• Raspberry Pi 3 Model B
• Slamtec RP LiDAR A2
• 32 GB MicroSD Card
• Anker PowerCore 10000
• A personal computer (tested on Mac and Linux)
• A monitor, keyboard, and mouse (for setting up Pi, unnecessary for later

• DJI Assistant 2 (for Mac)
• DJI Go (for device connected to remote controller)
• Etcher


The objective of this project is to add a LiDAR onto the M100 drone to implement
obstacle avoidance. This means that whenever the drone approaches an obstacle on its
horizontal axis, it will autonomously stop and hover in a stable position to avoid

This project is not designed to avoid obstacles above or below the drone. It only senses
obstacles on its horizontal plane.

We will be doing this by mounting the Raspberry Pi, the external battery, and the LiDAR
onto to the top part of the Matrice 100 center frame. We will collect data from the Pi via
remote access from another computer. By having the data sent to a computer on the
ground, we will be able to see what the Pi is doing and the decisions it’s making in real
time while the drone is flying.

Before you begin, it is important to look at all the necessary manuals. Please take the
time to read these manuals:

• DJI M100 Drone

o http://download.dji-


Set Up

Raspberry Pi
First, we have to set up the Raspberry Pi. Insert the MicroSD card into your computer.
Then download the following image of the Raspberry Pi operating system:

Then use Etcher to convert this image onto the MicroSD card. Then insert the MicroSD
card into the Raspberry Pi, and boot it up.
Once you are in, open Command line. Execute these following commands:

Update the software of Raspbian Jessie5:

sudo apt-get update
sudo apt-get install

Install gcc6:
sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

Install CMake7:
sudo apt-get install cmake

Install Git8:
sudo apt-get install git-all

Now we have to download the SDK necessary to make this all work. In your desired
directory, execute the following command:
git clone

Please read README.txt in this SDK as well as the code documentation for reference.

Now we have to setup all the hardware pertaining to the Pi. Connect the raspberry pi to
the LiDAR through the USB port. Then connect the Raspberry Pi to the drone using the
UART cable that is provided in the DJI M100 contents. The cable is connected into the

5 Raspbian Jessie is an operation system for the pi. More information at:
6 gcc is a C++ compiler. More information at:
7 CMake is a building platform. More information at:
8 Git is a version control system. More information at:

Figure 1.0 Figure 1.1

UART_CAN2 port of the drone (figure 1.0). The other side is connected to the GND,
TXD, and RXD pins of the pi (figure 1.1). Make sure that the RXD cable of the wire goes
to the TXD Port (Port 8), and that the TXD cable of the wire goes to the RXD Port (Port

Raspberry Pi Network
In order to communicate with the pi while the drone is flying, we set up a remote access
network using SSH9. This makes the Pi create a local network on boot up, which your
computer can connect to so that you are able to communicate with the Pi via your

Save /etc/network/interfaces file in case you need it again:

cp /etc/network/interfaces /etc/network/interfaces

Now modify etc/network/interfaces:

nano /etc/network/interfaces

Once you are in the nano platform, delete everything and add:
auto wlan0
iface wlan0 inet static
wireless-channel 1
wireless-essid Matrice 100 PI
wireless-mode ad-hoc

9SSH allows us to use the command line of the Pi remotely from another computer.
More information at:

Now reboot the pi. On your computer network settings, there should be a network called
Matrice 100 PI. Connect to it. Then, open up command line, and execute the following

Use the command line of the Pi:

ssh pi@raspberrypi.local

If that doesn’t work, try:

ssh pi@

After entering the password of your pi, you are using your Raspberry Pi’s command line,
denoted by:
pi@raspberrypi:~ $

Now you can put away the Pi’s monitor, keyboard, and mouse. To use your Pi now,
simply plug it in to the Anker or any power source, connect to its network on your
computer, and execute ssh pi@raspberrypi.local in your computer’s command line.

DJI Matrice 100 Drone

To get everything to properly work, we need a way for the pi to communicate only and
directly to the drone. Hence, we have to create what is called an app. First, if you aren’t
one already, register as a developer at:

Then, you must create the app. Hover over to User Center and create an Onboard SDK
app. Take note of the app information, namely the App ID and App key. We will use
these later.

If you haven’t familiarized yourself already to the software, and what capabilities it has,

Most of the information in the developer documentation portion of their website regards
version 3.3 of their SDK. As of June 19, 2017, the latest version of the SDK that supports
the Matrice 100 is 3.2. Please be aware of the documentation you are using. To avoid
risk, we recommend that you only use the above link to research the documentation of
the Matrice 100.

Next, we need to modify the drone
settings to accept API control and we
need to update its firmware if
necessary. In Assistant, hover to SDK
and check the box labeled “Enable
API Control” (figure 1.2). Also, make
sure that the Baud Rate is set to
230400. Then, in the firmware
Upgrade section, check to see if any
updates are required.

Figure 1.2

If you haven’t familiarized yourself already to the software and its capabilities, consult:

Figure 1.3:
From left to right: Matrice 100 remote, Matrice 100,
Raspberry Pi, Anker Power bank, RP LiDAR A2


To mount these pieces onto the

M100, we used zip ties and 3D
printed a mounting plate for
the LiDAR. We placed our Pi
under the first expansion bay,
and replaced the expansion
bay plate with our own 3D
printed plate that was custom
fit in order to accommodate
the LiDAR that was to be
placed on top of it. We zip tied
the Anker power bank on top
of where the camera is Figure 2.0
mounted, in the front of the
drone. Our program is
designed to omit the GPS module as an “approaching obstacle,” so there is no need to
displace the GPS module or remove it. Our mounting setup is shown in Figure 2.0.

3D Printing Configurations
Although the LiDAR can be mounted several ways, we decided to 3D print a mounting
plate that holds the LiDAR and replaces the expansion bay plate. For those who are
interested in 3D printing the plate, our documentation is as follows:

First, we need all the necessary hardware and software:

• LulzBot Taz 410
• SketchUp (for Mac)11
• Slic3r (for Mac)12

10 LulzBot Taz 4 is a 3D printer. More information at:
11 SketchUp is a 3D modeling application. More information at:
12 Slic3r is a G-code generator for 3D printing. More information at:

Insert the SD card provided by the LulzBot Taz 4 into your computer. Then, download
the following STL file13:

Open Slic3r, and click Add. Then select the downloaded STL file to add. In the Print
Settings, Filament Settings, and Printer Settings, change the settings according to your
configuration and your filament type. We used the following filament:

If you are using this filament, then your settings should be as follows:

Print Settings:

Filament Settings:

13STL is a file format specific to 3D models. More information at:

Printer Settings:

Next, in the Plater tab, hit Export G-code. Save the exported file into the SD card. Then,
insert the SD card into the 3D printer, and print from the SD card. If you want to change
the 3D model, use SketchUp to design your own model.


Now, to test and run the drone with obstacle avoidance, make sure the drone is in a
netted area, and that everyone surrounding this net knows and is aware of the flying
drone. It is also very important that this is tested and run outside, so that the Matrice
100 can use the GPS to stabilize when hovering. Again, make sure the drone is a safe
distance from anyone, and if possible, add a net. After booting up everything, SSH into
the Pi via your computer. Now, get into the m100-lidar directory, and execute the
following commands to get the obstacle avoidance up and running:

Go into build directory:

cd onboard-sdk/build

Compile the program:


Go into the bin directory:

cd bin

Edit UserConfig.txt:
nano UserConfig.txt

Enter in App ID and Key (For more information, refer to Set Up page):
DeviceName: /dev/ttyS0
BaudRate: 230400
Version: versionM100_31

Execute following command to start the program:

./djiosdk-linux-sample -interactive

Hit ‘Z’ to start obstacle avoidance. The drone must have lifted off before obstacle
avoidance is started. If this doesn’t work, try restarting Assistant and the program, and
use [e] Takeoff as a sample. If it does indeed lift off, then the obstacle avoidance should
be able to work.

Code Documentation

GitHub Repository
The GitHub Repository can be found at:

This contains all the code necessary to run this project. This should be downloaded into
the Pi. To access the Pi’s command line via another computer’s command line, refer to
the setup content in this documentation. To execute the program, refer to the testing
portion of this documentation.

Important/Useful Files
The .cpp file that is run when the command ./djiosdk-linux-sample –interactive is
executed can be found in:

The stop function that is used in LinuxInteractive.cpp can be found in:


To figure out where the obstacles are relative to the drone we used the diagram in Figure
3.0. The LiDAR, as mentioned in its documentation, scans clockwise and starts at 0°
opposite of where the cord is.

Figure 3.0: