Two-wheeled balancing robot

Status
Not open for further replies.

shukmeister

New member
Hello everyone,

I am a hardware amateur, and am building a robot that balances on two wheels as my first project. This is very difficult for me so I'm running into a few problems.

My robot is built from:
  • Teensy 3.2
  • MPU6050
  • DRV8835
  • HC-05
1) Out of the many open source libraries available, I cannot pick one that works best for a balancing robot.

At the moment, I am using Kris Winer's Library . Is this the right one to use for a balancing robot?
I liked the idea of using the DMP, but couldn't get Jeff Rowberg's Library to ouput anything over serial.
I have also tried TKJ electronics library.
I was a big fan of Barret's Projects Code but he doesn't use a MPU6050 so porting is difficult.

2) Using Kris Winer's library, is it possible to start and calibrate the MPU6050 from a vertical orientation. The MPU6050 must be positioned on the axle of the robot for accurate balance control, but it is difficult to mount it horizontally near the wheels. I've designed a connection to vertically mount it, but the ouput always seem off.
My wiring: http://postimg.org/image/eygsharyl/
Video: https://gfycat.com/TerrificUglyGraywolf (note how the horizontal orientation is 80 and not 90 degrees. also, note that the 0 position is ~2.3 degrees)

3) Why does the pitch not change from positive to negative after crossing 90 degrees?
Video: https://gfycat.com/ShadyLeafyDodo

4) Does changing delta_t impact performance? How often should I call MadgwickQuaternionUpdate()? From my testing, I've noticed that my motors are very slow to react to changes in angle (even when serial debugging output is off).

5) Does the INT pin need to be wired to the Teensy?

6) Do I need to use the i2c_t3 library? Kris Winer's code doesn't use it, but his seems to be the most complete mathematically. I could not find any i2c_t3 examples that use the MPU6050.

7) When hooking the motor drivers up, how do I isolate the ground lines to avoid ground loops? My current setup is included below.
Wiring w/ DRV8835 driver: http://postimg.org/image/r5xkn8a8r/

8) Random aside, what screw size do you use to mount the MPU6050? Most screw heads overlap with the capacitor above the hole

Any help would mean a lot to me :)
 
Nobody here has worked with a MPU6050?

Help with any of these questions would save my project. I've hit a brick wall in terms of progress.

Thank you
 
Well, I would first say that the MPU6050 wouldn't be my first choice for an IMU for a balancing robot. I would use an MPU9250 (or at least the MPU6500, also an Accel/gyro but significantly improved over the MPU6050). Forget about the DMP, it is 6 DoF and not worth the trouble even if you can make it work. With six degrees of freedom you will have gyro drift and therefore yaw drift. It might not matter if pitch and roll are all you care about. Even the MPU6050 can do that pretty well.

So on to your more or less specific questions:

My library is as good as any other, but you should be prepared to go over it line by line in consultation with the data sheet to make sure 1) you understand everything in it, 2) you can configure the sensor to your specifications. Pleased do not assume the library (any of them) is written specifically to match your requirements and that it has no errors of commission or omission. They all have these errors.

You should be able to achieve roll and pitch accuracy to within a few degrees, yaw accuracy not at all without a magnetometer. Without at least bias calibration the sensor data is useless. If you don't know what I mean by bias calibration, start here.

You should not change delta_t, it is a measure of the time between Madgwick or Mahony algorithm calls and is the time integration variable for both. This time will decrease as the processor speed you use increases. The rate output on the serial monitor tells you how often you are iterating on the sensor fusion solution for every new data sample you start with. Ideally you want to iterate four or five times on each new data sample to get a stable fusion result. At the same time you want to limit the bandwidth to about 20% of the sample rate for low noise. So I usually set my sample rates at 200 - 400 Hz, bandwidths at 40 Hz, and use enough processor horsepower to get 1 kHz or higher fusion rates. This can be done with the Teensy 3.1, the Arduino Pro Mini, not so much.

You do not need to use the interrupt pin, polling works fine. And I would recommend Brian Knox's i2c_t3,h library for use with the Teensy 3.1 since it allows at least 400 kHz I2C speeds (I have run the MPU6050 at 1 MHz I2C with it) and offers a lot of intuitive control over I2C communications. 1 MHz is overkill, but you definitely want to run at 400 kHz. The i2C_t3.h is simply the best I2C library around for any platform (but it only runs on the Teensy 3.1).

You're going to have to figure out the rest for yourself, I am afraid. Good luck.
 
This project is quite a challenge. The software-side is not easy, and if you're not experienced, i'd choose an other project.
Defragster already gave you some links to my "Roberta".
The last version worked without the Raspberry, and all work was done by the ATMEGA-8.
My Robot does not need high update-rates, the balancing-loops runs only at 20Hz (something in the near..i forgot the details). That is sufficant, because of the inertia and the weight.

I used the DMP-Code for the MPU6050, and some code more. The DMP-Code cares about the drift, too.
Additional axes are not needed.
(let the sensor warm-up some seconds, then re-calibrate)


A hint: Build the robot in a way, that the heaviest weight is on the top. This makes this type of balancing more easy.

This is another video:
https://www.youtube.com/watch?v=n-noFwc23y0
 
Last edited:
Thank you all for your help. After several days of fiddling around with source code, my robot is responding to IMU signals and attempting to balance. I'm still a ways off from stable control, but your input was very helpful.
 
Thank you all for your help. After several days of fiddling around with source code, my robot is responding to IMU signals and attempting to balance. I'm still a ways off from stable control, but your input was very helpful.

Just wondering how far have you gotten?
 
Status
Not open for further replies.
Back
Top