findball.c
来自「机器人足球教程footballteaching」· C语言 代码 · 共 119 行
C
119 行
#ifndef _FINDBALL_
#define _FINDBALL_
#include "HardwareInfo.c"
#include <GetCompoI.h>
#include <SetMotor.h>
void findBall(unsigned char jGuan)
{
unsigned char fyMax = 0; //当前最大光值的通道号
unsigned char sl = 0;
unsigned char sr = 0;
unsigned char maxIndex = 0;
fyMax = GetCompoI(_COMPOUNDEYE_Guan_, 9);
if ( fyMax<jGuan )
{
maxIndex = GetCompoI(_COMPOUNDEYE_Guan_, 8);
if ( maxIndex==7 )
{
SetMotor(_MOTOR_left_, 0, 80);
SetMotor(_MOTOR_right_, 2, 60);
}
else
{
if ( maxIndex==6 )
{
SetMotor(_MOTOR_left_, 0, 50);
SetMotor(_MOTOR_right_, 2, 20);
}
else
{
if ( maxIndex==5 )
{
SetMotor(_MOTOR_left_, 0, 25);
SetMotor(_MOTOR_right_, 1, 0);
}
else
{
if ( maxIndex==1 )
{
SetMotor(_MOTOR_left_, 2, 50);
SetMotor(_MOTOR_right_, 0, 80);
}
else
{
if ( maxIndex==2 )
{
SetMotor(_MOTOR_left_, 2, 20);
SetMotor(_MOTOR_right_, 0, 45);
}
else
{
if ( maxIndex==3 )
{
SetMotor(_MOTOR_left_, 1, 0);
SetMotor(_MOTOR_right_, 0, 25);
}
else
{
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 70);
}
}
}
}
}
}
}
else
{
maxIndex = GetCompoI(_COMPOUNDEYE_Guan_, 8);
if ( maxIndex<3 )
{
sl=1;
sr=0;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 70);
}
else
{
if ( maxIndex==3 )
{
sl=1;
sr=0;
SetMotor(_MOTOR_left_, sl, 50);
SetMotor(_MOTOR_right_, sr, 30);
}
else
{
if ( maxIndex>5 )
{
sl=0;
sr=1;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 70);
}
else
{
if ( maxIndex==5 )
{
sl=0;
sr=1;
SetMotor(_MOTOR_left_, sl, 30);
SetMotor(_MOTOR_right_, sr, 60);
}
else
{
sl=0;
sr=0;
SetMotor(_MOTOR_left_, sl, 100);
SetMotor(_MOTOR_right_, sr, 70);
}
}
}
}
}
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?