BuildRobotzRobotsTailwhip
Tailwhip.
BuildRobotz project · Overview

Tailwhip, the robot that sits on its tail

A two-wheeled balancing robot built from the hobby parts in most robotics drawers. It rests on its tail, rears up onto its wheels, balances, looks around, and lands on its tail when you shove it. You train its brain with reinforcement learning in MuJoCo on your laptop, then run it on the real robot.

On this page
  1. The robot
  2. Why this is a good robot to learn on
  3. How it works, in one picture
  4. Sister project
Simulation, trained policy
The trained policy in MuJoCo, on the simulated robot with its sloppy gearboxes, coarse encoders and radio delay. Rest, rear up, balance, drive, turn, take two shoves, lie back down. Nothing is scripted except the commands.
Wheels
2 × TT gearmotor
Servos
2 × SG-90
Mass
about 396 g
Height
264 mm
Parts
about $62
Brain
52 → 64 → 64 → 3
Rears up (sim)
84 %
Read this first: AI-generated, not yet builtThis design, its code and these pages were generated with AI, and nobody has built or tested a physical Tailwhip yet. The CAD, simulator, trained policy, firmware and print files are complete and checked numerically, and every performance number here comes from simulation. Treat it as a well-worked starting point: measure the parts the pages tell you to, check each step as you go, expect to fix things, and build at your own risk, especially around the 18650 cells. The Limits page lists what to measure and watch.

The robot

Tailwhip is a small two-wheeled self-balancing robot with a tail and a camera head. It is 264 mm tall, weighs about 394 g, and is made from the parts most robotics hobbyists already have in a drawer: two yellow TT gearmotors, two SG-90 servos, an ESP32, an MPU6050 and two 18650 cells.

It reads as a creature, not a machine. Switched off, it sits leaning back on its tail like a kangaroo. Told to stand, the tail pushes down and it rears up onto its two wheels. It balances, looks around with its camera head, and drives. Shove it hard and it can't catch itself with the wheels, so it lands on its tail, which was waiting for it, and gets back up. Shove it forwards and it lands on its feet.

Your first 30 seconds with a finished robot. Power on and run python host/drive.py PORT: it drives around on its tail with the arrow keys. Press p and the hand-written PID controller holds it upright if you lift it there yourself. Then run python host/run_policy.py PORT and type stand: the trained policy pushes down with the tail, rolls the wheels back under the body and rises. Getting from "PID balances when I hold it upright" to "it gets up by itself and survives a shove" is what the rest of the project teaches.

Why this is a good robot to learn on

Plain balancing on two wheels is a solved, hand-written control problem: a PID loop on the tilt angle does it. Tailwhip is built so that the interesting part is everything around that loop, which is hard to write by hand:

  • Rearing up needs the tail and both wheels to move together, with a servo that has only twice the torque it needs.
  • Deciding when a shove is too big for the wheels, and letting the tail take it instead.
  • Getting up off the feet needs a quick push of the wheels at the right moment.
  • Sloppy parts: TT gearboxes with several degrees of backlash, encoders that can't tell forwards from backwards, a radio link with 10-40 ms of delay.

Those are exactly the things reinforcement learning is good at, and exactly the things that make simulated robots fail on real hardware. The simulator here models every one of them on purpose.

What you will learn by building it.

  • Mechanical design: a parametric CAD in Python, a printed leaf spring, and checking a design numerically before printing it (including the fall problem the simulator caught, on the Mechanical page).
  • Electronics: a 2S 18650 pack with a protection board, two buck converters, an H-bridge, I2C sensors and an ESP-NOW radio link.
  • Control: a PID balancer you tune yourself, as the baseline.
  • Simulation: a MuJoCo model built straight from the CAD, with the motors, servo and sensors made as bad as the real ones.
  • Reinforcement learning: observations, actions, rewards, PPO, and evaluating over hundreds of randomised robots.
  • Sim to real: bench measurements that feed the simulator, then running the policy from the laptop and finally on the ESP32 itself.

How it works, in one picture

The robot's ESP32 reads the IMU 500 times a second and estimates its tilt. 100 times a second it sends a state packet over ESP-NOW to a second ESP32 plugged into your laptop. The laptop runs the policy, a small neural network (52 inputs, two layers of 64, three outputs), 50 times a second, and sends back two wheel commands and a tail angle. If the commands stop for 100 ms the robot cuts the motors and puts the tail down. Once the policy works from the laptop, you export it to a C header and it runs on the robot with no laptop at all.

Sister project

Tailwhip follows Ouro, the worm that bites its own tail and rolls away: same toolchain (Python CAD, MuJoCo, PPO, ESP32 + ESP-NOW), same way of documenting. If you have built Ouro, you will recognise everything here.

Build it, page by page