飞思卡尔智能车 智能车源代码光电组(有注解)
- 格式:doc
- 大小:78.00 KB
- 文档页数:5
智能车源代码光电组(有注解)
#include
#include
#include "math.h"
#include "PWM.h"
#include "A TD.h"
#include "LQprintp.h"
#pragma LINK_INFO DERIV A TIVE "mc9s12dg256b"
unsigned int i = 0;
unsigned int j = 0;
unsigned int t = 0;
byte ad_value[13];
uchar data[13];
int sum = 0;
uchar start_flag = 0;
uchar num = 0;
uchar lw=0;
unsigned int per = 65530;
int SPWM = 0;
int L_SPWM = 0;
unsigned int SPmax = 1000;
int MPWM = 0;
uchar current_corrd = 0;
static unsigned int mem_num = 0;
//***********************PID**************** ***************
static unsigned int Kp=25;
static unsigned int Kp2=60;
static unsigned int Ki=9;
static unsigned int Kd=30;
static unsigned int rKp=100;
static unsigned int rKp2=60;
static unsigned int rKi=0;
static unsigned int rKd=60;
unsigned short E = 5;
unsigned char q = 1;
int Mp = 0;
int Mi = 0;
int Md = 0;
int Mp2 = 0;
int P_Speed = 0;
int L_u[3];
//****************************************** ****************
//***********************舵机PID变量**********************
static unsigned int s_sKp=35; //直道PID的P值
static unsigned int s_sKp2=0; //直道PID 的二阶P值
static unsigned int s_sKi=0; //直道PID的I值static unsigned int s_sKd=10; //直道PID的D值
//****用于防止PID溢出******
unsigned short s_sE = 5;
unsigned char s_sq = 1;
//*************************
//****分别存放P I D 值*****
int s_sMp = 0;
int s_sMi = 0;
int s_sMd = 0;
int s_sMp2 = 0;
//*************************
int sL_u[3]; //存放前3次理论速度与实际速度的差值
int last_corrd[3][10] ={{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
//****************************************** ***************
//*********************PID调试中断**************************
unsigned char cp = 0;
unsigned char ci = 0;
unsigned char cd = 0;
unsigned int search_PACN10;
unsigned int np = 0;
unsigned int sp[500];
//****************************************** ****************
//*********************存储前20点的数据*********************
int L_num[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int sum_corrd = 0;
int wb = 0; //记录当前状态黑为0,白为1;
//****************************************** ****************
//********************红外滤波*****************************
int corrd[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int T_corrd = 0;
int is_white = 0;
int numb = 0;
//****************************************** ****************
//***********************数据统计***************************
int corrd_sate[23] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int SPWM_sate[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int MPWM_sate[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uchar corrd_time[512];