View Full Version : [posted] Quadruped walking robot

02-12-2020, 07:28 PM
I wanted to learn modern machine learning by building a small walking robot and have it controlled by a neural network. I will get to that, eventually. That's the primary reason I chose the Teensy 4 over other platforms, it has the computing power to run some decently sized neural networks in real time.

So far it has been a project about servos, mechanics, robotics, kinematics, electronics, etc.

What it has become, so far, is a neat walking robot that is quite capable of slowly walking difficult terrain https://youtu.be/a22FzKibE3c. It is somewhat capable of trotting at a higher speed too but the software needs some love. https://youtu.be/MDsygNth5o0


The heart of the beast is a Teensy 4.0 where I have used all pins but one on the normal side pinouts. 12 PWMs are controlling the servos, 4 ADCs read the foot sensors, 2 I2C pins talk to the MPU6050 gyro/accelerometer modules and 5 pins do SPI to the NRF24 radio.
The robot is powered by a 4 cell LiPo pack, which is total overkill, a 2 cell would be work perfectly fine. I have one switching voltage regulator for the servos to supply the 5-6V and one regulator for the fine electronics, Teensy and others. Since I didn't know if the Teensy supplied 3.3V would be enough there is another 3.3V linear regulator as well. I could probably skip that but I know that the NRF24 radio module is very very picky when it comes to getting a stable 3.3V.


The NRF24 radio sends all sensor data it has back to and old Arduino that relays it via serial to my PC, at 100Hz. The PC sends back commands from the game controller I use to tell the bot what to do. I'm working on modding and old PS2 controller to talk directly to the bot.

The leg mechanics is a bit strange. It's not like Boston Dynamics spot legs or most other bots you see people build. If it was a horizontal arm, and not a leg, the boston leg would be called a scara arm. My leg is a 5-bar parallel, or 5-bar scara arm, with an extension. The 5-bar is quite strong mechanically and it was easy to place the servos to fit all 3 axis per leg in a small package. The math is quite hairy though. I was considering a delta leg, but fitting the servos on a reasoanable way was not possible.


It is very handy that the bot is pretty small, it's just 20cm long and weighs about 600g. It is totally harmless to both itself and it's operator. It has pinched my fingers quite a few times (those tiny 14g servos are strong) but never anything serious. I happily upload code that is never simulated, bugs out totally and sends all servos to their extreme, no harm done. It's just a funny pose. The digital servos cuts the power after a while if they can't reach their position.

The magic to getting it walk as good as it does is all in the software. The MPU and the foot sensors are critical input to be able to walk good, but it takes software to process that data and control the servos.
I have spent many hours coding on the kinematics, i.e. converting from x,y,z to motor positions (and back), and lots of 3D algebra, rotations, translations, etc. I am a CS major though, my home turf :)

For now it can only walk slow and stable, and do some shaky trotting. I have only implemented static balancing, it has no idea about speed and inertia. I quickly tried some simple stand on 2-leg balancing but failed. I hope that the servo lag/gearbox play does not make this totally impossible. It might. Boston Dynamics Spot can easily lift two legs and with (what looks like) no effort stand two legs.
If there existed tiny brushless motors, play-free gearboxes and reasonable motor controlles I would get them in a heartbeat. The RC servos are blunt machines.

Back to machine learning, the starting point of the project. My idea for now is to make it walk decently with hand coding, record a lot of walking and use that data to train a neural network. Once it can imitate reasonably I can let it control the physical robot, walk around and learn by itself. I just have to figure out a reasonable arena for it to train in, and how to get it back on it's feet when it falls over. And the magic of network design, reward functions etc. It was easier back in the 90's when I last played with neural networks, kohonen and 3 layers.

02-12-2020, 07:49 PM
Gorgeous mechanics! I love the leg hinge solution. What material are you using it? You're spot on about the difficulty of using 'dumb' motors, closed-loop is a fundamental feature for systems with so many DOFs. If you had an internal physics engine servo telemetry would let you do velocity estimation. Have you considered using something like these new baby Dynamixels (http://www.robotis.us/dynamixel-xl-320/)?

I'm also really curious what 'fitness' metric you have chosen for ML.

02-12-2020, 07:57 PM
I forgot to mention that never ever connect a PWM pin from the Teensy directly to a servo. It works fine until the cables on the servos short, intermittently, sends 6V to the teensy and fries it. Believe me, I have 5 fried Teensies.
It works with a 330ohm resistor in series. The proper solution would probably be some lever converters/isolators that prevent back-currents.

02-12-2020, 08:20 PM
The leg hinges are in PP, polypropylene, perfect plastic for hinges. And 3D printable, at least for simple items like this. There is still a bit of flex in non-wanted angles when the legs are at extreme sideways positions, but the hip servos tends to give up in those situations. The small flex in the hinges should save the servos from some shocks too. But, it's a very small robot.

Dynamixels looks very cool, i'll check them out in detail.

I have one pin left on the Teensy, and seriously consider making that a current measurement pin. For good walking energy use is very important. Other than that and the obvious ones for fitness, such as distance traveled in wanted direction, I am not sure.

Edit: And for "closing the loop" i think that absolute precision in each motor is not critical. The loop can be closed good enough by end effector feedback, ie foot sensors in this case. The issue with RC servos are the PWM update time(100Hz ish) and the massive backlash in the gearbox, several degrees.

02-12-2020, 08:32 PM
As I said impressive effort. When I was testing the servos with the T4 I was concerned of the possibility of 5v getting back into the T4 so I started to use level shifters just in case especially since I was using digital servos. Serial servos are interesting, haven't had much time to play with them

02-13-2020, 05:19 AM
Even cooler when seeing the details and more behind it!

Only one pin left? Have you used any of the bottom pins in case you needed more? The T_3.6 type T_4.1 PJRC is working on would have a few more pins- plus the bottom 10 pins on the edges, and easier to get USB Host for Bluetooth dongle to connect a PS/2 controller - though the NRF24 radio a bit close for the 1" growth.

Very good leg selection and articulation - and hips too!

02-26-2020, 12:20 AM
I have been struggling hard to make it keep some kind of dynamic balance, ie take speed into account. But I fail miserably all the time :(

I think one of the problems is that the hobby servos have a massive slop in the gearboxes. At a normal stance you can wiggle the legs +-1cm sideways, all is gearbox slop.

Now I could either redesign and gear down the hip join to reduce the slop, or make a very advanced control algorithm that takes the slop into account, or release the AI and see what it comes up with :)

I would have to construct something to automatically get it back on its feet when it falls over...

jim lee
05-07-2020, 08:57 PM
That is incredibly cool!

Why not just add a passel of Teensys? Then you can bust up the coding making it easier to write and faster to respond, and you end up with more pins that you'd ever need.

-jim lee

05-26-2020, 04:36 AM
This project was posted on the blog. Still on the main PJRC today.


06-01-2020, 08:02 AM
Great job!

06-04-2020, 03:56 AM
The skeleton is the same. It looks interesting.

06-04-2020, 06:49 AM
This project was posted on the blog. Still on the main PJRC today.

Thanks for this link, it is very interesting to watch the video!

06-30-2020, 06:19 AM
Very cool, I also study machine learning in python, but I can’t even imagine how to translate all this into a robot in real life.

06-30-2020, 09:09 AM
I forgot to ask, and do you have a video where does he go?

07-10-2020, 04:45 AM
Hello, how are you? ... I am an electronic engineering student at TECNM, and I see your project very interesting. I would like to develop it for academic purposes.
If you are willing to help me, I would appreciate if you can provide me with the diagrams that were used, and the 3D designs of the components.
Thank you in advance, and your help will be very helpful.