Go Down

Topic: Balancing robot for dummies (Read 152192 times) previous topic - next topic

kas

:( :( :(

"Hi"

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

"Thank you"

hoyeungl

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: [Select]
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: [Select]
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: [Select]
-constrain(K*(pTerm + iTerm + dTerm), -255, 255);

Patrik

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?  ;)
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

Quote
In post 1 , I found that this code don't have the Ki term.
Code: [Select]
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: [Select]
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: [Select]
PWM_val= updatePid(PWM_val, speed_req, speed_act);                        // compute PWM valuePWM_val parameter is not actually modified in updatePid and my original code was:

Code: [Select]
 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

kas

#64
Nov 02, 2010, 08:44 pm Last Edit: Nov 02, 2010, 08:46 pm by kas Reason: 1
@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: [Select]
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"

Patrik

#65
Nov 03, 2010, 06:47 am Last Edit: Nov 03, 2010, 06:48 am by X-firm Reason: 1
@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.

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

Patrik

#66
Nov 05, 2010, 09:04 pm Last Edit: Nov 06, 2010, 07:21 pm by X-firm Reason: 1
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

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

kas

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


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


Code: [Select]
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  :(

Patrik

@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
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

#69
Nov 07, 2010, 06:44 am Last Edit: Nov 07, 2010, 07:44 am by kas Reason: 1
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

Patrik

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
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

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

this thread is becoming a bit cluttered  ;), this bookmark should help for future reference.
Thanks Patrik for hosting the code on your blog

T.J.L.

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.

Patrik

@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...  
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

pramlie

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

Go Up