Over time I've developed an affection for brushless DC (BLDC) motors. Their robust and efficient design makes them an attractive option for robotics and industrial applications. BLDC motors have permanent internal coils which are driven by a control circuit (motor controller) according to precise timing such that a rotating force is created on the magnetic rotor.
In my adventures as a robotics engineer I've encountered a variety of motor controllers, from super simple ESCs (often used with drones or RC cars), to full featured industrial controllers like Roboteq and ODrive. In many cases, motor controllers offer an interface that allows engineers to interact with the controllers through code. Roboteq has an RS232 interface and ODrive supports not only UART but also has a full fledged Python interface over USB.
Using these interfaces it is possible to not only send commands like velocity / position control, but read properties like current draw, torque, and power consumption as well.
I realized that this functionality presents a great opportunity to leverage embedded machine learning for predictive motor maintenance. Instead of adding external sensors to detect faulty behavior, why not try to make do using only the motor controllers' internal properties?
So I set out to combine my ODrive motor + controller with Edge Impulse to create an anomaly detection model based solely on power consumption data streamed from the motor controller!
Here's the idea:
1. Sample instantaneous power consumption data from the ODrive controller while the connected D5065 motor moves around.
2. Create an anomaly detection model based on this data.
3. Send an alert when the model detects potentially faulty behavior.
It seemed too easy to have the motor simply spin at a constant velocity, so I used a Python script to make it change velocity pseudo-randomly. This was its movement more closely resembled that of, say, a robotic arm joint. This is the resulting power signal:
Here's a short video showing the entire setup. You can hear the random changes in motor velocity.
I communicated with the ODrive using a Raspberry Pi Pico, which I programmed using the Arduino IDE. Edge Impulse supports exporting ML models as self-contained Arduino libraries, so this made it super straightforward. First, I sent the data to the Edge Impulse suite via the data forwarder using my own code to sample the ODrive power data and stream it over serial, and then I created a K-means anomaly detection model (see Jenny Plunkett's tutorial on this.)
Once I trained the model I got this nice visualization of the K-means clusters. The circles represent regions of typical behavior. We can use our anomaly detection module to alert us when the power signal behavior falls outside these circles (clusters).
I deployed the model as an Arduino library, and made a few adjustments to this code to have my Raspberry Pi Pico blink an LED when an anomaly (over a certain threshold) was detected!
Where to from here?
This project was a minimal proof of concept intended to demonstrate how it's possible to create relatively noninvasive ML predictive motor systems employing a motor controller's built-in properties. It would be worth using more than one input signal to achieve a more nuanced model, and it's also possible to train a classification model to recognize specific motor faults.
More details are available in the full walkthrough of this project.
Want to see Edge Impulse in action? Schedule a demo today.