problem in write PID program in C !!!

Interested in Robotics? Here's the place to be.
Post Reply
choisoso
Posts: 10
Joined: Sat Mar 15, 2003 1:01 am
Location: hk
Contact:

problem in write PID program in C !!!

Post by choisoso »

hi, i am writing a PID program that can control the car to have lane keeping function.
i am using six Sharp GP2D12 IR sensors to collect the data then by using C program to write PID.
so my problem now is how to write this one??
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: problem in write PID program in C !!!

Post by bwts »

Do u have an algolrythm or flow chart or sumfing?<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
choisoso
Posts: 10
Joined: Sat Mar 15, 2003 1:01 am
Location: hk
Contact:

Re: problem in write PID program in C !!!

Post by choisoso »

hi
my flow chart is like this:
input is sensor data
via PID controller
and then via vechicles<p> PWM
ref distance output
--->------+ >----PID ----->car ---->IR sensor
| |
|----<-------------------|
the above figure is my flow chart
so how can i write it in C program??
i am soso
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: problem in write PID program in C !!!

Post by bwts »

First of all I dont know wot a PID is but I can definately help u with the C code but u will have to B more specific about the operation of ur car.<p>1) What are the addresses of the sensor inputs and the motor outputs?<p>2) What format and meaning does the data from the sensors have?<p>3) What format and meaning does the data to the motors have (what makes them turn on/off faster/slower left/right)?<p>4) What affect do u want the senor information to have upon the motors?<p>5) Do u have any programming experience at all, with C or any other language?<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
xeno
Posts: 1
Joined: Wed Mar 19, 2003 1:01 am
Location: England
Contact:

Re: problem in write PID program in C !!!

Post by xeno »

How about this:
If you are using a differential drive system then .....
Use PID to control forward speed of vehicle using some sort of feedback system ie wheel encoders ( black and white disks on the motor shafts, and a IR Tx/Rx package such as LED/phototransistor). The encoder counts can then allow you to correct any errors in the forward speed using a PID algorithm.<p> Then work out way to give you a steering value from the sharp detectors e.g +10 if vehicle is too far to the right. Then add this number to the forward speed of the right wheels and subtract this number from the speed of the left wheels. The vehicle will then correct its position.<p>Just an idea anyway, hope it helps
choisoso
Posts: 10
Joined: Sat Mar 15, 2003 1:01 am
Location: hk
Contact:

Re: problem in write PID program in C !!!

Post by choisoso »

ok thans everybody.<p>but my problem now is i want to generate a PWM signal by using 8255 programmable peripheral interface card. i short out0 and Gate1 so that out1 can output PWM.
but i use CRO to look at it. But just a constant voltage appears.
my program is follows:<p>#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<math.h>
#define control 0x30B
#define count1 0x309
#define count2 0x30A
#define count0 0x308<p>void main()
{
int c,x,sec;
outportb(control,0x34);
outportb(control,0x72);
outportb(control,0xb4);
outportb(count0,128);// LSB
outportb(count0,312); //MSB with output 50Hz<p>x=3600;
c=40000-x;
sec=c%/256;
outportb(count1,sec);//LSB
sec=c/256;
outport(count1,sec);//MSB
}<p>so what is the problem???
i am soso
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: problem in write PID program in C !!!

Post by bwts »

I think your problem might be that u r changing the output to quickly. There seem to be no pausing going on in ur program.<p>set high
pause for desired duration
set low
pause for desired duration
loop<p>The desired durations will be the parameters for ur pulse width.<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
Will
Posts: 310
Joined: Tue Feb 11, 2003 1:01 am
Location: Katy Texas
Contact:

Re: problem in write PID program in C !!!

Post by Will »

Mr Btwz/Bucky,
I'm becoming interested in this problem because I don't know `C' and would like to. I see that you know `C' but don't know `wot' (A nice piece of humorous English) PID is - If you will comment choisoso's C program so that I can understand what each line is trying to do - then I may be able to understand it. I have ,most difficulty with what the various quantities in parentheses (Count1,sec) etc mean and don't understand `C%'.- and I can't see any input statement to read sensors. If you would like to do that and are interested I will send you a short, simple description of PID. If you like you can contact me direct at [email protected]
Will
BB
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: problem in write PID program in C !!!

Post by bwts »

Hi Will here goes<p>
#include<stdio.h> //tells the compiler to include
#include<conio.h> //these already written routines
#include<time.h> //that handle I/O timing and
#include<math.h> //math functions
//these are part of the C
//langauge nowa days so will not
//have to write them yourself
//although u should B familiar<p>#define control 0x30B //tell the compiler to
#define count1 0x309 //replace label with the
#define count2 0x30A //value stated ie count1
#define count0 0x308 //with hex 309<p>void main() // start of main body of program
{
int c,x,sec; //declaration of variables in this
//integers (int)
outportb(control,0x34); //output via port b
//to control1 the
//value hex 34 (could B
//wrong here not familar
//with outportb
outportb(control,0x72);
outportb(control,0xb4);
outportb(count0,128);// LSB
outportb(count0,312); //MSB with output 50Hz<p>x=3600; // set x to dinary 3600
c=40000-x; // set c to 40000-x strange but true
sec=c%/256; // this is puzzeling 2 me 2 maybe
// lowest nibble of c?
outportb(count1,sec);//LSB
sec=c/256;
outport(count1,sec);//MSB
}
// end of prog usually terminated with return 0<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
Will
Posts: 310
Joined: Tue Feb 11, 2003 1:01 am
Location: Katy Texas
Contact:

Re: problem in write PID program in C !!!

Post by Will »

Thanks Bucky,
I have printed that out and will study it. I just spent 20 minutes writing you a description of PID and my E mail service program cut me off because I had not talked to it in a while so I lost the while thing. I'm not typing it in again. If you would like me to send you a description of PID then you will have to send me your E mail address so that I can attach an MS Word document which includes it.
Will
BB
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests