标题:
单片机PID智能小车避障Proteus仿真+程序
[打印本页]
作者:
LOLon
时间:
2019-12-13 15:49
标题:
单片机PID智能小车避障Proteus仿真+程序
智能小车避障 仿真+实物图
51hei截图6.jpg
(898.59 KB, 下载次数: 85)
下载附件
2019-12-13 21:26 上传
单片机源程序如下:
#include<pid.h>
#include "STC12C5A.h"
#include "ioConfig.h"
#include "string.h"
#include "Stdio.h"
#include "absacc.h"
#include "intrins.h"
xdata struct PID spid; // PID Control Structure
unsigned int rout; // PID Response (Output)
unsigned int rin; // PID Feedback (Input)
unsigned int temper;
unsigned int set_temper;
/************************************************
PID函数
*************************************************/
void PIDInit (struct PID *pp)
{
memset ( pp,0,sizeof(struct PID));
}
/************************************************
增量控制PID函数体
51单片机最不擅长浮点数计算,转换成int型计算
*************************************************/
unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint )
{
unsigned int dError,Error,pError;
//增量法计算公式:
//Pdt=Kp*[E(t)-E(t-1)]+Ki*E(t)+Kd*[E(t)-2*E(t-1)+E(t-2)]
Error = set_temper - NextPoint; // 偏差E(t)
pError=Error-pp->LastError; //E(t)-E(t-1)
dError=Error-2*pp->LastError+pp->PrevError; //E(t)-2*E(t-1)+E(t-2)
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (
pp->Proportion * pError //比例
+ pp->Integral *Error //积分项
+ pp->Derivative * dError // 微分项
);
}
/************************************************
PID函数初始化
*************************************************/
void PIDBEGIN()
{
PIDInit(&spid); // Initialize Structure
spid.Proportion = 10; // Set PID Coefficients
spid.Integral = 5;
spid.Derivative =4;
}
复制代码
/*****************************************/
/********* 行者 任 ********** ****/
/*****************************************/
#include<reg52.h>
#include"1602.h"
#include"pwm.h"
#include"xunji.h"
sbit POWER=P3^5;
void main (void)
{
Timer0Init();
Timer1Init();
LCD_Init();
LCD_Str(5, 0, "1421h");
LCD_Str(0,0,"***smart car***");
LCD_Str(0,1,"*DANG HONG MIN*");
while(POWER) LCD_Flash(500);;
DelayMs(50);
LCD_Write_Command(0x01);
LCD_Str(0,0,"***smart car***");
while(1)
{
xunji(800);
}
}
复制代码
所有资料51hei提供下载:
避障仿真.rar
(67.51 KB, 下载次数: 223)
2019-12-13 21:27 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
113265
时间:
2019-12-16 15:56
有点看得不懂
作者:
798540381
时间:
2020-3-1 19:15
单片机的RST连的是什么
作者:
hj08102
时间:
2020-3-9 10:35
感谢分享,搞了好久都没搞懂PID
作者:
hj08102
时间:
2020-3-9 10:43
有点没看懂,你电机的反馈信号是怎么采集的呢?
作者:
sai256516
时间:
2020-3-12 10:20
没这么看懂
作者:
linnyshow
时间:
2020-4-7 14:39
非常感谢。
作者:
1490055139
时间:
2020-4-8 14:06
非常好的资源,必须点赞支持一下
作者:
1490055139
时间:
2020-4-8 14:07
非常好的资料,必须点赞支持一下。
作者:
清雅
时间:
2020-4-22 13:39
感谢楼主
作者:
144290
时间:
2020-4-28 17:00
打不开
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1