go_away

Author Topic: PID control for two-wheel balancing robot  (Read 4563 times)

0 Members and 1 Guest are viewing this topic.

Offline chuong_bkTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
PID control for two-wheel balancing robot
« 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?

Offline knossos

  • Robot Overlord
  • ****
  • Posts: 278
  • Helpful? 14
Re: PID control for two-wheel balancing robot
« Reply #1 on: October 13, 2010, 04:44:42 AM »
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.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."
 
Oscar Wilde

Offline chuong_bkTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: PID control for two-wheel balancing robot
« Reply #2 on: October 13, 2010, 09:34:10 AM »
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.

Offline knossos

  • Robot Overlord
  • ****
  • Posts: 278
  • Helpful? 14
Re: PID control for two-wheel balancing robot
« Reply #3 on: October 13, 2010, 11:00:38 AM »
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. 
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."
 
Oscar Wilde

Offline chuong_bkTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: PID control for two-wheel balancing robot
« Reply #4 on: October 14, 2010, 01:40:39 AM »
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.

Offline knossos

  • Robot Overlord
  • ****
  • Posts: 278
  • Helpful? 14
Re: PID control for two-wheel balancing robot
« Reply #5 on: October 14, 2010, 05:04:25 AM »
Data Logging is simply when you record information.  Read this tutorial about data logging.

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.
« Last Edit: October 14, 2010, 07:18:49 PM by knossos »
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."
 
Oscar Wilde

Offline chuong_bkTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: PID control for two-wheel balancing robot
« Reply #6 on: October 14, 2010, 07:03:46 PM »
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!

 


Get Your Ad Here