ballhandle.c
来自「一个机器人提足球的代码!基于神经网络! 一个机器人提足球的代码!基于神经网络!」· C语言 代码 · 共 121 行
C
121 行
#ifndef _BALLHANDLE_
#define _BALLHANDLE_
#include "HardwareInfo.c"
#include <SetMotor.h>
#include <SetTenthS.h>
#include "turnAngle.c"
#include <GetUltrasound.h>
#include "angle.c"
#include "turn.c"
void ballHandle(unsigned int rightDistance, unsigned int leftDistance, unsigned int distance, unsigned char yfy, unsigned char jGuan)
{
unsigned int distance_middle = 0; //后超声波测距模块的返回值
unsigned int distance_left = 0; //后超声波测距模块的返回值
SetMotor(_MOTOR_left_, 2, 100);
SetMotor(_MOTOR_right_, 2, 100);
SetTenthS(2);
turnAngle(180, yfy);
for (int _FOR_3_ = 0; _FOR_3_ < 3; _FOR_3_++ )
{
distance_left = GetUltrasound(_ULTRASOUND_left_);
if ( distance_left<100 )
{
break;
}
}
if ( distance_left<leftDistance )
{
for (int _FOR_0_ = 0; _FOR_0_ < 3; _FOR_0_++ )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
if ( distance_middle<100 )
{
break;
}
}
if ( distance_middle<distance )
{
angle(270);
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 100);
SetTenthS(2);
angle(180);
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 100);
SetTenthS(2);
turnAngle(90, yfy);
}
else
{
SetMotor(_MOTOR_left_, 2, 100);
SetMotor(_MOTOR_right_, 2, 11);
SetTenthS(6);
turn(jGuan);
}
}
else
{
if ( distance_left>rightDistance )
{
for (int _FOR_1_ = 0; _FOR_1_ < 3; _FOR_1_++ )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
if ( distance_middle<100 )
{
break;
}
}
if ( distance_middle<distance )
{
angle(90);
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 100);
SetTenthS(2);
angle(180);
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 100);
SetTenthS(2);
turnAngle(270, yfy);
}
else
{
SetMotor(_MOTOR_left_, 2, 11);
SetMotor(_MOTOR_right_, 2, 100);
SetTenthS(6);
turn(jGuan);
}
}
else
{
for (int _FOR_2_ = 0; _FOR_2_ < 3; _FOR_2_++ )
{
distance_middle = GetUltrasound(_ULTRASOUND_middle_);
if ( distance_middle<100 )
{
break;
}
}
if ( distance_middle<distance )
{
SetMotor(_MOTOR_left_, 0, 100);
SetMotor(_MOTOR_right_, 0, 100);
SetTenthS(2);
SetMotor(_MOTOR_left_, 2, 10);
SetMotor(_MOTOR_right_, 2, 100);
SetTenthS(6);
turn(jGuan);
}
else
{
SetMotor(_MOTOR_right_, 2, 10);
SetMotor(_MOTOR_left_, 2, 100);
SetTenthS(6);
turn(jGuan);
}
}
}
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?