内容发布更新时间 : 2025/6/22 6:47:20星期一 下面是文章的全部内容请认真阅读。
5.3.3
获取赛道信息;通过对左丢线还是右丢线来判别车体偏离中心线的程
度。
uchar RightLostCnt,LeftLostCnt; void Getline2 (uchar *a) {
uchar i;
uchar LeftLostFlog=1,RightLostFlog=1; for(i=2;i<124;i++) {
if(abs(a[i]-a[i+2])>Threshold) {
if(abs(a[i-1]-a[i+3])&&abs(a[i-2]-a[i+4])) {
LeftPot=i+1; LeftLostFlog=0; LeftLostCnt=0; }
if(a[i]>a[i+2]) {
RightPot=i+1; RightLostFlog=0; RightLostCnt=0; } } } }
if((LeftLostFlog==0)&&(RightLostFlog==0))
21
RaceFlog=NotLost; else if(LeftLostFlog==0) {
RightLostCnt++; RaceFlog=RightLost; }
else if(RightLostFlog==0) {
LeftLostCnt++; RaceFlog=LeftLost; } else
RaceFlog=AllLost;
5.4转向控制策略;
转向控制信号的源输入控制信号源自CPU对编码器信息和传感器CCD信息经过一系PID计算分别对电机控制模块输出当前小车状态下赛道对电机运转的要求。 提取赛道信息:
float Direction_P; float Direction_D;
float DirectionError0,DirectionError1,DirectionDiff; //0当前差值,1上次差值 int DirectionOut;
void DirectionControl1(void) {
float fP,fD;
float BorderCom;//丢线补偿量
22
float BorderError;//丢线偏差 //取中线偏差
if(RaceFlog==NotLost) {
Centerpot=(LeftPot+RightPot)/2; DirectionError0=Centerpot-LineCenter; }
else if (RaceFlog==RightLost) {
BorderError=LeftPot;
BorderCom=Border