Self-Balancing robot

Im trying to build self balancing robot. Later I used PID and simple DC motor. I want to try do it with BLDC and simpleFOC. Can you give me advice how can I do it? May be something have similar project. Thank you

Hi there, sounds like a cool project!

Its not exactly the same thing, but a similar kind of project is already in the examples of SimpleFOC: https://docs.simplefoc.com/simplefoc_pendulum

Personally, I would order one of these BGC 3.0 controllers
It costs only about $10, is programmable by Arduino IDE, and can drive 2 brushless motors. It also comes with an MPU6050 3-Axis Gyro/Accelerometer sensor, which connects via I2C, and which you will need for the balance-bot.

To use the BGC board you have to first flash an Arduino Bootloader on it, which involves soldering a header. After that it should be manageable to write a firmware with 2 SimpleFOC motors and the Gyro sensor, following an existing balance bot algorithm…

Let us know how it goes! It would be cool to see pictures of your bot when it takes shape!

1 Like

Hey @German_io,

I’d love to see the first balance bot with SimpleFOC. You’re going to have a great time moving away from the backlash, noise and slowness of geared DC-motors :smiley:

For my Control of the Ball and Wheel System - applications - SimpleFOC Community I used a closed loop brushless in voltage control mode and used my own control algorithm. I would suggest you do something similar.

Funny timing :slight_smile: I have managed to get my own self-balancing robot (pretty much) balancing in the last couple of days. It uses SimpleFOC (openloop-velocity mode) running on a 2-channel BGC gimbal controller connected to 2 gimbal motors, a 3d-printed frame and second arduino running the PID controller connected to a BNO055 IMU. Next steps are adding 2xAS5600 encoders and enabling proper FOC so I don’t melt the motors at low speed.

Link: https://youtu.be/OLmSPBEftPM

Not sure yet but I might eventually replace the gimbal controller with 2x B-G431B-ESC1 connected over CANbus but the gimbal controllers are cheap and work eventually.

I haven’t opensourced anything yet (there are a lot of other examples out there) but let me know if you have any Qs and I will be happy to help you out if I can.

3 Likes

I’m also building one :smiley:
I think this is going to be a very cool race :cowboy_hat_face:

1 Like

If you have some working code for B-G431B-ESC1 using canbus, I’m interested :nerd_face:

Cool I’ll let you know as soon as I have something :slight_smile: I managed to get everything installed and hooked up last night using my existing gimbal controller and some AS5600s via an i2c multiplexer but ran out of RAM on the ATMega 328P once I added sensors to my current code. I think I can probably try the trick @Antun_Skuric mentioned elsewhere to replace the _sin, _cos lookup tables with the native sin, cos functions to save RAM but I might just bite the bullet and get the B-G431B-ESC1 working instead. I kind of like the idea of having 1 motor controller per wheel and maybe use the 2&3 channel gimbal controllers for things like arms and grippers.

1 Like

I’m also. :slight_smile:

6 Likes

Can you share the code?

I’m impressed, once again!
lI’m hoping to have as good results, I’m not far as well. :smiley:

I’m basing myself of two SimpleFOCShields, nucleo and mpu6050.

2 Likes

@Rem666 I watched a bunch of your videos on YT a week or two ago. Some cool projects there :slight_smile:

Looks great @Rem666 is definitely the king of balance bots!

Do you have an angle (from imu6050) pid loop feeding straight into voltage control mode?

Yes. In voltage control mode motors works as DC motors. No difference.
I also tried in velocity control mode. It works. Maybe today I will make video what difference, and why I did change to velocity control mode.

6 Likes

I do not have as nice videos as you do @Rem666, but I am very happy with the results.
Once I have it properly tuned and configured I’ll make sure to share the code and the build. Because it is certainly one of the simplest balancing robot hardware/sotware combinations I’ve made so far. Much simpler than the stepper balancers I’ve done in past and much better dynamics than both steppers and dc motors :smiley:
Here is a quick preview.

Basically I use:

  • Stm32 nucleo f411re
  • 2x SimpleFOCShield
  • 2x atm103 cui encoders
  • mpu6050

The libraries are i2cdevlib + simplefoc v2.0.1.
The motors are in the voltage mode and I use two PID controllers. One for stabilization and one for velocity.

1 Like

Good result. Interesting place of mpu6050 :slight_smile:
I use LQR.
Steppers with microstepping also works good. Only lower RPM.

Nice. We have a few balance bots!

I’m doing some work in this area too. I’ll be implementing an IMUSensorI2C.cpp with no dependencies (except Wire) that implements Sensor.h initially supporting mpu6050 but hoping to add mpu9250 support too. This should simplify future balance bots.

I also want to experiment with a CallbackSensor. This is a shell sensor that has a getAngle() callback. We’ve had a couple of requests for supporting new sensors - this might be a way of expanding what SimpleFOC can be used with.

A bit of crash testing :smiley:

I am not sure which is worse, the video resolution or my driving :smiley:

5 Likes

@Antun_Skuric, how are you controlling your balance bot?

I’m using a PI + PID cascade if you were thinking of control structure. I’ll make sure to document this project well in next few weeks and explain the particular approach I’ve chosen in depth.

For remote control I’m using a HC-05 bluetooth miguel and an android app that I’ve made some time ago:

It was made for the project of a stepper based balancer few years ago: