Society of Robots - Robot Forum
Software => Software => Topic started by: chuong_bk on October 12, 2010, 11:44:22 PM
-
Hi,
I'm working for a two-wheel balancing robot using a PID control,but now I'm having a trouble with PID.It balances for like 3 seconds before oscillating back and forth and eventually falling.
This is my code:
Kp=0.5;
Kd=0.01;
Ki =1
e_current=0;
e_last=0;
e_sum=0;
tilt_balance=0;
e_current=tilt_balance-tilt_est;
P=Kp*e_current;
de=e_current-e_last;
D=Kd*de;
e_sum=e_sum+e_current;
I=Ki*e_sum;
Drive=P+D+I;
e_last=e_current;
So,anyone can give me some advise?
-
Kinda early to look at code, but try adjusting your Kp, Kd, and Ki values. I would also consider logging data so you can see what your system is actually doing. At a quick glance, the basic code looks fine, but I need coffee (mmmm coffee ~D| ) before my brain can get more coherent thoughts out.
-
Hi,Knossor
First,thank you very much for considering my question.I tried to adjust Kp,Kd,Ki many many time,but it didn't work.I see someone add the encoders value to their PID code,but I really don't know how to do it.
-
Do you know how to output data to your computer for data logging? If you do that would be a great help in determining which gains (Kp, Ki, or Kp) need adjusting. Also, where are you getting your tilt_est value from? I still haven't taken a close look at your code yet though, but I'll try to get to that in a little bit.
-
I don't know what is data logging.You means,I get the data and simulate response of the system?can you tell me clearly about that?
T get the tilt_est value form the Kalman fillter.I use acccelerometter ADXL202E and gyro ADXRS150E,and I use Kalman fillter to calculate the tilt value.
-
Data Logging is simply when you record information. Read this tutorial about data logging (http://www.societyofrobots.com/programming_data_logging.shtml).
You would output data from your sensors, important formulas, and your gains. I would output the data in a comma separated value format. Each line would then end up looking something like this (values are made up):
P, 1.5, I, 1, D, 0.15, Accel, 113, Gyro, 28, Tilt est, 13
With this information you can see what your robot is actually doing. It should really help solving your problem. For example if you see the change in P continuously increasing, then it is likely the source of your oscillations.
-
Now I understand what is data logging.I think it's may helpful for me.I will try it and tell you the result soon.I'm very grateful to you for helping me.Thanks a lot!