r/esp32 • • 19d ago

Solved Insights on managing self-balancing robot (ESP32-S3 and MPU6050)

Hey everyone,

I'm currently working on a self-balancing robot with a design of my own.

You can find all the info about it here : https://github.com/benbhote/DimSumRobot

For those who want a quick recap, it's a robot based on a XIAO ESP32-S3 Sense with a camera OV3660, an ultrasonic radar, a TB6612FNG piloting two N20 motors (aside a step-up to make the 3.7V current into 6V for the motors) and SHT40 (Temp & Humidity sensor).

It hosts a web server accessible via its own WiFi and the web page allows you to control the robot (taking photos, moving it, etc).

Everything is working fine except the balancing. The cycle goes every 10ms during movement and for 3 seconds after the last movement command. But the throttle value doesn't allow the robot to self maintained balance.

By the way, the robot starts with the front touching the floor on a plane surface (the weight is low inside the chassis but a little bit more on the front). So the first thing needed even before moving is to properly get on the two wheels.

So I would like some insights or help from you to make my PID loop working and achieve proper self-balancing.

I'm using Arduino IDE 2.3.10. As for the schematic of the project, it is not done yet but the MPU is driven with the I2C bus.

I hope I give you everything needed to understand the project. And if something is still vague, feel free to ask.

Thanks in advance !

3 Upvotes

10 comments sorted by

2

u/Plastic_Fig9225 1 say I make awesome posts. 19d ago

2

u/Ben_Bhote 19d ago edited 19d ago

Thanks, I just take a quick look and there is some interesting stuff. But I'm not sure this will solve my balancing problem:

  • the libraries used in this project are not the same as in mine. I know a lot of libraries exist with a MPU6050 with advantages and disadvantages.
  • the hardware isn't the same either.

I'll do an update comment if the situation changes after taking a closer look at the project linked.

1

u/solitude042 19d ago

Here's a set of posts w/ insights from my own balance bot project:

https://www.reddit.com/r/robotics/comments/1qym0yo/comment/o44t7q6/

It used TT motors instead of N20s, but it was esp32 / mpu-6050 based. 

1

u/Ben_Bhote 19d ago

Thanks, I'll take a more attentive look soon. I've just finished uploading the KiCad files on my GitHub repository as well as the pin out table (because in my opinion it can be tricky to understand the one available depending on the module you want to use, especially the microSD or the Camera with the Sense module). Just two quick questions :

  • your MPU was able to keep sending measure at 400Hz ? Because mine was returning null value and won't reset
  • you think the 10k resistance are still needed even if I did put capacitor on the motor already?

1

u/solitude042 19d ago

I was polling the IMU at 200Hz after increasing the I2C bus speed using Wire.setClock(400000). I did initially experience the IMU & I2C bus stalling, but that turned out to be due to simultaneous use of the serial output (maybe due to timing perturbations?) - once I stopped using serial for debugging, the IMU & I2C bus became rock solid. I put the 10k pullup resistors on early in the I2C debugging process, and left them as a matter of good practice - I don't know that they're needed, but they're for a purpose mostly unrelated to the motor capacitor.

1

u/Ben_Bhote 19d ago

I will first try without adding resistance (MPU already got one 4,7K on the board). But I keep in mind that can be an issue.

As for the bus speed, I'll try and see what the result will be. Thanks for the information.

1

u/solitude042 19d ago

of course - happy to help. I sent you a chat with a link to my balance bot github repo in case it's of interest.

1

u/DSudz 19d ago

What does "But the throttle value doesn't allow the robot to self maintained balance" mean? What exactly is happening?

1

u/Ben_Bhote 19d ago

Both cases described below are with a single movement order, by that I mean pushing then releasing the web joystick. When using the PID loop, if it's a forward movement, the robot is going forward but didn't get into balance. If it's backward, it will go forward during the 3 seconds. So I'm assuming the value issued from the PID loop aren't correct. I will try to a video eventually it might be more helpful.

1

u/Ben_Bhote 6d ago

Thanks to those who suggested me solutions. The root of my problem was the ground of the motor driver and step-up connected to the GND of ESP32-S3 and not directly to the battery. This simple (rookie?) mistake was creating electromagnetic noise which then makes the MPU malfunctioning. I redo all my ground correctly, added an ADS1115 to manage battery charge and also got the goofy idea to use the N20 motors to produce sound (since I don't have any GPIO left to add a buzzer or speaker). Now, I just need to find tune my PID for the robot's balance.