Finding Balance with TinyML
Artificial neural networks with billions or trillions of parameters are getting a lot of attention these days, but there is quite a lot that can be accomplished with much smaller networks running on inexpensive microcontrollers. Just how small can you go before a neural network stops being useful for a real-world application? The maker behind the YouTube channel Build Mode recently set out to answer that question by putting a neural network with just 32 neurons to work balancing and driving a two-wheeled robot.
The robot was built using a series of 3D-printed structural components that provide mounting points for a pair of DC gear motors, batteries, and some control electronics. An ESP32 microcontroller is at the core of the system, and a small display provides information about everything from its lean angle to the control algorithm that is presently in use.
Rather than having the robot learn to balance itself through trial and error, Build Mode took advantage of a linear-quadratic regulator (LQR) controller that had already been developed for the robot. By feeding the LQR algorithm a wide range of artificially generated inputs and recording its outputs, a training dataset could be generated without so much as switching on the robot. Training a neural network on this data took about 40 seconds on a PC.
The network consists of two hidden layers of 16 neurons each and has a grand total of 385 trainable parameters. It accepts five inputs that describe the state of the robot and the strength of its response to tipping, and produces a single value that serves as the base motor command. It takes the ESP32 just 33 microseconds to run an inference, leaving plenty of time for other tasks in the robot's 500 Hz control loop.
After a few attempts at training the network, Build Mode arrived at one that could reproduce the outputs of the LQR controller quite closely. The network was initially run alongside the LQR controller without being given any control over the motors. E




Comments
No comments yet. Be the first to share your thoughts.