Tracing a drone flight

May 16, 2018 |

Percepio’s Senior Drone Builder and Support Engineer Niclas Lindblom with his Embedded World drone.

We knew we had to have something special. We knew we were going to show Tracealyzer 4 at Embedded World 2018, and we wanted the world to take notice – it was after all the largest improvement in at least five years.

We also wanted something that could really show the potential of tracing and live visualization. Not just a basic “blinky” demo, but a real-time system with advanced, complex features. Those systems can’t be halted and resumed for debugging, as that would break the real-time requirements, so you really need tracing to understand their runtime behaviour.

Project take-off in October

– Last October, at Arm TechCon in California, we came up with the idea of flying a drone in our booth at Embedded World. We figured it would make a nice demo, says Niclas Lindblom, Percepio’s Field Application Engineer and support superhero.

That is, not a nice demo of drone flying per se, but of one of the most booth-friendly new features of Tracealyzer 4: live streaming and visualization of trace data.

Once the decision was made, Niclas was named Senior Drone Builder and sent to acquire the necessary parts. First out was the flight control software, LibrePilot, and a four-motor drone build kit. LibrePilot runs on top of FreeRTOS on an STM32 microcontroller, and Niclas spent the next few days configuring it and integrating the Tracealyzer recorder libraries. On the first test run, however, he realized that he would have to think through a few things again.

– I had configured Tracealyzer for snapshot recording, where we store trace data in a small RAM buffer on the target, but I immediately realized that this system generated a huge number of events. I could only record a few milliseconds worth of data before the buffer filled.

Several strings attached

The next challenge then became to make the drone software stream trace data to a host computer while flying. Tracealyzer supports streaming in several ways, for instance via SEGGER J-Link probes, but we still had to deal with the mass of data produced by the drone software. When idle, the amount of data was not so bad, but when flying it produced about 2 Mbytes/second.

– After some more discussions we concluded that streaming via a SEGGER J-Link over cable was the only realistic solution. We considered streaming the data over radio, but the LibrePilot board only had a 56 Kbit/s radio link intended for basic telemetry data. Another idea was to transfer the trace data via USB to a second board with Wifi capability, but we would probably not have been allowed to fly untethered in the exhibition hall anyway.

In the end safety won the day. The drone flew in Percepio’s booth not only tied to a computer with an Ethernet cable but also anchored to a table with four one-meter-long strings. At times we even disconnected the wires and “flew” it by hand – holding it in a firm grip while the LibrePilot control system controlled the motors at full power (a bit scary!).

However, even the J-Link choked when trying to stream RTOS events at 2 Mbyte/s. In experiments, we found it only managed about 850 Kbyte/s. But the recorder library already contained a solution for this – event filtering. Niclas configured the recorder to exclude some of the most frequent kernel calls from the trace, which brought the data rate down to a more manageable 200-300 Kbytes/second.

A trace from LibrePilot flying. Left are all the tasks in the system, above right shows CPU load and below that you can see the output signal to each of the four motors.

To plot some interesting output on the screen, Niclas added Tracealyzer User events to the LibrePilot source code to transmit the motor output signals to Tracealyzer. Each of the four motors had its own user event channel.

– In level flight the outputs are quite small, but any disturbance can give a short spike of full power output for that motor, and we could show those changes on the screen as they happened, says Niclas.

The missing resistor

Looking back, Niclas says the most challenging problem was to make the flight controller and Segger probe talk to each other. In the beginning they didn’t, even though there was a cable connecting the two. It turned out to be that elusive thing every programmer sometimes wishes he could blame: a hardware bug.

– I spent days fighting with this until I finally picked up the hardware manual from Arm. It clearly said that there should be a resistor between two solder points, but I could just as clearly see that there wasn’t one on the board I had. Time to bring out the soldering iron.

The drone has been dormant since Embedded World, but we will almost certainly bring it out on more occasions. Niclas says he also has plans to improve the demo.

– I still hope we will be able to at least add wireless communication to it.

The specifications

  • LibrePilot flight controller software
  • FreeRTOS including Tracealyzer library
  • STM32F4 MCU (ARM M4-based)
  • Various sensors: magnetometer, barometer, gyro, accelerometer
  • Four motors w/propellers