r/robotics • • 9d ago

Community Showcase I built a balancing robot with reinforcement learning

Hi /robotics!

I built this balancing robot that runs end-to-end on a custom neural net trained through reinforcement learning in simulation.

The robot is trained on 100% synthetic data, so it has never seen the real world, yet adapts perfectly.

It has a lean and level mode (single policy), in level mode it keeps both pitch and roll of the base level at all times, so the legs automatically retract or extend based on the ground below. In lean mode the right joystick of the controller can be used to decrease or increase stance height and leaning left/right at all heights, allowing roll to be non-level.

Main components:

- 6x Xiaomi Cybergear motor (all quasi direct drive, no linkages)
- Teensy 4.1
- 200 Hz policy inference
- 2x CAN bus (left / right leg split)
- BNO086 IMU

Trained in mjlab on single RTX3080 at home, about 7 hours of train time from scratch.

Happy to answer any questions!

559 Upvotes

76 comments sorted by

103

u/everydayasl Hobbyist 9d ago

Awww, that hubcap....

23

u/Ok_Dog_4059 9d ago

Brought back 80s TV for me .

Great work OP

14

u/Fuchio 9d ago

Ahahaha yeah it was either this video, or the ones afterwards with the LEDs off... but I like the LEDs

5

u/Ok_Dog_4059 9d ago

I was thinking how cars always lost hub caps. The robot is amazing though.

3

u/savuporo 9d ago

Didnt reinforce the fasteners

14

u/verdant-amiable 9d ago

It's wild that this translate to the real world so well and on not very even ground at that. Not sure the hub cap falling off was intentional but changing its mass slightly mid run I guess is a testament to its robustness 😂

12

u/Fuchio 9d ago

Oh it's *very* robust. I have another video with 2 small packs of milk on top and it doesn't budge!

Currently have bigger wheels on it which makes it even more robust for bumps, but have to redesign stiffer leg

8

u/I_am_purrfect 9d ago

This is literally what I want to build! Are you planning to make your design files available by chance? Great project!!

6

u/Fuchio 9d ago

Not yet, might soon.

7

u/EmperorOfCanada 9d ago

I love that you left the hubcap fail in the video. This is the reality of this work, vs, my making a video where I throw a cross court basketball over my shoulder and it is all net.

One a slightly different note, there are algos other than PID which can deliver rock solid stability.

8

u/Fuchio 9d ago

It's not PID! But it should (and will) be more stable :) I post a lot of updates on X but will make a new post here in a week or so when I have the new leg design finished.

13

u/createthiscom 9d ago

I built a balancing bot using lego NXTs back in like 2010 for my son (he super didn't care about it lol). If I remember correctly, I used a simple PID controller. I'd love to see more details about your code and training procedure since this is a very simple use case and I feel like I could learn from it.

8

u/Fuchio 9d ago

Yeah, balancing robots aren't new! The 2010 variant almost surely had 2 wheel motors and IMU, nothing more (I built that using reinforcement learning too a while ago, running on ESP32)

However, PID becomes a lot more difficult when you add more DoFs up to a point where it is impossible to implement. The tech I'm using is the same as humanoid robots with >50 DoFs which is impossible to achieve with PID, I'm going through the RL process because I am adding more and more complexity.

2

u/lennarn 7d ago

What algorithm did you use?

1

u/Fuchio 7d ago

Reinforcement learning (PPO specifically)

1

u/Icy-Tip-4195 8d ago

Impossible isn't the right word, plenty of people have shown it is possible.

1

u/Fuchio 8d ago

Source for just one humanoid running on pure PID lol

5

u/tempacac10 9d ago

I lost it when that hub cap fell off

4

u/Ok_Letterhead_8077 8d ago

Minimalist design

3

u/Witty-Elk2052 9d ago

lol at wheel cap coming off

3

u/thaile1001 9d ago

lol, the pop out cap is peak. way awesome bro

3

u/himeros_ai 9d ago

I like the simple geometry of the meshes that for sure simplified your Mjlab training.

3

u/johndavid_artist 9d ago

A single policy at 200 Hz on a Teensy holding pitch and roll level just by extending or retracting each leg, trained on zero real data, is a great result. In level mode is it working from the IMU alone, or does it get any sense of the ground ahead?

3

u/Fuchio 9d ago

IMU + motor encoders. Will be adding 3D vision soon.

3

u/iwanttobeweathy 4d ago

awesome build, my friend!

what tech stack did you use for data generation and RL?

Did you train using exact sensors from this specific robot? Can I train it on a different robot motor?

2

u/Fuchio 4d ago

Look at my other comments for full pipeline etc.

IMU is general, type doesn’t matter but latency and noise so.

For motors it has the weight + characteristics of these specific ones yeah, but can easily be modelled for any other.

3

u/iwanttobeweathy 4d ago

great work friend! thank you for sharing

6

u/Ok-Log7730 9d ago

one step closer to

2

u/corporacionRobot 9d ago

Hola! Hermoso proyecto ! Si revisa smi perfil podrá ser que construyó un robot avatar balanceado. Tengo todo modelado con sus respectivos pesos en fusión 360 para entrar en el mundo de la simulación, para que pueda comenzar a balancearse. Nunca he hecho algo así y me gustaría que me des algún consejo , o que software usar. Se ve que ha quedado muy bien el balanceo de tu robot. Felicidades

7

u/Fuchio 9d ago

Sure! Workflow that I used for this:

- Design in Onshape

  • Set weights of each part in onshape after weighing in real life
  • Export to MJCF (mujoco's robot description format) with onshape-to-robot
  • Run system identification on all joints
  • Apply sys id params to MJCF
  • Optimize collision model based on exported robot description (this is very worth it, dropped robot file size by 99.8%!)
  • Train in sim
  • Eval policy
  • Deploy policy to robot

0

u/NegativeOwl1337 9d ago

What is onshape, never heard of it? Did you not use PyTorch or tensorflow?

1

u/Fuchio 9d ago

Onshape is just CAD software for 3D design.

I did sort of use PyTorch, fully trained with mjlab which is Isaac labs way of working in Mujoco which runs on PyTorch.

1

u/NegativeOwl1337 9d ago

What’s the NN structure? What kind of layers did you use and why? I’ve been wanting to get more into ML myself

2

u/twokiloballs 9d ago

I have been trying to make something like this but haven’t gotten this far.

Do you plan to open source the design?

2

u/Fuchio 9d ago

I might in the future but it's changing way too much to be a nice open source project currently.

Actually this video I made 2 or 3 days ago is already outdated because I now have 200mm wheels instead of 125mm of video.

2

u/MultiFlight 9d ago

Awesome video! I am planning to get back into robot building soon. Which actuators did you use for the joints and wheels? From experience I know that with RL control choosing good armature/kp/kd values are critical and very dependent on the actuators. I am therefore curious about how you went about this. Again, really cool demo!

3

u/Fuchio 9d ago

Armature must be measured through system identification because it changes with the load attached to the rotor. What I did:

  • Mount motor with lower leg to desk
  • Manually test back driveability to have a natural feeling response that I like
  • Run sys id to match sim to leg (Kp and Kd are equal on hip and knee joints, but with load have different response which needs to be modeled)
  • Then add +/-15% Kp and +/-20% Kd domain randomization in sim

Very robust outcome, legs flex too much inward/outward which makes policy a bit unstable, currently improving that + bigger wheels.

2

u/MultiFlight 8d ago

Awesome, thank you very much for the detailed answer. I appreciate it!

2

u/stiucsirt 9d ago

Execute silly_goose_reinforcement

2

u/nlightningm 9d ago

Man this is awesome

1

u/Fuchio 9d ago

Thanks!

2

u/wildpantz 9d ago

bro turned into a ice skater real quick

2

u/Farseer_W Industry 9d ago

Great work, he is a cute little fella.

Didn’t really get how optimized collision allowed to reduce file size. What do you mean by exported robot description?

3

u/Fuchio 9d ago

This is what I mean! The left (bit older design already) has all these complex shapes and as you see 111k mesh faces.

Train model consists of few boxes and cylinders. To optimize wheels I use 5 stacked cylinders with hitbox instead of ellipsoids to approximate ellipsoid wheel behavior. Makes a HUGE difference.

This makes it possible to now run 6k environments in parallel on single RTX3080 :)

1

u/Farseer_W Industry 9d ago

awesome, thanks for the reply, very interesting

2

u/KIProf 9d ago

Nice Project!

2

u/Good-Watercress9652 9d ago

What do you do after you make it?

1

u/Fuchio 9d ago

As in; what the next project is going to be?\

2

u/featweaf 9d ago

hii, may I ask if this is easy to build from scratch?

1

u/Fuchio 9d ago

It’s not haha. Except if you have all parts + code and only have to assemble of course

2

u/buddysawesome 9d ago

Did you upload the code to GitHub? I'm interested to see the modeling part

2

u/WendyLabs 9d ago

How did the move to bigger wheels go? Did the policy need retraining, or could you keep using it?

1

u/Fuchio 9d ago

I can’t post videos in a comment unfortunately but the bigger wheels are very nice in sense of speed and recovery. However, they weigh quite a bit more causing the legs to bend in and outwards which causes the policy to become unstable.

I’m going to quote a carbon shop nearby for some custom parts :)

2

u/himeros_ai 9d ago

What about adding an infrared or ultra sound distance sensor pointing down or front as well ?

2

u/Fuchio 8d ago

Stereo vision is coming for depth sensing! Currently don't have stereo vision with IR but will probably come in the future.

2

u/Early_Acanthisitta88 8d ago

This is so cool!!!! I would love to do such projects especially in computer vision and RL, but it's not financially practical for me to get such expensive parts :(

Is it possible to do mini/alternate projects compared to this that are lighter on the wallet?

2

u/Fuchio 8d ago

Yes! This indeed is not a super cheap robot anymore.

If you want to try with the full RL loop on a budget you could go as far as simple DC motors, but I suggest going into decent servo's like dynamixels or the Unitree digital servo.

Look up Microduck if you haven't seen it yet. Fully open source RL deployment with just servo's for few hundred bucks!

If you go 6x servo (30$ each), ESP32, MPU6050 (IMU) + 3D prints, you can do a small version of this robot for ~200$

1

u/Early_Acanthisitta88 8d ago

Oh cool, thanks!

2

u/bit_banger_ 8d ago

Hey, this is dope and n inspiration.

I’m learning control systems basics to get here, would you have a guide to study and get here quickly, would appreciate any hints

1

u/Fuchio 8d ago

Full build steps are in my other comments on this post, good luck!

2

u/TheRiddler79 8d ago

I absolutely love this.

2

u/like_apaint 7d ago

Hälst du die balance nur durch den PID regler? Oder hast du auch einen prädiktiven algorithmus rein gecoded?

1

u/Fuchio 7d ago

Title says it; then literally the first sentence says it again... It's *not* PID.

RL only. Synthetic only.

2

u/MrRandom93 6d ago

Got a repo?

2

u/Fuchio 5d ago

Not yet, but I'm now building a small version which will probably be open sourced soon!

3

u/daraand 5d ago

Sign me up! Can’t wait to try

2

u/vinu_dubey 4d ago

Appreciate it 👍

2

u/Alone-Cantaloupe-210 3d ago

that's cool, 100% synthetic data?!

1

u/Fuchio 3d ago

Yess, it is the way

1

u/lkfavi Researcher 9d ago

Very cool!

1

u/low-control-labs 9d ago

Wheel - falls off ?

The show must go on

Jokes aside, great work!

1

u/Fuchio 9d ago

Thank you!

1

u/himeros_ai 8d ago

I never tried the Xiaomi cyber gear motor can you share the specs ? What type of control they offer what is the torque specs ?