标题: 单片机PID智能小车避障Proteus仿真+程序 [打印本页]

作者: LOLon    时间: 2019-12-13 15:49
标题: 单片机PID智能小车避障Proteus仿真+程序
智能小车避障 仿真+实物图


单片机源程序如下:
  1. #include<pid.h>
  2. #include "STC12C5A.h"
  3. #include "ioConfig.h"
  4. #include "string.h"
  5. #include "Stdio.h"
  6. #include "absacc.h"
  7. #include "intrins.h"


  8. xdata struct PID spid; // PID Control Structure
  9. unsigned int rout; // PID Response (Output)
  10. unsigned int rin; // PID Feedback (Input)
  11. unsigned int temper;
  12. unsigned int set_temper;

  13. /************************************************
  14.               PID函数
  15. *************************************************/
  16. void PIDInit (struct PID *pp)
  17. {
  18.   memset ( pp,0,sizeof(struct PID));
  19. }
  20. /************************************************
  21.               增量控制PID函数体
  22. 51单片机最不擅长浮点数计算,转换成int型计算
  23. *************************************************/
  24. unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint )
  25. {
  26.   unsigned int dError,Error,pError;
  27.   //增量法计算公式:
  28.   //Pdt=Kp*[E(t)-E(t-1)]+Ki*E(t)+Kd*[E(t)-2*E(t-1)+E(t-2)]
  29.   Error = set_temper - NextPoint;       // 偏差E(t)
  30.   pError=Error-pp->LastError;         //E(t)-E(t-1)
  31.   dError=Error-2*pp->LastError+pp->PrevError; //E(t)-2*E(t-1)+E(t-2)
  32.   pp->PrevError = pp->LastError;
  33.   pp->LastError = Error;
  34.   return (
  35.             pp->Proportion * pError        //比例
  36.             + pp->Integral *Error  //积分项
  37.             + pp->Derivative * dError          // 微分项
  38.                         );  
  39. }

  40. /************************************************
  41.                                 PID函数初始化
  42. *************************************************/
  43. void PIDBEGIN()
  44. {
  45.   PIDInit(&spid); // Initialize Structure
  46.   spid.Proportion = 10; // Set PID Coefficients
  47.   spid.Integral = 5;
  48.   spid.Derivative =4;
  49. }
复制代码
  1. /*****************************************/
  2. /*********     行者 任     ********** ****/
  3. /*****************************************/

  4. #include<reg52.h>
  5. #include"1602.h"
  6. #include"pwm.h"
  7. #include"xunji.h"

  8. sbit POWER=P3^5;

  9. void main (void)
  10. {
  11.         Timer0Init();
  12.         Timer1Init();
  13.         LCD_Init();
  14.         LCD_Str(5, 0, "1421h");
  15.         LCD_Str(0,0,"***smart car***");       
  16.         LCD_Str(0,1,"*DANG HONG MIN*");       
  17.         while(POWER) LCD_Flash(500);;
  18.         DelayMs(50);
  19.         LCD_Write_Command(0x01);
  20.         LCD_Str(0,0,"***smart car***");       
  21.         while(1)
  22.         {
  23.                 xunji(800);
  24.         }
  25.          
  26. }
复制代码


所有资料51hei提供下载:
避障仿真.rar (67.51 KB, 下载次数: 223)



作者: 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