Poll
Question: I will need help with my project ?
With the programing part - 47 (58%)
With the DC motors - 34 (42%)
Total Voters: 26

Pages: 1 ... 3 4 [5] 6 7 ... 16   Go Down
Author Topic: Balancing robot for dummies  (Read 129432 times)
0 Members and 2 Guests are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-sad smiley-sad smiley-sad

"Hi"

carefully ready the two threads and come back if you didn't find your answers

"Thank you"
Logged

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

Quote
"Hi"

carefully ready the two threads and come back if you didn't find your answers

"Thank you"

I have read two posts almost 3 times....  
In post 1 , I found that this code don't have the Ki term.
Code:
int updatePid(int command, int targetValue, int currentValue)   {             // compute PWM value
float pidTerm = 0;                                                            // PID correction
int error=0;                                  
static int last_error=0;                            
  error = abs(targetValue) - abs(currentValue);
  pidTerm = (Kp * error) + (Kd * (error - last_error));                            
  last_error = error;
  return constrain(command + int(pidTerm), 0, 255);
}
After I search for two posts I found something useful in post 2 =>Part four: PID control
But while I study your code
Code:
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);
}
I got confuse why the first post's code "updatePID" you got three input variables but second one you got 2 inputs:int targetPosition, int currentPosition.
Maybe I am not familiar with PID, would you please tell me that what is the value for -GUARD_GAIN and GUARD_GAIN?
Also, What is the K means?
Code:
-constrain(K*(pTerm + iTerm + dTerm), -255, 255);
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on GUI in processing where you will see all important parameters and sensor inputs. And be able to change parameters in the arduino on the fly and save all settings in the arduino memory.

Also in the future be able to control the bot wireless true a blueSmirf.

Quote
V1.5 will bring "utilities" for live tuning without re uploading the code

Are you also working on something? Interested of co-op?  smiley-wink
Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In post 1 , I found that this code don't have the Ki term.
Code:
int updatePid(int command, int targetValue, int currentValue)   {             // compute PWM value
float pidTerm = 0;                                                            // PID correction
int error=0;
static int last_error=0;
  error = abs(targetValue) - abs(currentValue);
  pidTerm = (Kp * error) + (Kd * (error - last_error));
  last_error = error;
  return constrain(command + int(pidTerm), 0, 255);
}
The first code snippet was created as a stand alone PID motor control application.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282384853/0
It allows to run a DC motor at very low speed while retaining normal torque.
For this type of application, Integral parameter is generally not required.

Quote
After I search for two posts I found something useful in post 2 =>Part four: PID control
But while I study your code Code:
Code:
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);}
I got confuse why the first post's code "updatePID" you got three input variables but second one you got 2 inputs:int targetPosition, int

currentPosition.
For a balancing robot targetPosition should always be "zero"
I chose to create this variable to allow fine tuning and later for RC control

Code:
PWM_val= updatePid(PWM_val, speed_req, speed_act);                        // compute PWM value
PWM_val parameter is not actually modified in updatePid and my original code was:

Code:
 PWM_val= PWM_val + updatePid(speed_req, speed_act);                        // compute PWM value
  PWM_val = constrain(PWM_val + int(pidTerm), 0, 255);
I decided to pass PWM_val as a parameter to allow constrain(XXX, 0, 255) to sit in the updatePid function.
Both implementations are equivalent.

Quote
Maybe I am not familiar with PID, would you please tell me that what is the value for -GUARD_GAIN and GUARD_GAIN?
Also, What is the K means?
Integral is the only term that keeps changing no matter how small the error remains
GUARD_GAIN sets up a limit for iTerm. It is standard procedure to clip Integral.
K, Kp, Ki and Kd are parameters to be adjusted purely on experimentation
Logged

0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Patrik
I am not really familiar with Java/Processing,  :-[
Building a GUI is a great idea, please post ASAP

I just finished a much simpler version, using the IDE serial monitor:


Code:
int getTuning() {
  if(!Serial.available())    return 0;
  delay(10);                  
  char param = Serial.read();                            // get parameter byte
  if(!Serial.available())    return 0;
  char cmd = Serial.read();                              // get command byte
  Serial.flush();
  switch (param) {
    case 'p':
      if(cmd=='+')    Kp++;
      if(cmd=='-')    Kp--;
      break;
    case 'i':
      if(cmd=='+')    Ki++;
      if(cmd=='-')    Ki--;
      break;
    case 'd':
      if(cmd=='+')    Kd++;
      if(cmd=='-')    Kd--;
      break;
    case 'k':
      if(cmd=='+')    K +=0.2;
      if(cmd=='-')    K -=0.2;
      break;
    default:
      Serial.print("?");           Serial.print(param);
      Serial.print(" ?");          Serial.println(cmd);
    }
  Serial.println();
  Serial.print("K:");           Serial.print(K);
  Serial.print("   Kp:");       Serial.print(Kp);
  Serial.print("   Ki:");       Serial.print(Ki);
  Serial.print("   Kd:");       Serial.println(Kd);
}
Usage:
to increase Kp: type "p", then "+" then "enter"
to decrease Kp: type "p", then "-" then "enter"
same procedure for Ki: "i" , for Kd: "d" and for K: "k"
« Last Edit: November 02, 2010, 02:46:01 pm by kas » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@kas
Quote
I am not really familiar with Java/Processing,  
Building a GUI is a great idea, please post ASAP

I have started with the GUI and I want it widget based some please tell me what type of widget you want to have in the GUI.

You can see more info about it on my blog.

It's only a beta, I will improve the graph widget and clean up the code a little then I will post the source on my blog and put a link here.


« Last Edit: November 03, 2010, 12:48:12 am by X-firm » Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Heres the first beta version of the Balancing Bot GUI and it includes one widget that are a dynamic graph...
      
  • You can add as many graphs as you want and set the size and shape of them
  • You can maximiz a graph
  • You can also move it in real time
Right now you can only show information from the bot, but I will soon update the GUI with the possibility to change parameters in the bot.
Below is a image of the GUI that are using three Graph widgets:





Heres the code from the example above...


Sketch for Processing IDE:

Download and unzip the folder in your sketch directory. Change the serial port to the corresponding for you computer...

Complete sketch

« Last Edit: November 06, 2010, 01:21:37 pm by X-firm » Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Patrik

I went on your blog http://www.x-firm.com/?cat=6
nice job, I will have to jump in Processing some days  :smiley


Quote
I have started with the GUI and I want it widget based some please tell me what type of widget you want to have in the GUI.
Those are the parameter I did have to adjust or monitor:

 - STD_LOOP_TIME           adjustable
 - lastLoopUsefulTime        read only
 - lastLoopTime                read only
 - ACC_X, _Y, GYR_Y        read only or trending
 - actAngle, ACC_angle     trending
 - setPoint                        adjustable
 - K, P, I, D                      adjustable
 - pTerm, iTerm, dTerm     trending
 - drive                            trending

More to come with encoder and RC implementations smiley-wink


Code:
Heres the code from the example above...

Sketch for Processing IDE:

Download and unzip the folder in your sketch directory. Change the serial port to the corresponding for you computer...

Complete sketch
Your links are dead  smiley-sad
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@kas

I will make so we can change the parameters as you describable below..
Quote
- STD_LOOP_TIME           adjustable
- lastLoopUsefulTime        read only
- lastLoopTime                read only
- ACC_X, _Y, GYR_Y        read only or trending
- actAngle, ACC_angle     trending
- setPoint                        adjustable
- K, P, I, D                      adjustable
- pTerm, iTerm, dTerm     trending
- drive                            trending

I have fixed the links..
Quote
Heres the code from the example above...


Sketch for Processing IDE:

Download and unzip the folder in your sketch directory. Change the serial port to the corresponding for you computer...

Complete sketch
Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hi Kas,
 
first to tell you how much I like your post "balancing robot for dummies" and how useful it has been. I have been following it real time since you started it.

I was wondering if you solved how to upload the v1.0 of the code already or if you know where I can take a look to it if thats not to much asking!

keeep it up, thanks!
Thanks for the nice comments  8-)
Patrik has offered to host the code on his web site.
I sent him the zip by email, he will release the link pretty soon
« Last Edit: November 07, 2010, 01:44:48 am by kas » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have now uploaded the KasBot V1 code on my blog you can reach it from the link below:

http://www.x-firm.com/?p=142
Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

0
Offline Offline
Sr. Member
****
Karma: 17
Posts: 378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

                [size=18]KasBoT V1.0   is just above[/size][/color]

this thread is becoming a bit cluttered  smiley-wink, this bookmark should help for future reference.
Thanks Patrik for hosting the code on your blog
Logged

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

Thanks Patrik for the graph drawing sketch. I've been looking for a nice way to visualize the gyro & accelerometer measurement and now I have it smiley.

If you are going to develop the sketch further, I'd like to see some kind of easy scaling for the graph amplitude and also for update speed on x-direction. I did found a way to change them in code, but it could maybe be easier.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@T.J.L.
Quote
Thanks Patrik for the graph drawing sketch. I've been looking for a nice way to visualize the gyro & accelerometer measurement and now I have it .

If you are going to develop the sketch further, I'd like to see some kind of easy scaling for the graph amplitude and also for update speed on x-direction. I did found a way to change them in code, but it could maybe be easier.

It's nice to here that someone has had use of the GUI. And like u say the update speed is updated every time the Arduino sends anything. I can add some buttons for changing the scale..

I'm currently building my new robot and will adapt the KasBot_V1 code to my hardware to be able to help developing this further. When that are done the GUI developing will be more in focus...  
Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

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

The processing code not work for me. I just upload K_BotV1.pde and then run BalancingBotControl.pde on Processing. I got only 3 tables on the screen, without processing anything...If I'm doing wrong, would you tell me step-by-step procedure your GUI sketch Patrik? Thanks
Logged

Pages: 1 ... 3 4 [5] 6 7 ... 16   Go Up
Jump to: