🞴 Engineering Index About Search

Servo Control GUI Tool


In order to configure and tune the servo control parameters of my servo control firmware, I had to get a little creative with the communication interface since I was using most of the available pins on the board. One option was to use the CANBUS port, but that would require a specialized interface to connect it to a computer, which is undesirable and possibly expensive. I figured I could instead use the SWD interface provided by the STLink included on the board. I used the memory reading and writing functionality of the STLink interface to communicate with the controller via a memory buffer.

Using that interface, I create a GUI tool that displays high-resolution time-series data to diagnose servo performance and to tune the various servo parameters. Additionally, a variety of commands are available to command certain motions of the motor so that the controller performance can be easily tested.

An example of using the GUI tool to command several position step inputs and observe the resulting motion.

The code is available on Github.

STLink Communication Interface

The STLink itself has a pretty simple USB interface, but I only used a very simple subset of that: the WRITEMEM_32 and READMEM_32 commands for the interface. Towards this end, I implemented a simple API that exposes functions to read/write arbitrary buffers from/to the microcontroller.

The first problem I had to solve was that I could only read absolute addresses, so in order to read data that could be placed whereever by the linker, I had to create a symbol in a consistent known location that could serve as an anchor to the rest of the data. I added a symbol in the linker script that always appears at the beginning of RAM (the address 0x80002000), which I could hardcode into the STLink interface. At that address, I stored a pointer to another, larger struct, which contains a bunch of pointers to other relevant structs, such as the servo configuration parameters, a command buffer, and a telemetry data buffer.

Telemetry Data Buffer and Visualization

I determined that the ability to visualize the performance of the controller was one of the most impactful features I could implement. On the firmware side, I created a ring buffer of data points that I added to every control loop interation, which happens at 2KHz. In the data buffer, I store the input, filtered setpoint, and actual values for the position, velocity, and acceleration, which is all the relevant motion data.

On the GUI side, I just repeatedly read directly from the ring buffer. The bandwidth of the STLink memory reading is high enough to read the data with high reliability. I then graph the each of the data series in a viewport on the GUI.

Controller Command Buffer

In order to command the controller to perform various actions, I creating a simple ring buffer of commands that the controller only ever reads from and the STLink interface only ever writes to. There are several general commands, such as changing the position set point, saving the servo parameters to flash, or turning on or off the motor power.

Future Plans

One feature I want to implement in the future is to command a specific input and use the telemetry data to automatically calculate certain parameters such as inertia, torque bandwidth, and eventually automatically tuning the controller.