Log 20: The first learned walk

· A build log for LocksleyFox, a home-built robot dog

This log covers two days. On November 13 LocksleyFox learned to stand from any pose, took its first scripted steps, and got a motion sensor. That evening it ran a walk trained in simulation for the first time. On November 14 that walk went from trotting in place to walking off the mat and across the floor. Then all the electronics moved onto one board, so the robot no longer needs a USB cable.

The gray printed robot mid-step on a wooden floor, its front-left paw reaching past the edge of a black mat, with red and black wires trailing from the body
Walking off the mat and across the floor, the last run of the day

Standing up from any pose

In Log 19, Stand refused to start whenever a leg had folded past its limits. After Sit the motors ease off, so the legs end up wherever they fall. Now Stand works from any pose. A leg that can't move straight to the stand pose unfolds one joint at a time instead. Before flashing it, I ran the stand in a test program from 200 random starting poses, and every one stood up.

There was also a surprise after a power cycle. The motors report their angle within one turn. Two joints whose range crosses that wrap point came back a full turn off, and the control panel then deleted their saved limits. The firmware now picks the turn nearest the middle of each joint's limits, and the panel never deletes saved limits.

First scripted steps

Next came a simple walk that I wrote by hand. It's a crawl, where one foot lifts at a time. Before each lift the body slides forward or back so the weight sits inside the three feet still down. A new Settle button also evens out the load on the four paws by adjusting each leg's length a few millimeters.

Two things went wrong along the way. When the 48 V supply was cut while it stood, the robot dropped onto the carpet. Later, on the second step of a run, the front bus filled with errors, one knee went silent, and the front legs switched off and collapsed. After I reseated the connectors, seven step runs in a row finished with no bus errors at all.

A motion sensor

A walk needs to know which way is up. I taped an Adafruit ISM330DHCX to the floor of the body. It's an IMU, a small board that measures tilt and turning speed. Tipping the robot nose down and then onto its side confirmed the axes were the right way round.

Top view of the robot on a gray rug with the legs folded, a breadboard and lever connectors in the middle bay, and a small taped board with a green light beside the breadboard
The IMU taped in the middle bay, green light on, next to the old breadboard

The learned walk on the Teensy

The real walk comes from simulation. A small neural network, the walker, learned to trot in MuJoCo by trial and error. It reads the joint angles, the IMU and a speed command, and it sets new targets for all eight motors 50 times a second. To fit it on the Teensy I stored its weights as 8-bit numbers. One step of the network takes 2.7 ms, and it walks the same as the full-size version in simulation.

On the evening of November 13 I tried it with the robot on its stand and the legs in the air. Two runs of 20 and 31 seconds went cleanly, with no errors on either bus.

The robot on its printed stand over a green towel, legs in mid-trot in the air, with red and black wires running down to the floor
The first learned walk, on the stand with the legs in the air

On the floor it lasted a fraction of a second. Within 0.2 s of the first steps both buses logged errors, and the rear bus shut itself off. With four motors gone, everything eased off and the robot folded. The legs also stepped very fast, about 2.7 steps per second even at a slow walk, because the walker was trained with that rhythm.

A day of floor tests

The first floor runs on November 14 used the same walker. They took lots of steps but went nowhere. The robot trotted in place, and the back-left foot barely lifted. With a multimeter on the front for extra weight, it spun in place instead.

The robot trotting on a black mat laid over a green towel in a sunny room, a white rug behind it and wires leading off to the right
The morning runs. Lots of steps, but going nowhere

Meanwhile I trained a new walker. It steps more slowly at low speed, about 1.9 steps per second. During training its weight moved around the body and it carried up to 2 kg extra, since the real robot is heavier at the back. It also takes a turn command, so the Teensy can use the IMU's gyro to hold a straight heading. I trained two versions at once, one on a laptop and one on a Mac mini. Before flashing, I ran both through software in the loop, where the real firmware code drives the simulated robot. The version that kept more speed with the weight at the back went onto the robot in the afternoon. It still turned to the right.

I worked through the easy suspects first.

  • The mat was sliding on the towel under it, a bit like a treadmill. I took the towel out and taped the mat to the floor. The robot turned less but still stumbled.
  • Holding the cables up, in case they were pulling it back, made no difference.
  • A faster motor current loop made no difference either.
  • The Teensy now records the walker's inputs and outputs 50 times a second. Played back in the simulator, the real joints followed the walker's targets within about 1°. The same targets still walked the simulated robot on a slippery floor. So the motors and the floor grip weren't the problem.

The real problem was leg length. With the robot standing in the air, I measured each leg from the hip to the paw with a ruler. The front-right and rear-left legs were about 25 mm longer than the other two. Most of that came from the TPU paws, which were pushed onto the legs to different depths. The scripted stand already corrected for this with Settle's offsets, but the walker ignored them. So it leaned on the long diagonal pair every step, and a foot that should have lifted was carrying weight. In simulation, a leg error of only 11 mm drops the walker from 0.42 m/s to 0.04 m/s.

The walker now builds each leg's offset into its leg calibration. I set the offsets from the ruler, then let Settle fine-tune them. They came out at +12.8, −13.8, −11.8 and +12.8 mm for the front-left, front-right, rear-left and rear-right legs. Settle also got calmer. It used to swing past the balance point and give up, so now it halves its step each time it overshoots.

The robot mid-trot on a black mat taped to a wooden floor, one front paw lifted, with a bench supply and books in the background
The first run after evening out the legs, at 3:57 pm

The next run was much better. The body rocked far less, though it still drifted right about 40° in 8 seconds.

Around 3 pm, before that run, the front-left knee motor jammed while I was handling the leg with the power off. I swapped in a spare and emailed the seller about a warranty replacement.

Across the floor

Two more safety features went in. If the robot is picked up while walking, it sits and eases off. The knees carry about 3.6 N·m while standing and nearly nothing when lifted, so that's easy to detect. I tested it by lifting the robot mid-walk, and it sat down within about 2 seconds.

At 4:18 pm the robot was walking well when the power lead came loose, and all eight motors lost power at once. At 4:23 pm it walked off the mat and across the wooden floor. It covered about 0.9 m in 3 seconds. That's about 0.3 m/s against the 0.5 m/s I asked for, including a one-second ramp up. When I picked it up, it sat down on its own.

One board for everything

Until today the Teensy sat on a breadboard, with a Waveshare CAN board for each bus wired to it by jumper wires. One of those boards was badly seated in its breadboard, and touching it caused bus errors. That may be part of what went wrong on the first floor run.

All of that is now replaced by an SK Pang Teensy 4.1 Triple CAN board. It has three CAN transceivers built in, each with its own screw terminal. The front legs go on one terminal and the rear legs on another, and the third is spare. The IMU plugs straight into the board's small I2C socket. With all eight motors connected, a scan found every one, with no faults and no bus errors.

Top view of the robot on its back on a black mat, legs folded, with the middle bay holding a silver finned converter, taped boards, lever connectors and green screw terminals on a blue board
The middle bay with the new board and the 48 to 12 V converter, no breadboards left

A 48 to 12 V converter now powers the board from the robot's own supply. The board runs on 7 to 24 V and makes the Teensy's 5 V itself. So the Teensy keeps running with the USB cable unplugged. A new cable-free mode uses that. If the control panel goes quiet, the robot keeps standing or walking. If it's picked up, it sits. If it's held face down, it eases off in place.

Close-up of the middle bay with the finned silver converter at left, taped modules in the middle, yellow and blue wires into green screw terminals on a blue board at right, and a USB cable plugged in
The converter, the taped-down modules, and the CAN wires going into the board's screw terminals

One catch with this board is that the USB 5 V and the board's own 5 V are joined. With USB plugged in while the converter is on, the two supplies are tied together. The fix is either a USB adapter that blocks the 5 V line or cutting a small pad on the board.

Sit also changed. On the floor, a Sit at 7:20 pm ended with the knees still holding about 4 N·m, because the belly hadn't reached the floor yet. When the motors eased off, the body dropped the rest of the way. Now the feet keep pushing up slowly until the knees carry almost no load, so the belly is resting on the floor before anything lets go.

Paw shapes in simulation

In the background, the simulator has been testing paw shapes for top speed. The current flat paw tops out around 1.65 m/s. A paw with a curved, rocking sole, a slightly soft contact and a longer toe averaged 2.02 m/s over three training runs. The next paw is already sliced for printing.