Author Topic: Need help in solving PID Control System  (Read 6812 times)

0 Members and 1 Guest are viewing this topic.

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Need help in solving PID Control System
« on: October 14, 2008, 02:36:07 AM »
Hello everyone,

As mentioned in the topic, I need help in solving the equation required in controlling my differential steering robot with PID implementation.

Introduction:
I'm using dsPIC30F4011 as the core processor with 15MHz * 8 = 120MHz and a pair of Vexta Brushless DC Motor. Besides, I have built my robot with encoders located parallel to the motor shaft. The purpose of this project is to develop a smooth and fast line follower robot. The sensors I used are QRD1114 and 6 of them are placed inline. Nothing particular in the mechanical parts.

Programming:
I'm using the sensors to determine my PV and set the setpoint = 0

void read_sen(void){
if(!sen1)   PV+=1;
if(!sen2)   PV+=10;
if(!sen3)   PV+=100;
if(!sen4)   PV+=1000;
if(!sen5)   PV+=10000;
if(!sen6)   PV+=100000;

swithc(PV){
// setting my variable "error" with a value ranging from -3 to +3 with setpoint = 0;   
case 0b001100 : error = 0;
case 0b011000 : error = -1;
.....
}}

void PID(void){
 
Perror = Kp*error;   // (proportional gain)*(position error)
Derror = Kd*errorD; // errorD = error - prev_error;
Ierror  = Ki*errorI;   // errorI += error;

PID = Perror + Derror + Ierror ;
}

void speed_control(void){
left_pwm = ???
right_pwm = ???
}

The program above is not a complete program and I even left out some of it from PID().
My problem is that how should I control the speed for both motors using the found value of PID ?
Is there any specific equation that could control both motors?
From the tutorial I read from this website, it use the PID value to control the actuator(motor). However I still not able to come out with a suitable expression for it since I'm just starting to adapt in PID environment.
Also, please comments on read_sen() whether should I range the error from a negative value or using just positive value (1-6). Will it greatly affect in complexing the require speed control equation ?

If you need more information, kindly notice me please. Thanks for helping me out.

Vincent

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Need help in solving PID Control System
« Reply #1 on: October 14, 2008, 06:08:57 AM »
PID is suposed to control the speed of the robot. To get the robot to turn you need an offset that is added to one motor and substracted from the other motor's PWM.

To make the robot go nice and smooth, you need to slow down the speed as the turn gets sharper. Use the switch case to determine the angle of the turn (the offset) and also use it to adjust the speed as you did by calculating the PID value. To keep the robot at max speed, insted of increasing the speed for one motor and decreasing it for the other to make the turn, just decrease the speed of the motor on the same side of the turn. You can also implement a second PID control to calculate the angle of the turn.

This is interesting, let me know the results since I'll be working on a Lego Line Follower robot sometimes in November.

Take a look at this links:
http://www.seattlerobotics.org/encoder/200108/using_a_pid.html
http://www.wrighthobbies.net/guides/linefollower.htm
Check out the uBotino robot controller!

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Need help in solving PID Control System
« Reply #2 on: October 15, 2008, 09:26:11 AM »
Well I have read those articles months ago. Anyway, it is a good start for those who would like to expose themselves more in PID.
Looking back on those equations, I think I will try to develop them and give it a go. I will publish my result once I get it. It will take awhile as I'm configuring my ADC right now for the sensor (QRD1114).

By the way, based on everyone experiences, what are the approximate value for those 3 gains, P, I and D ?
Usually I found in articles are that P is somewhere around hundred, D is between 0.5 to 2 and I is probably 1.
So, any suggestion bout the value ?

My maximum value for PWM is 1022.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Need help in solving PID Control System
« Reply #3 on: October 16, 2008, 09:44:28 PM »
Quote
By the way, based on everyone experiences, what are the approximate value for those 3 gains, P, I and D ?
Usually I found in articles are that P is somewhere around hundred, D is between 0.5 to 2 and I is probably 1.
So, any suggestion bout the value ?
It entirely depends on many factors:
weight of your robot
desired stopping and acceleration speed
mechanics of your robot (motor, gearing, etc)


On small robots I just don't bother with the I term, never needed it . . . just play around with the other values till its satisfactory for you.

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Need help in solving PID Control System
« Reply #4 on: October 17, 2008, 09:46:13 AM »
One question on how to control my acceleration.
Usually I accelerate or increasing my speed using interrupt function and for every interrupt occurred, the speed is added by 1 [speed +=speed].
I have done some thinking on it, if I was to use PID and the error happens to be very large, so basically I need to significantly increase my speed from the current speed right? And I'm using acceleration to do so instead of just change the PWM value. So, as to what I want is that I want to increase the acceleration by double [eg speed = speed + 2]. Is there a simple method to calculate the value for the acceleration rate? I have thought of using the Derivative error [Kd*(error rate of change)]. Any suggestion and opinion/comment?

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: Need help in solving PID Control System
« Reply #5 on: October 19, 2008, 02:10:42 AM »
Just use the PID output to set the acceleration.  Though if you can set the velocity I have no idea why you would set the acceleration instead, since that makes the compensator slow and prone to overshoots.

There is no prepacked gains you can use and expect to work, you must spend some (or alot in many cases) time tuning them, though because your sensors seems to give discrete values PID might not be the best control solution. 

Also, you are setting the errors by hand, which really decreases the utility of PID control.

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Need help in solving PID Control System
« Reply #6 on: October 20, 2008, 01:47:07 AM »
Hello szhang, thanks for the comment. Maybe I shouldn't change the rate of acceleration.
So, you idea is that using the calculated PID value to change the speed instantly. Well, by doing so, obviously there is a drawback right? Usually, if you sudden change you PWM value for example from 100 to 800 or vice verse, you robot won't speed up smoothly.  Will that be a huge matter to you? If yes, how do you solve for that?
If no, maybe you did not anticipate such problem but I do since I'm using maybe some intermediate motor.

Yeah, i get it that using discrete values PID might not be the best control solution. Well, i'm working on it on the analog value with 10-bits resolution.
Thanks for mentioning.
One question on ADC, should I quantized my ADCvalue[ranging from 0-1023]?

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: Need help in solving PID Control System
« Reply #7 on: October 20, 2008, 01:20:13 PM »
What you are doing is

Code: [Select]
if(sensor=x) error=y
else if (sensor=w) error=z
...

PWM=PID(error)

which can be simplified to just

Code: [Select]
if(sensor=x) PWM=x
else if (sensor=w) PWM=z
...

without any PID control (because you're not really doing any)

And about sudden changes in output: it is the garbage-in-garbage-out principle.  If you have a continous control signal (or close to it), PID will provide more or less a smooth output signal.  If you have a very discretized input, you'll still have big changes in output even if you use acceleration, unless you make the acceleration really small (in that case it'll be very slow to converge, and it will overshoot).

If you really want to reduce the "jerk", limit your maximum acceleration instead.

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Need help in solving PID Control System
« Reply #8 on: October 20, 2008, 10:24:05 PM »
What you are doing is

Code: [Select]
if(sensor=x) error=y
else if (sensor=w) error=z
...

PWM=PID(error)

which can be simplified to just

Code: [Select]
if(sensor=x) PWM=x
else if (sensor=w) PWM=z
...

without any PID control (because you're not really doing any)


Wow, really? Hmm... should have know. PID won't be that of simple from the beginning.
Well, do you mind showing me some idea on how to develop its algorithm. Shoot me with the basic one at least.
Really need some guide here ?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Need help in solving PID Control System
« Reply #9 on: October 23, 2008, 06:54:21 AM »
Quote
One question on ADC, should I quantized my ADCvalue[ranging from 0-1023]?
With reference to what? An analog to digital converter will 'quantize' anything and everything . . . that why its analog-to-digital :P

Offline EnginiusXIIITopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Need help in solving PID Control System
« Reply #10 on: October 23, 2008, 09:42:29 AM »
Haha, yeah. Quite stupid in asking that question.
Admin, got any help in PID? Have you wrote a PID source code for any line follower robot?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Need help in solving PID Control System
« Reply #11 on: October 27, 2008, 07:56:45 AM »
I had some PID sourcecode a long time ago, but it was lost years ago.

For line following I use fuzzy logic - much simpler and just as effective.

 

SMF spam blocked by CleanTalk