Personal Project: BLDC Self-Balance Bot

I. Intro

Date: August 2024.

A brushed DC motor with reduction gears has inevitable gaps between gears, and this can result in inaccurate actual speed readings from a low-resolution encoder, such as Hall effect sensor. BLDC motor, 12bit AS5600 encoder, and Field Oriented Control (FOC) can solve this problem. Still, I used cascade PID to to the control loop.

The code, CAD model (STL), and circuit schematic are on GitHub: Brushless-Self-Balance-Bot-FOC

II. Velocity Control and Position Control with FOC

Since the encoder AS5600 and the motor are separated, I need to build something to put them together, so I just started building the self-balance bot.

Figure 1: print the wheel hub
Figure 2: remove the supports
Figure 3: remove more supports
Figure 4: put on the tire
Figure 5: install the motor by press fit. It’s easy to push it in and requires a hammer to knock it out.
Figure 6: install the magnet by press fit, no superglue required
Figure 7: install AS5600 encoder
Figure 8: push the three phase wires through the hole and install the motor to the frame
Figure 9: solder the wire for MPU6050
Figure 10: solder the wire for two AS5600 and one MPU6050. The circuit was already tested.
Figure 11: install the driver board
Figure 12: connect AS5600
Figure 13: done.
Figure 14: testing two AS5600 and one MPU6050 with two I2C bus
Figure 15: looks like this board doesn’t support high current motors with 0.1 ohms resistance. It only supports gimbal motors with resistance of 10 ohms. I asked sellers and they don’t even know what kind of motor their board supports.
Figure 16: so I had to find a new driver board and design a new one. Since I am going to use jump wires so I left some space for them.
Figure 17: I used the old frame as the test stand to test position control and velocity control
Figure 18: it’s getting warmed, but not crazy hot.
Figure 19: there’s noise when velocity is positive, higher the velocity, louder the noise, but there’s no noise at all when it’s negative
Figure 20: CCW is -20 rad/s, and CW is 20 rad/s with noise
Figure 21: I plotted Ualpha and Ubeta, and found that the frequency when rotating CW is a little bit smaller than the frequency when it’s rotating CCW, so the problem is from the electric angle.
Figure 22: to solve this problem, the electric angle offset must be set correctly.
Figure 23: only use electric angle here, not electric angle plus the offset
Figure 24: then reverse the sign of the PID gain value
Figure 25: change the frequency from 10kHz to 30kHz so human can’t hear the high frequency noise, then reduce the PWM resolution to 11 so that Freq*2^res<=80MHz
Figure 26: after fixing the noise problem, the velocity control and the position control are tested. But the noise still exists when the speed is over about 40 rad/s
Figure 27: and then I was trying to measure the current and do the current control, but the ESP32 ADC shows a sine wave when I am holding the motor to a position and the current is direct.

III. Print and Assembly

Figure 28: print the parts
Figure 29: remove the supports
Figure 30: bottom side
Figure 31: install motor and MPU6050
Figure 32: install AS5600
Figure 33: connect the MPU6050
Figure 34: connect the LEDs
Figure 35: solder the 6 pin headers for the sensors onto the breadboard
Figure 36: solder everything onto the breadboard carefully.
Figure 37: after using a DMM to test the circuit, it’s ready to power up for the first time. No smoke, good.
Figure 38: install the LEDs
Figure 39: put on the color cover, but the green light is much dimmer
Figure 40: so I reduce the top layer thickness, it’s still dimmer than the yellow one, but brighter than before
Figure 41: you can still see the special infill pattern
Figure 42: assembly done, front view
Figure 43: assembly done, back view
Figure 44: assembly done, bottom view
Figure 45: testing the circuit after the assembly is done. I connect a DPST switch with the enable gate, so I can control the on and off from both the code and the mechanical switch.

VI. Stand Up

Figure 46: it stands still because it get stuck at some weird positions. I guess it’s the USB cable behind it is holding it.
Figure 47: I just roughly tune the PID, and it has decent stability already.
Figure 48: the next day, I finly tuned the PID many times, and it’s much more stable than what’s shown in the previous video.
Figure 49: stability test wih position control. Later on I found that the position control didn’t work that well, so I add a switch on the Bluetooth control to enable/disable the position control. All videos after this one has no position control.
Figure 50: standing still, it’s barely moving.
Figure 51: standing still with Bluetooth control test
Figure 52: stability test without the position control,
Figure 53: I guess it’s due to the dynamic property of a pendulum, it needs to tilt to accelerate, but stay level at a constant speed, so it oscillates back and forth sometime. It falls because the wheel reached the maximum speed, and can’t accelerate anymore. This limit might be from the PID output limit and/or the commutation problem at high speeds

Leave a Reply

Your email address will not be published. Required fields are marked *