Building a Searchlight with the DJI PSDK

Building a Searchlight with the DJI PSDK

Sep 27, 2022

What is the DJI Payload SDK?

The DJI Payload SDK (PSDK), is a development kit provided by DJI to support developers to develop payloads that can be mounted on DJI drones. Combined with the X-Port, SkyPort or extension port adapter, developers can obtain the information or other resources from the drone. According to the software logic and algorithm framework designed by the developer, users could develop payload that can be mounted on a DJI drone, to perform actions they need, such as Automated Flight Controller, Payload Controller, Video Image Analysis Platform, Mapping Camera, Megaphone and Searchlight, etc.

The Idea

We decided to make something from a PSDK expansion board and X-Port gimbal we had at the office. It was the perfect storm. With the kit and access to a Matrice 300, we decided to keep it simple and build a searchlight that would be mountable on the X-Port gimbal. After all, there's nothing simpler than switching a light on and off, right?

DJI Adapter board

DJI X-Port gimbal

The DJI PSDK comes with this adapter board that connects to either the Skyport2 or the X-Port gimbal. Its function is to break out the power and data connections for your custom payload.

The Plan

The intent was to focus on how to connect and communicate with the PSDK framework to end up with something that would provide knowledge and a good starting point for other future projects.

The Parts

We needed to find a super bright LED and something to manage the heat it would produce, and settled on the 'Dynamic 10 Watt LED Light Module Kit' from ledsupply.com. The kit comes with a 100mm long metal tube that acts as heat sink and enclosure for the light and LED driver module.  We bought this one without really having the full picture of what the final design would be like. Spoiler: 100mm was too long, but it worked because the goal was more about learning the PSDK than designing the perfect spotlight. Version 2 would be more about compactness, lumens and beam shapes, but for now we just wanted to make it work with the PSDK.

We noticed that the PSDK came with a lib for compiling on arm, so we chose to use a Raspberry PI Zero 2. The PI would run the main C++ application and would be in charge of talking to the M300 and also controlling a small relay to switch to power the searchlight on and off.

We designed and 3D printed the enclosure even though it has some flaws, and are proud of how the design worked out. 3D printed parts would not be good for a daily use payload, however the intention is that this spotlight would never really leave the ground. Its purpose is to  be used as a development platform for the PSDK. In the next version the plan will be to find or make an aluminum enclosure to handle the heat and weather.

The Raspberry PI has some extra features we didn’t need, so we disabled the HDMI port and reduced the amount of video RAM needed. Also, we set up the file system to be read only by default, this helps to prevent corruption of the SD card if a file is being written when the power shuts off.

The Build

Here is a schematic drawing of the circuit:

Schematic drawing of a Raspberry PI connected to the relay circuit.

Here’s the result:

After some soldering the relay board (bottom with yellow connectors) , the PI are mounted to the top panel of the enclosure.

To mount the LED, we were able to use the 1 inch thread on the back of the aluminum housing to hold the light in place and reduce how much potentially hot metal would actually be in contact with the 3D printed panel. We used high temp ABS plastic for the panels, but felt we should be better safe than soft and melty.

Back panel with 1 inch thread and hole for wires

Aluminum housing screwed on to panel

This is when it started to come together, and you'll see the PSDK expansion board on the bottom panel. You can also see the power wires going into the relay board and the serial connection coming from the PI to the expansion.

Put it all together and you get this chunky box, that is certainly not perfect, but will work for the first development prototype.

Once it was assembled, it was time to work on the main C++ that would run on the PI. Since the PI was connected to WiFi, we were able to compile the application while it was connected to the drone. This was super convenient for testing code as we progressed.

The Code

The plan was now to create a C++ application the would do the following:

  • Provide the API key to DJI and bind this payload

  • Implement a UI interface using the widget support built into the PSDK and DJI UI/UX SDK

  • Handle tap events from the widget to turn the searchlight on and off

We started by copying some files from the PSDK sample app. The sample has some C++ files that were designed to be ported over for custom applications. The files we needed provided a header file to include the API key and user information and some utilities required to use the serial bus and also access the operating system on the PI. The PSDK needs access to write logs and other files so the main application will have to run with sudo or as root.

The Binding

The first step is to bind the payload to DJI servers, and this process was easy. The binding is done via the DJI Enterprise assistant. After initiating the serial bus, the first thing the main application does is call an INIT function with my API key and some other information. The enterprise assistant picks up this info and communicates with DJI during what they call the binding process. Once this is complete, the payload doesn’t have to be re-bound and will work with other compatible drones.

The Widget

We were thinking we would need to create a special application for the searchlight, but DJI has a dynamic widget system built into the UI/UX SDK and also included in the DJI Pilot application. 

To use a widget, you define a JSON file that specifies what kind of controls you would like to add to a widget list UI component. We only needed a button to toggle the searchlight on and off. The PSDK takes this JSON file and icon images and uploads them to the application on the remote control.  Like magic the button appeared in DJI Pilot and we were able to get tap events from it to control the relay circuit.

Also, because we initialized the X-Port a widget appeared for steering the gimbal too. 

That was a lot of steps to turn a light on and off, and we did get stumped a few times along the way, but achieved our goal and have a great starting point for future projects. After setting the PI to execute the main application after booting we were done.

The Next Step

While working on this, DJI pushed an update to the PSDK that included ESP-32 support. It is the perfect fit for this payload. It's smaller, uses less power and we feel better about not needing an entire Linux OS to turn a light on and off. Also, the searchlight needs to be replaced with something brighter and smaller.

ESP-32 and a potential new set of LEDs for the next iteration

Overall, this project was successful and sets the stage for more future development. If there's any way we can help you with your next DJI project, contact the team at RIIS.

Where the brightest people solve the toughest problems to create the greatest future.

570 Kirts Blvd # 211, Troy, MI 48084 🇺🇸

(248) 351-1200

© 1998-2024 RIIS LLC.

Where the brightest people solve the toughest problems to create the greatest future.

570 Kirts Blvd # 211, Troy, MI 48084 🇺🇸

(248) 351-1200

© 1998-2024 RIIS LLC.

Where the brightest people solve the toughest problems to create the greatest future.

570 Kirts Blvd # 211, Troy, MI 48084 🇺🇸

(248) 351-1200

© 1998-2024 RIIS LLC.