Go Down

Topic: DC motor control with PID (Read 97105 times) previous topic - next topic

kas

It's balancing (at first try)  :) :) :)



See it live:  http://www.youtube.com/v/pC6yeyDunJg?

As soon as I install the battery on top (charger still not received), I will open a new thread with a more relevant title
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

Ro-Bot-X

This is freaking awesome!!! Congratulations!

I was so busy with my other projects that I neglected my balancing robot (I bought smaller motors and same Pololu wheels, they plug in directly on the motor shaft). I have a 2 axis accelerometer and a one axis gyro, do you think it will suffice or should I get a 5 axis IMU?

Gibby623

That is amazing, why is mine so bad... Sigh... What controller are you using for he wheels?

thinkaneer

[glow]// Kalman filter module

float Q_angle  =  0.001;
float Q_gyro   =  0.003;
float R_angle  =  0.03;[/glow]

Hi Kas, awesome work on the project! My mate at uni was showing this to me today looks cool, great progress!

I am also working with an IMU a 6dof one and just wondering for your kalman filter above, how did you find the covariance matrices for measurement error and process error? lke what did you do and stuff?
Because im upto that aswell, i have my state space of the kalman filter, just dont understand how to get the covariance matrix.
Any help would be appreciated.

Thanks!!

kas

#19
Sep 15, 2010, 09:17 am Last Edit: Sep 15, 2010, 09:19 am by kas Reason: 1
Hi Ro-Bot-X, nice to see you around  ;)

I hope your robot will balance soon
Two axis accelerometer & one  axis gyro are OK for the job
If you use separate breakout boards, make sure that axis are orthogonal, you may end up  having the gyro board being perpendicular to the main board.
Also sensors units should match, don't fuse radian with deg/sec in your code
Finally the backlash we talked about is noticiable, but manageable

Please keep me informed of your progress, here
or there http://letsmakerobots.com/node/19558
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

kas

#20
Sep 15, 2010, 11:50 am Last Edit: Sep 15, 2010, 11:52 am by kas Reason: 1
@Gibby623

>>What controller are you using for he wheels?
Not sure I understand your question, please elaborate
If you mean motor driver,here it is: http://www.pololu.com/catalog/product/708

>>why is mine so bad... Sigh...
I understand your frustration,  ;) I have been pursuing this quest nearly for 2 years
Please post photos of your bot, together with the code, I will look for possible obvious reasons
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

haha97

i will do this later,if i success[ch65292]i'll show my pictures.  
i  got  a  question ,why do you put the battery on the top[ch65311]
i think that if you put it  on  the  bottom,you  can  controll  the  balance better.

cr0sh

Quote
i think that if you put it  on  the  bottom,you  can  controll  the  balance better.


I know nothing about balancing robots, but I would tend to think having the mass at the top would be easier to balance. Try to balance a pencil on your hand, then try it with a weight on top (blob of clay), then a weight near the hand - you'll find its easier with the weight at the top. I imagine the same would be true for a robot (ie, inverted pendulum)...

:)
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

kas

Quote
Quote:

i think that if you put it  on  the  bottom,you  can  controll  the  balance better.

I know nothing about balancing robots, but I would tend to think having the mass at the top would be easier to balance. Try to balance a pencil on your hand, then try it with a weight on top (blob of clay), then a weight near the hand - you'll find its easier with the weight at the top. I imagine the same would be true for a robot (ie, inverted pendulum)...


Your are right cr0sh
the robot acts as an inverted pendulum and works better when the weight is high (it increases intertia and allows more reaction time).
Try to balance a broom in the palm of your hand and see which side is easier to balance.
However, PID parameters need different tuning
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

kas

Quote
// Kalman filter module

float Q_angle  =  0.001;
float Q_gyro   =  0.003;
float R_angle  =  0.03;

Hi Kas, awesome work on the project! My mate at uni was showing this to me today looks cool, great progress!

I am also working with an IMU a 6dof one and just wondering for your kalman filter above, how did you find the covariance matrices for measurement error and process error? lke what did you do and stuff?
Because im upto that aswell, i have my state space of the kalman filter, just dont understand how to get the covariance matrix.
Any help would be appreciated.

Thanks!!


Kalman filter module works pretty well but is still a Black Box for me
I tried hard to understand and finally gave up.  :o

This code is a modified version from the AeroQuad project from Ted Carancho
http://code.google.com/p/aeroquad/

I spent some hours playing with Q_angle, Q_gyro and R_angle, and finally reverted to the original parameters

Some additional lectures for the brave:
http://academic.csuohio.edu/simond/courses/eec644/kalman.pdf
http://www.cs.unc.edu/~welch/kalman/index.html#Anchor-Rudolph-6296
http://forum.sparkfun.com/viewtopic.php?t=6186
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

josev

Kas,

I am confused, on the let's make Robots site, you stated that thanks to Dallaby your robot balances. Now,  Dallaby uses a complementary filter. You mention you are using a Kalman filter. So, is this the case, if so what is the contribution from Dallaby?

I am  asking because I am trying to start similar project and not sure whether to spend more time trying to be able to run the kalman routines or go ahead with the complementary filter. Several sites talks very good about this simpler approach.

Thanks !

Gibby623

Kas,
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284650649/0#0

How do you add photos?

kas

Hi josev,

This is a long story
I made several unsuccessfull attemps to build an acceptable balancing bot, both with Kalman or complementary filter; I finally gave up 6 months ago.
Reading, Dallaby blog gave me new ideas for the project, mainly for hardware (I was using continuous rotation servos).
Dallaby uses a single axis accelerometer which is OK small angles, together with a very simple and efficient code.
I chose the full blown path, but again, without visiting his site, I wouldn't be writing to you right now.  ::)

The above Kalman code is really convenient and self contained
Feed it with Acc angle, Gyro speed and loop time, it will spit back the filtered angle right away
Just make sure that data are scaled and your loop time is accurate/constant,
mine is running 100 Hz, see above "loop timing control".

Good luck, keep us informed
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

kas

Quote
Kas,
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284650649/0#0

How do you add photos?


Easy  ;)
- Go to http://imgur.com/
- Upload you photo(s)
- copy the "Message board" line
- paste it here
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

kas

#29
Sep 16, 2010, 06:13 pm Last Edit: Sep 16, 2010, 06:32 pm by kas Reason: 1
Gibby623,
A bit dubious about your PID function
Why do you have "PID" and "PID_comp"?? is "a" a tuning factor (as my "K") ??
I would have expected PID to be positive or negative according to the bot being tilted forward or backward
Also if your loop is fixed time, you can omit the dt factor

anycase, here is my PID code:
Code: [Select]

float K = 1.4;
int   Kp = 3;                      
int   Ki = 1;                  
int   Kd = 6;  
int last_error = 0;
int integrated_error = 0;
int pTerm = 0, iTerm = 0, dTerm = 0;

int updatePid(int targetPosition, int currentPosition)   {
 int error = targetPosition - currentPosition;
 pTerm = Kp * error;
 integrated_error += error;                                      
 iTerm = Ki * constrain(integrated_error, -GUARD_GAIN, GUARD_GAIN);
 dTerm = Kd * (error - last_error);                            
 last_error = error;
 return -constrain(K*(pTerm + iTerm + dTerm), -255, 255);
}

This function accepts 2 parameters
- target position (normally = 0)
- current position = the angle obtained from Kalman or complementary filter
the function returns an integer value, between -255 and +255

Please let me know which Acc and Gyro models are buit on your specific Sparkfun board
- Rubik's cube Robot solver                 forum.arduino.cc/index.php?topic=271827.0
- Android Bluetooth joystick               forum.arduino.cc/index.php?topic=173246.0
- Balancing robot for dummies           forum.arduino.cc/index.php/topic,8871.0

Go Up