comeback.c

来自「一个机器人提足球的代码!基于神经网络! 一个机器人提足球的代码!基于神经网络!」· C语言 代码 · 共 88 行

C
88
字号
#ifndef _COMEBACK_
#define _COMEBACK_
#include "HardwareInfo.c"
#include "turnAngle.c"
#include <GetUltrasound.h>
#include <SetMotor.h>
#include "returnOut.c"
#include <SetCentiS.h>
#include "stop.c"

void comeBack(unsigned char yfy, unsigned int middleDistance, unsigned int distance)
{
    unsigned int distance_middle = 0;   //装在机器人后面的超声波测距模块的返回变量值。
    unsigned char fyMax = 0;   //当前复眼所有通道的最大光值。
    unsigned char i = 0;   //returnOut()的返回值。
    turnAngle(0, yfy);
    for (int _FOR_0_ = 0; _FOR_0_ < 3; _FOR_0_++ )
    {
        distance_middle = GetUltrasound(_ULTRASOUND_middle_);
        if ( distance_middle<100 )
        {
            break;
        }
    }
    if ( distance_middle>distance )
    {
        while ( distance_middle>distance )
        {
            SetMotor(_MOTOR_left_, 2, 100);
            SetMotor(_MOTOR_right_, 2, 56);
            distance_middle = GetUltrasound(_ULTRASOUND_middle_);
            while ( distance_middle==888 )
            {
                distance_middle = GetUltrasound(_ULTRASOUND_middle_);
                i = returnOut(yfy);
                if ( i==1 )
                {
                    return ;
                }
            }
            i = returnOut(yfy);
            if ( i==1 )
            {
                return ;
            }
        }
        SetMotor(_MOTOR_left_, 0, 100);
        SetMotor(_MOTOR_right_, 0, 100);
        SetCentiS(26);
    }
    else
    {
        if ( distance_middle<middleDistance )
        {
            while ( distance_middle<distance )
            {
                SetMotor(_MOTOR_left_, 0, 40);
                SetMotor(_MOTOR_right_, 0, 40);
                distance_middle = GetUltrasound(_ULTRASOUND_middle_);
                while ( distance_middle==888 )
                {
                    distance_middle = GetUltrasound(_ULTRASOUND_middle_);
                    i = returnOut(yfy);
                    if ( i==1 )
                    {
                        return ;
                    }
                }
                i = returnOut(yfy);
                if ( i==1 )
                {
                    return ;
                }
            }
            SetMotor(_MOTOR_left_, 2, 100);
            SetMotor(_MOTOR_right_, 2, 70);
            SetCentiS(20);
        }
        else
        {
            turnAngle(0, yfy);
            stop(yfy);
        }
    }
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?