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:

Limiting the maximum regen power in moteus

When using a servo controller, any time the motor needs to either decelerate or resist an external torque, the controller may “regenerate” energy that has to go somewhere. By default, moteus will apply that energy back to the input bus, potentially charging a battery if that is used as the power source. When the input voltage rises too high, either because the battery impedance is high or because a PSU is as the source, then moteus will apply “flux braking” to dissipate the energy in the windings of the motor instead of allowing the voltage to grow without bounds. This often works great, but in some common scenarios flux braking by itself can be inadequate. In order to operate stably, flux braking need to use a filtered version of the bus voltage. This means that if the bus voltage rises fast enough, the maximum configured voltage can be exceeded before flux braking has had a chance to actually begin dissipating significant energy in the motor.

RLS Orbis SPI support

Hot on the heels of BiSS-C encoder support intended for high end applications, I am excited to announce that moteus now supports the RLS Orbis SPI protocol for lower-end systems as of firmware version 1.0.0.

The RLS Orbis is an absolute magnetic encoder suited for use with diametric ring magnets and can be configured to use a number of different communication protocols. If you have a moteus-n1 or moteus-x1, then the newly released BiSS-C support already lets you communicate with them. However that left out the moteus-c1, which does provide the 5V necessary for an Orbis to function, but does not have a built-in RS422 transceiver.

moteus firmware version 1.0.0!

The first public version of moteus-r4 was announced way back in 2019. Since that time, there have been many new board variants and innumerable additional features and capabilities. Amazingly, through all of that, the CAN-FD wire protocol has actually remained backwards compatible the entire time! It is still possible to monitor that very first moteus with tview, and to command it using the register protocol with appropriate configuration. Many projects hem and haw about releasing a version 1.0 of their software, justifying breaking things from a users perspective over and over again. Here, we’ve actually maintained nearly complete backwards compatibility despite having a pure time based release versioning scheme.

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.

Native socketcan support for mjcanfd-usb-1x

Since the fdcanusb, and subsequently the mjcanfd-usb-1x, have been released, the only interface they presented to a PC host was a USB CDC (communication class device). That meant they appeared as a modem, on linux as /dev/ttyACMx and on Windows as COMx. Sending and receiving frames was pretty simple using a basic line based protocol.

This works fine as long as you are either using the mjbots tools, or designing a complete custom application. However, if you want to use the adapter with other CAN or CAN-FD based applications on Linux, there wasn’t a whole lot you could do. There was a simple daemon which, with a fair amount of effort, would make the hardware appear as a slcan device, but that was finicky and hard to get working and not terribly reliable.

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.

PWM input support

The new features and capababilities for moteus just keep coming! Here is another relatively straightforward one available in firmware release 2026-01-21, support for PWM (pulse-width-modulated) inputs. If an appropriate pin is configured, moteus can report the period and duty cycle of a PWM input to applications. This can be used to monitor the fan RPM for the moteus cooling fans on moteus-c1, moteus-n1, or moteus-x1, or could be used to read the value of a RC receiver output. Read on to learn how to use it and what the limitations are:

BiSS-C encoder support

I’d like to announce more encoder support in moteus, this time for BiSS-C encoders in unidirectional mode. BiSS-C is a protocol often used in higher end industrial encoders that uses a RS-422 wire level signaling scheme. This support works out of the box for moteus-n1 and moteus-x1 which have a RS-422 connector already included. All you need is to have firmware 2026-01-21 or newer installed and to follow the documentation for upgrading.

If you want to see a specific configuration example, or read about how the feature was implemented, read on!