I'm making a "simple" balancing robot
Here it is:
I'm using a Uno, with an Arduino motor shield to drive 2x 6V mini metal gearmotors
. 130 RPM 0.3 kg.cm. With 32mm wheels.
An MPU 6050 from Sparkfun. And pots to tune the PID parameters.
Motors and pots have their own supply (9.6V with 5V voltage regulator for the pots).
The Uno only powers the MPU 6050.
For the code I mostly followed the advice from Kas' thread
which has been super helpful (thanks heaps Kas!).
I use the raw readings from the 6050 (I use "getmotion6" from the MPU6050 lib to get 6 raw readings from accel and gyro). Each loop takes an average of 3 sets of readings, then I use the Kalman filter from Kas to get a clean angle.
Angle readings I'm quite confident with, nice symmetric and smooth (although it still picks up a bit of rotation when I shake it in "translation" but it's hard to control the shake
so not 100% sure).
Then the PID part. It's my problem.
I start with all 3 coeffs P,I,D at 0 and increase P with a pot.
Problem is, I can't seem to get proper balance with the P. When I increase the P it goes like that:
- phase 1: robot cant recover from the 1st tilt, ie; it's always gonna fall on the side it tilted first. I increase P it just falls slower.
-phase 2: robot shakes. It's super jerky.
Then I tried everything, play with many values for the I term, I can somehow get it to balance for ~20sec, but it's still supre shaky and ends up countering the slow oscillations too much and slamming itself in the floor.
I tried playing with D but because robot is super shaky it just picks up the "noise" and makes it shakier :p If I keep the value super low it does nothing and if I increase it starts shaking more.
So there I am... I've been fiddling with the PID values for a couple hours now. I thought it could be backlash, so I tried to map the motor speed from (0,255) to (30,255) so they wouldn't "stick" and not turn at low PWM. Didn't work.
I graphed the command PWM (output of the PID function) and it's all over the place, basically it varies from -255 to +255 multiple times per second.
I was thinking doing some kind of averaging of the command. The whole code loop runs in ~5ms so is it a good idea to try and run the loop say 4 times and only send command every 20ms? Or do a rolling average?
I don't even knoow if the PWM all over the place is a bad thing. The motors need ~50 to get unstuck from stopped so I guess that's the problem, but there could be others.
I would appreciate any advice! thanks! (I can post a video of shakybot if needed)