?? defengsivefootball.c
字號:
#ifndef _DEFENGSIVEFOOTBALL_
#define _DEFENGSIVEFOOTBALL_
#include "HardwareInfo.c"
#include <GetCompoI.h>
#include <SetMotor.h>
#include "turnAngle.c"
#include <GetUltrasound.h>
#include "goline.c"
#include "returnOut.c"
#include "comeBack.c"
void defengsiveFootball(unsigned char yfy, unsigned char var0, unsigned char jfy, unsigned int dis_left, unsigned int dis_right, unsigned char No, unsigned int distance, unsigned int middleDistance, unsigned int backDistance, unsigned int dis_middle)
{
unsigned char fyMax = 0; //當前復眼所有通道的最大光值。
unsigned char maxIndex = 0; //當前復眼最大光值的通道號。
unsigned int distance_middle = 0; //裝在機器人后面的超聲波測距模塊的返回變量值。
unsigned int distance_left = 0; //裝在機器人左面的超聲波測距模塊的返回變量值。
unsigned char sr = 0; //右馬達控制命令字,若為0,向前轉,為1則停止。
unsigned char sl = 0; //右馬達控制命令字,若為0,向前轉,為1則停止。
unsigned char i = 0; //returnOut()的返回值。
unsigned char fyMin = 0; //當前復眼所有通道的最小光值。
while (1)
{
fyMax = GetCompoI(_COMPOUNDEYE_fy_, 9);
fyMin = GetCompoI(_COMPOUNDEYE_fy_, 11);
if ( (fyMax>yfy)||((fyMax-fyMin)>var0) )
{
if ( fyMax>jfy )
{
maxIndex = GetCompoI(_COMPOUNDEYE_fy_, 8);
if ( maxIndex==7 )
{
SetMotor(_MOTOR_left_, 0, 80);
SetMotor(_MOTOR_right_, 2, 50);
}
else
{
if ( maxIndex==6 )
{
SetMotor(_MOTOR_left_, 0, 80);
SetMotor(_MOTOR_right_, 2, 20);
}
else
{
if ( maxIndex==5 )
{
SetMotor(_MOTOR_left_, 0, 50);
SetMotor(_MOTOR_right_, 1, 100);
}
else
{
if ( maxIndex==1 )
{
SetMotor(_MOTOR_left_, 2, 50);
SetMotor(_MOTOR_right_, 0, 100);
}
else
{
if ( maxIndex==2 )
{
SetMotor(_MOTOR_left_, 2, 20);
SetMotor(_MOTOR_right_, 0, 100);
}
else
{
if ( maxIndex==3 )
{
SetMotor(_MOTOR_left_, 1, 100);
SetMotor(_MOTOR_right_, 0, 50);
}
else
{
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 70);
}
}
}
}
}
}
}
else
{
maxIndex = GetCompoI(_COMPOUNDEYE_fy_, 8);
if ( maxIndex<4 )
{
sl=1;
sr=0;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 100);
}
else
{
if ( maxIndex>4 )
{
sl=0;
sr=1;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 100);
}
else
{
sl=0;
sr=0;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 100);
}
}
}
}
else
{
turnAngle(0, yfy);
for (int _FOR_0_ = 0; _FOR_0_ < 3; _FOR_0_++ )
{
distance_left = GetUltrasound(_ULTRASOUND_left_);
if ( distance_left<110 )
{
break;
}
}
for (int _FOR_1_ = 0; _FOR_1_ < 3; _FOR_1_++ )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
if ( distance_middle<=110 )
{
break;
}
}
if ( distance_left<dis_left )
{
while ( (distance_middle<dis_middle) )
{
goline(No, yfy, 90, distance);
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
while ( distance_middle==888 )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
i = returnOut(yfy);
if ( i==1 )
{
break;
}
}
i = returnOut(yfy);
if ( i==1 )
{
break;
}
}
turnAngle(0, yfy);
}
else
{
if ( distance_left>dis_right )
{
while ( (distance_middle<dis_middle) )
{
goline(No, yfy, 270, distance);
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
while ( distance_middle==888 )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
i = returnOut(yfy);
if ( i==1 )
{
break;
}
}
i = returnOut(yfy);
if ( i==1 )
{
break;
}
}
turnAngle(0, yfy);
}
}
comeBack(yfy, middleDistance, backDistance);
turnAngle(0, yfy);
}
}
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -