Finding Balance with TinyML
By Nick Bild
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. Even when the robot was given a few shoves, the outputs of the two algorithms differed by no more than 0.18%. With the neural network in the driver's seat, the robot successfully completed ten freestanding starts without falling over. It was also driven a distance of over 40 meters using keyboard controls without the backup controllers having to intervene. Some issues did crop up during more aggressive testing, however. In one case, the additional computational workload exposed a timing issue in the existing firmware. And when tested on a soft bed, the network exhibited the same oscillations that its LQR teacher was prone to. While replacing five LQR gain values with 385 neural network parameters may not make much practical sense at present, the experiment lays some interesting groundwork for future projects. Build Mode is considering giving the network some internal memory or having it work in conjunction with a conventional PID controller. It will be interesting to see if a tiny neural network can eventually teach its teacher a few new tricks.A tiny neural network keeps this robot balanced (📷: Build Mode) Five inputs determine the state of the motor (📷: Build Mode)
↑ Back to top
Originally published by
Hackster News ↗
· rebuilt here from its own full-text RSS feed · all rights
remain with the publisher, please read and support them there.