⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wulongqiu.c

📁 机器人足球教程footballteaching
💻 C
字号:
#include "HardwareInfo.c"
#include <SetSysTime.h>
#include <GetCompoI.h>
#include <GetCompassB.h>
#include <GetSysTime.h>
#include <SetMotor.h>
#include <SetCentiS.h>
#include "TurnAngle.c"
#include <GetUltrasound.h>

int main(void)
{
    unsigned char GuanMax = 0;   //当前所有通道的最大光值
    unsigned char Guan3 = 0;   //当前3号通道的光值
    unsigned char GuanKan = 55;   //远距离光值,一般是没有球的情况下的光值,再加上3-5就好了。
    unsigned char Guan4 = 0;   //当前4号通道光值
    unsigned char Guan5 = 0;   //当前5号通道光值
    unsigned char MaxNo = 0;   //当前最大光值的通道号
    unsigned int b = 0;   //当前角度值
    unsigned long t = 0;   //当前系统时间
    unsigned char q1 = 115;   //场地定义角
    unsigned char q2 = 245;   //场地定义角
    unsigned int p1 = 45;   //场地定义角
    unsigned int p2 = 315;   //场地定义角
    unsigned char JGuan = 180;   //较近距离的光值阀值,用在乌龙球的处理
    unsigned int you = 0;   //当前超声测距读数
    SetSysTime(0);
    while (1)
    {
        MaxNo = GetCompoI(_COMPOUNDEYE_Guang_, 8);
        GuanMax = GetCompoI(_COMPOUNDEYE_Guang_, 9);
        Guan3 = GetCompoI(_COMPOUNDEYE_Guang_, 3);
        Guan4 = GetCompoI(_COMPOUNDEYE_Guang_, 4);
        Guan5 = GetCompoI(_COMPOUNDEYE_Guang_, 5);
        b = GetCompassB(_COMPASS_1_);
        t = GetSysTime();
        if ( ((Guan3>JGuan)||(Guan4>JGuan)||(Guan5>JGuan))&&((b>=q1)&&(b<=q2)) )
        {
            SetMotor(_MOTOR_left_, 2, 100);
            SetMotor(_MOTOR_right_, 2, 100);
            SetCentiS(2);
            TurnAngle(180);
            while (1)
            {
                you = GetUltrasound(_ULTRASOUND_right_);
                if ( you!=9999&&you!=0 )
                {
                    break;
                }
            }
            if ( you<=55 )
            {
                SetMotor(_MOTOR_left_, 2, 100);
                SetMotor(_MOTOR_right_, 2, 40);
            }
            else
            {
                SetMotor(_MOTOR_left_, 2, 40);
                SetMotor(_MOTOR_right_, 2, 100);
            }
            t=0;
            SetSysTime(0);
            while ( ((b>5)&&(b<355))  )
            {
                b = GetCompassB(_COMPASS_1_);
                t = GetSysTime();
                if ( t>100 )
                {
                    break;
                }
            }
            SetMotor(_MOTOR_left_, 2, 100);
            SetMotor(_MOTOR_right_, 2, 100);
            b = GetCompassB(_COMPASS_1_);
            SetSysTime(0);
            t = GetSysTime();
            Guan3 = GetCompoI(_COMPOUNDEYE_Guang_, 3);
            Guan4 = GetCompoI(_COMPOUNDEYE_Guang_, 4);
            Guan5 = GetCompoI(_COMPOUNDEYE_Guang_, 5);
            while ( ((Guan3<125||Guan4<125 || Guan5 <125) && ((b<p1) ||(b>p2))) && t<60 )
            {
                b = GetCompassB(_COMPASS_1_);
                Guan3 = GetCompoI(_COMPOUNDEYE_Guang_, 3);
                Guan4 = GetCompoI(_COMPOUNDEYE_Guang_, 4);
                Guan5 = GetCompoI(_COMPOUNDEYE_Guang_, 5);
                t = GetSysTime();
            }
            SetSysTime(0);
        }
        if ( GuanMax>GuanKan )
        {
            SetSysTime(0);
            if ( MaxNo==7 )
            {
                SetMotor(_MOTOR_left_, 0, 80);
                SetMotor(_MOTOR_right_, 1, 50);
            }
            else
            {
                if ( MaxNo==6 )
                {
                    SetMotor(_MOTOR_left_, 0, 60);
                    SetMotor(_MOTOR_right_, 1, 25);
                }
                else
                {
                    if ( MaxNo==5 )
                    {
                        SetMotor(_MOTOR_left_, 0, 40);
                        SetMotor(_MOTOR_right_, 1, 100);
                    }
                    else
                    {
                        if ( MaxNo==1 )
                        {
                            SetMotor(_MOTOR_left_, 1, 50);
                            SetMotor(_MOTOR_right_, 0, 80);
                        }
                        else
                        {
                            if ( MaxNo==2 )
                            {
                                SetMotor(_MOTOR_left_, 1, 25);
                                SetMotor(_MOTOR_right_, 0, 60);
                            }
                            else
                            {
                                if ( MaxNo==3 )
                                {
                                    SetMotor(_MOTOR_left_, 1, 100);
                                    SetMotor(_MOTOR_right_, 0, 40);
                                }
                                else
                                {
                                    SetMotor(_MOTOR_left_, 0, 100);
                                    SetMotor(_MOTOR_right_, 0, 100);
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            SetMotor(_MOTOR_left_, 0, 50);
            SetMotor(_MOTOR_right_, 2, 50);
        }
    }
    return 1;
}

⌨️ 快捷键说明

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