Close

Smooth operator

A project log for Tardygrade

3D printed quadruped with a tiny BOM

Dejan RisticDejan Ristic 10/15/2021 at 21:110 Comments

Improved servo action using the esp32 remote control module (and a tiny bit of math)

The Tardygrade turning gear mechanism is designed to allow the robot to pivot 15° at each step. In theory this will let it pivot a full 360° within twelve full revolutions of the main gear.

But there's a snag. The servo moves at linear speed, resulting in abrupt acceleration and deceleration. This can make the feet loose their grip and slide about, which means pivoting the robot to a precise degree becomes impossible.

After becoming aware of this issue I made a brief attempt to introduce smooth endpoints to the servo action. But since I couldn't immediately figure out how to put that into code I threw it in my mental basket marked "annoying little bugs I'll probably get around to fix sometime".

Now I figured would be a good time to pick something out of that basket instead of putting more stuff in.

I had bookmarked [James Brutons] video on how to make robots move smoothly (which I probably found on the Hackaday blog originally).
Although the method he used was elegant, it only provided smooth deceleration. I needed smooth acceleration as well. 
The comment section steered me in the direction of cosine interpolation—thanks YouTube user [Cole Smith]. Then this post on the CodePlea blog "refreshed my memory" on how to do it, and also covered an alternative that doesn't involve cosine.

in the end the math required was as simple as: x^2(3-2x)

Now, all of this worked well enough when using the machine.PWM library. However there's some considerable loss of duty cycle resolution since that library only deals with integers.

But by being a frequent lurker on the micropython.org forum I'd been made aware of an alternative, thanks to user [wangshujun].
The ESP32 RMT module is intended for IR remote control communication, but can really be used for any kind of pulsed data. It's accesseded through the esp32.RMT library.

Using RMT instead of the PWM library brings two advantages: One is higher duty cycle resolution. The second is that the entire pulse sequence can be offloaded to hardware, which is an ideal way of making the servo action non-blocking. This will allow the robot to be more responsive when controlled by remote. It can also make life simpler when adding new functionality like AI and such.

While I was at it I saw no reason why not to use the RMT module to control the other servo as well. While not as dramatic of an improvement, that allows me to easily achieve gradual changes in walking speed, which is a nice feature to have.

Discussions