pid控制的C语言编程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pid控制的C语言编程相关的知识,希望对你有一定的参考价值。

请专业人士编写一个pid控制的c语言程序,*****请在每条语句后注明详细的解释*****,最好不要在百度上搜一段回复,希望有强人亲自编写一段,感激不尽!

参考技术A #include<unistd.h>
#include<stdio.h>
int main(int argc,int **argv)

int pid=fork();
if(pid==-1)

printf("error");

else if(pid==0)

printf("This is the child process!\n");

else

printf("This is the parent process! child process id=%d\n",pid);

return 0;

首先为什么这段代码gcc编译不了,只能用g++编译,gcc编译显示结果如下
Undefined first referenced
symbol in file
__gxx_personality_v0 /var/tmp//ccuHN8IS.o
ld: fatal: Symbol referencing errors. No output written to t5
collect2: ld returned 1 exit status
其次,g++编译后运行结果如下
This is the parent process! child process id=27406
This is the child process!本回答被提问者采纳
参考技术B #include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar timecount ,PWMH,SpeedSet,SpeedDet;

uchar KP,KI,KD;
int e1,e2,e3,uk,duk;

sbit Dir = P1^0;
sbit PWM = P1^1;
sbit P2_0 = P2^0;
sbit P2_1 = P2^1;

void delay(uchar i)

uchar j;
for(;i > 0; i--)

for(j=29;j > 0;j--)
_nop_();
_nop_();



void PWMout (uchar q)

PWM = 1;
delay(q);
PWM = 0;
delay(100-q);


void timer1() interrupt 3

TH1 = 0x3c;
TL1 = 0xb0;
if(--timecount == 0)

timecount = 4;
TR0 = 0;
SpeedDet = TL0;
TL0 = 0;
TR0 = 1;
e1 = SpeedSet - SpeedDet;
duk = (KP*(e1-e2)+KI*e1+KD*(e1-2*e2+e3))/10;
uk = uk+duk;
if(uk>100) uk = 100;
else if(uk< -100) uk = -100;
if(uk < 0)

PWMH = -uk;
Dir = 0;

else

PWMH = uk;
Dir = 1;

e3 = e2;
e2 = e1;



void main()

TMOD = 0x16;
TH0 = 0;
TL0 = 0;
TH1 = 0x3c;
TL1 = 0xb0;
timecount = 4;
PWMH = 0;
SpeedSet = 80; //设定转速为2000rpm
SpeedDet = 0;
e1 = 0; //对应为PID控制中的
//e(k),e(k-1),e(k-2)
e2 = 0;
e3 = 0;
KP = 10; //对应为PID控制中的
// Kp,K1,Kd
KI = 1;
KD = 2;
TR0 = 1;
TR1 = 1;
ET1 = 1;
EA = 1;
while(1)

PWMout(PWMH);

以上是关于pid控制的C语言编程的主要内容,如果未能解决你的问题,请参考以下文章

PID控制算法C源码

C语言开发单片机为啥都是全局变量形式?

UNIX c编程[关闭]

C语言程序如何读取cmd命令的返回值?

C语言循环遍历文件夹查找文件内容(搜素/proc文件夹下的内容获取进程pid)

怎么用c语言解析xml文件