![]()
"Hi"
carefully ready the two threads and come back if you didn't find your answers
"Thank you"
![]()
"Hi"
carefully ready the two threads and come back if you didn't find your answers
"Thank you"
"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.
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
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? -constrain(K*(pTerm + iTerm + dTerm), -255, 255);
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.
V1.5 will bring "utilities" for live tuning without re uploading the code
Are you also working on something? Interested of co-op? ![]()
In post 1 , I found that this code don't have the Ki term.
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.
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.
For a balancing robot targetPosition should always be "zero"
I chose to create this variable to allow fine tuning and later for RC control
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:
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.
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
@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:
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"
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.
Heres the first beta version of the Balancing Bot GUI and it includes one widget that are a dynamic graph...
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...
Hi Patrik
I went on your blog Prevas Parekring
nice job, I will have to jump in Processing some days :![]()
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:
More to come with encoder and RC implementations ![]()
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 ![]()
I will make so we can change the parameters as you describable below..
- 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..
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...
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 ![]()
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
I have now uploaded the KasBot V1 code on my blog you can reach it from the link below:
KasBoT V1.0 is just above
this thread is becoming a bit cluttered ;), this bookmark should help for future reference.
Thanks Patrik for hosting the code on your blog
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.
@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.
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 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
@pramlie
The BalancingBotControl.pde has not yet bean adapted to the K_BotV1 code so you need to change some small things in the Arduino Code and also in the BalancingBotControl.pde.
I can update the BalancingBotControl.pde under the day to be turn key finished for the K_BotV1. All come back when it's done...
You will den get the following functions:
- STD_LOOP_TIME adjustable
- lastLoopUsefulTime read only
- lastLoopTime read only
There are no serial communication added in the K_BotV1 code, I will make a modified version that has the serial part added that are adapted for the GUI..
I have added serial communication to the KasBotV1 code and called it KasBotV1_Serial. The serial communication is aimed for the Balancing Bot GUI.
You can now download dose files in the same blog post as the KasBot_V1 code without serial communication. And also the Balancing Bot GUI
Just received from Sparkfun:
2X 1mW Xbee modules XBee 1mW Chip Antenna - Series 1 (802.15.4) - WRL-08664 - SparkFun Electronics
1X Xbee wireless shield SparkFun XBee Shield - WRL-12847 - SparkFun Electronics
1X Xbee explorer regulated SparkFun XBee Explorer Regulated - WRL-11373 - SparkFun Electronics
1X Xbee Explorer USB dongle SparkFun XBee Explorer Dongle - WRL-11697 - SparkFun Electronics
More info to come soon ![]()
I have one question about the encoder:
How did you wire them ? Did you use any pulldown resistors?
Nice parts I haven't decided if I'm going to use the bluesmirf or Xbee but it will be nice getting a report about the Xbee from you.. ![]()
The 1X Xbee explorer regulated is not need if I just want to communicate with a Arduino UNO?
Hi Patrick,
I have used the xBees for a wireless serial link and also for wireless code uploading. From what you see in the above picture, you will need:
You can also install the Shield on your Uno and the regulated board on a different microcontroller and have them communicate wirelessly. This kit allows you to do what ever combinations you might need.
I have 2 regulated boards. I connect one to my microcontroller board on the FTDI connector and the other to the FTDI cable through an inverter connector that swaps Rx with Tx. (The Explorer already does this and has the FTDI onboard.)
Now that I have my webstore open, I will start working on the Compact robot to make it balance. I intend to use the xBees and your Processing GUI to adjust the parameters on the fly. I hope it works!