Pages: 1 [2] 3   Go Down
Author Topic: DC motor control with PID  (Read 58379 times)
0 Members and 2 Guests are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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



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
Logged

Toronto, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[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!!
Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Ro-Bot-X, nice to see you around  smiley-wink

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
« Last Edit: September 15, 2010, 02:19:01 am by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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,  smiley-wink 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
« Last Edit: September 15, 2010, 04:52:49 am by kas » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 5519
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)...

 smiley
Logged

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

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Atmel rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

How do you add photos?
Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  :smiley

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
Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

Easy  smiley-wink
 - Go to http://imgur.com/
 - Upload you photo(s)
 - copy the "Message board" line
 - paste it here
Logged

0
Offline Offline
Sr. Member
****
Karma: 11
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: September 16, 2010, 11:32:12 am by kas » Logged

Pages: 1 [2] 3   Go Up
Jump to: