首页 > 编程知识 正文

学汽车维修的学校在哪,智能搬运小车电赛

时间:2023-05-05 23:37:30 阅读:175784 作者:4754

近10所学校的比赛程序(无保留),你知道。 很经典,做智能车可不能错过哦。

好的内容都能看到回复

程序1.# include hidef.h/* commondefinesandmacros */# include mc9s 12dg 128.h/* derivative information */# pragma link 闭环调速unsignedintpicture1[ 10 ] [4]={ { 600,600,0,40 }、{ 600,600,0,80 }、{ 600,600,0,80 }和} unsigned int Picturewrflag[10]; //图像数据真伪判别标志intpicturecoordinate [ 10 ]={ 0,0,0,0,0,0,0,0 }; //图像坐标unsigned int FieldCNT; int RowCNT; int CapFlag; long coordinate1,coordinate2,line_wideth; int se=0; int PMCNT,NextPMCNT; int curvature; //曲率int ServoMotorPWM; int i; int TurningLine;/* * * * * * * * * * * * * * * * * * * * * * * * * static int wait time=0; int speed_0=0; int e=0,e_1=0; int ie=0; int Kp=35; int Kd=0; int Ki=10; //5; int PACN0_i; int SpeedMin=90,SpeedMax=400; char a;/* * * * * * * * * * * * * * * * * * * * * * * * int bendstraightmemory [ 100 ]; //直道曲线数据存储/* * * * * * * * * * * * * * * * * * voidccdinit (void; voidPWMinit(void; voidsysteminit(void; voidpicturedispose(void;/* * * * * * * * * * * * * * * * * * * * * * * * * staticvoidrtiinit (void; voidsetspeed(void;/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

*****/void main(void) {        DisableInterrupts;        SystemInit();               EnableInterrupts;     for(;;) {  EnableInterrupts;  JourneyMemory();  PictureDispose();  }}/************************************************************************系统初始化区域**************************************************************************/  void SystemInit(void){        AbsoluteTime = 0; // 初始化系统时钟        DDRB = 0xff; // 初始化PORTB,用于数据输出        FieldCNT = 0; // 场计数器初始化        ETCInit();        PWMInit();        RTIInit();  }  static void RTIInit(void) {  /* setup of the RTI interrupt frequency */  /* adjusted to get 1 millisecond (10.24 ms) with 16 MHz oscillator */  RTICTL = 0x64; /* set RTI prescaler */  CRGINT = 0x80; /* enable RTI interrupts */    }  void ETCInit(void)  {      TCTL4_EDG0B=0;   TCTL4_EDG0A=1; //0 channel Capture on rising edges only   TCTL3_EDG7B=1;   TCTL3_EDG7A=0; //7 channel Capture on falling edges only   TIOS_IOS0=0; //0 channel input compare   TIOS_IOS7=0; //7 channel input compare          TIOS_IOS4 = 0; // 视频输入捕获        TIOS_IOS5 = 0; // 行同步        TIOS_IOS6 = 0; // 场同步        TSCR1_TEN = 1; // 使能计数        TSCR1_TFFCA = 1; // 捕获中断、比较中断标志位通过读取数据和写入数据清除        PACTL=0x40;   //16位累加器A使能 ,下降沿工作PBCTL_PBEN=1;//16位累加器B使能        TC4 = TC4; // 清除中断标志位        TC5 = TC5;        TC6 = TC6;        CCDInit();  }  **********************************函数名称:CCDInit  功能描述:图像空间初始化  ********************************   void PWMInit(void) {        PWME = 0x00;              // 禁止所有的PWM输出通道        PWMPOL = 0xFF;     // 所有的PWM输出高电平有效        PWMCLK = 0x00;         // Clock A && Clock B is the clock source for PWM channel 0~7        PWMPRCLK = 0x03;         // bus clock:24M;Clock A--8分频,Clock B--0分频        PWMCAE = 0x00;         // 所有的PWM输出为左对齐方式输出        PWMCTL = 0xFF;         // 将两个8位的PWM输出通道组合成一个16位的PWM输出通        PWMCNT01 = 0xFF;         // PWM计数器清零        PWMCNT23 = 0xFF;        PWMCNT45 = 0xFF;        PWMCNT67 = 0xFF;        PWMPER01 = 60000; // 驱动前轮舵机,周期20ms,频率50Hz        PWMPER23 = 2400; //周期0.1ms,频率10kHz        PWMPER67 = 2400;        // 设置占空比初始值        PWMDTY01 = 4200//舵机要求PWM高电平宽度0.5ms~2.5ms对应计数器数值为3800~4450~5150右        PWMDTY23 =1660;        PWMDTY67 =0;                       PWME = 0xFF;         // 所有PWM通道使能        }                  EnableInterrupts;   }/**************************************************************************速度PID控制区域***************************************************************************  interrupt void Real_Time_Interrupt(void)  {        AbsoluteTime++; // 运行系统时钟  SpeedPID();     PORTB=(char)(PACN10);        CRGFLG = 0x80;         // 清中断标志                EnableInterrupts;  }/*******************************************************************/  void SpeedPID(void)  {   PACN0_i=PACN10;          CurrentSpeed = PACN0_i;//码盘输入引脚PT0        PACN10=0;        e_1=e;        e=CurrentSpeed-DstSpeed;//-CurrentSpeed;        if(e<-20){        PWMDTY67 =0;                  PWMDTY23 =2400;        }        else if(e>20){        PWMDTY23=0;        PWMDTY67=2400;        }        else        {        ie+=e;        speed_0=speed_0-(Kp*e/10)-(int)(Ki*ie/1000)+Kd*(e-e_1);  SetSpeed();        }  }  void SetSpeed(void)  { if(speed_0>2400)  speed_0=2400;        PWMDTY67 =0;                  PWMDTY23 =speed_0;           }   复制代码
     

文件到原文下载,原文出自:https://bbs.usoftchina.com/thread-205436-1-1.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。