Archives: Development

moteus-n1 gate drive strength fix

Sometimes a bug report comes in that is simple. Sometimes a bug report comes in that is complex. This is the story of a bug report that looked very simple, but in the end was actually much more complex than I had initially expected. Further, it likely contributed to electrical damage on many deployed moteus boards, which is definitely not something I aim to do! Read on to learn more.

Host side SPMSM simulation for regression tests

When developing features for the moteus controller, testing on actual hardware has long been the primary way that new motor control features were validated. That includes “hero” testing on the lab bench, and the hardware-in-the-loop (HIL) dynamometer fixture used to validate each new firmware release.

While those are valuable techniques, dynamometer testing is not something that you can do rapidly, is limited to validating a small number of things at a time, and has a non-zero fraction of false positive failures due to unmodeled effects. To enable more rapid feature development, I wanted to test a lot of what was validated on the dynamometer fixture in a host side simulation. This would provide a lot of benefits:

  • It could run much faster than real time
  • 100% deterministic
  • Multiple instances can run in parallel
  • Agents can use it as success criteria for validating development

Read on to see how it was done:

Moteus performance analysis tool - CLI mode

I’ve previously written about the moteus performance analysis tool and how it can be used to evaluate different motor control systems for performance purposes. The tool described there is entirely a web based application that requires clicking around in the HTML interface in order to configure an analysis.

Now, there is newly added feature in the main moteus git repository that provides a command line interface (CLI) to the analysis kernel! This capability lets you run sweeps through various parameters or motor configurations much more easily than before, or even wrap the analysis in an optimization loop without resorting to browser based automation techniques.

moteus.move_to and moteus ruckig python example

For some time now the moteus python library has had a convenience function to repeatedly execute a command until moteus determines that the trajectory has completed. This helps a lot with simple applications with a single device, but as soon as multiple controllers are involved in the same machine numerous problems appear:

Watchdog timeout: moteus has a watchdog timeout and unless all devices are sent commands on a regular basis, they will fault. This is easy to do with set_position_wait_complete, which by definition only sends commands to a single device.

Optimizing fast movements

In a mini-project inspired by a Discord chat about a Rubik’s cube solver, I decided to undertake a project to see how quickly I could get moteus to make a controlled 90 degree movement and a controlled 180 degree movement. The project ended up involving a fair amount more work and theory than I had expected, but resulted in an overall solution that is relatively close to optimal for the specified moteus and motor. If you find text too hard, you can watch the video below, otherwise read on to see the details:

Capturing full rate debug data from moteus

Most users of the moteus brushless motor controller will perform diagnostics and monitoring over CAN-FD, using something like tview, the moteus python library or the moteus C++ library. These options are great, since CAN-FD works over long distances, allows multiple devices to be multiplexed and is relatively immune to EMI or other electrical disturbances. The biggest downside is that at best, you can capture telemetry a few thousand times a second. For instance here, 2.5kHz is the maximum achievable update rate with a pi3hat and a single moteus.

What should you do when you want to monitor events that happen faster than that? Well, moteus has a solution for that too, and while it isn’t nearly as convenient, it does get the job done for many uses. It is called “high rate debug output” and lets moteus emit small amounts of telemetry data at every single control cycle, so up to 30kHz. In this post I’ll show how to configure and use it, how to capture the resulting output, and how to plot it or otherwise make use of it.

Fitting moteus motor saturation models

Way back in 2020, I wrote about the motor saturation model that moteus uses to accurately calculate torque when a motor is operating in a region where the stator becomes saturated. What I didn’t write about was a method for actually determining those fit parameters for a given motor. This isn’t too critical, as most position mode applications don’t require the applied torque to be terribly accurate, but in some cases it does matter. When that is the case, there is now a tool that can calculate parameters appropriate for entering into moteus. Read on to find out more!