足球机器人实验报告
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
机器人足球实验报
告
专业:计算机科学与技术
课程名称:足球机器人理论与实践
指导老师:刘钊
学号: 200813137197
学生姓名:顾伟
1.实验目的
1)逐步掌握FIRA平台的使用
2)掌握FIRA客户端智能体的编写
3)完成指定的智能体功能与动作
2.程序清单:
#ifndef_AFX_NO_DAO_SUPPORT_5V5_PARAMETER
#include
#define PI 3.14159265
typedef struct {double x, y,z;} Vector3D;
typedef struct {long left, right, top, bottom;} Bounds;
typedef struct {Vector3D pos;} Ball;
typedef struct {Vector3D pos;double rotation;} OpponentRobot;
typedef struct {Vector3D pos; double rotation,velocityLeft, velocityRight;} Robot; typedef struct {
Robot home[5];
OpponentRobot opponent[5];
Ball currentBall, lastBall, predictedBall;
Bounds fieldBound, goalBound;
long gameState;
long whosBall;
void *userData;
} Environment;
//基本数据处理函数组
double angle(Vector3D p,Vector3D p0);
double angle(double x,double y,double x0,double y0);
double angle(Vector3D p0,Vector3D p);
double dist(double x1,double y1,double x2,double y2);
double dist(Vector3D p1,Vector3D p2);
double differ_two_angle(double a1,double a2);
Vector3D turn_blue(Vector3D p);
Vector3D turn_yellow(Vector3D p);
double turn_blue(double rotate);
double turn_yellow(double rotate);
//策略函数组
void act_v(int no,double vl,double vr,Environment* env);
void rotation_to(int po,double rotation,Environment* env);//po号机器人面向rotation 角度,基于坐标变换后的角度值
void run_to_pos(int po,Vector3D pos,Environment* env);//po号机器人跑到pos位置void run_to_pos2(int po,Vector3D pos,Environment*env);
#endif
3在stdfx.cpp中添加基础数据处理函数实现过程
#include"math.h"
double differ_two_angle(double a1,double a2)
{
double a=fabs(a1-a2);
if(a>180) a=360-a;
return a;
}
Vector3D turn_blue(Vector3D p)
{
Vector3D pp;
pp.x=p.y-41.8061;
pp.y=93.4259-p.x;
return pp;
}
Vector3D turn_yellow(Vector3D p)
{
Vector3D pp;
pp.x=41.8061-p.y;
pp.y=p.x-6.8118;//6.8118Field Left x coordinate
return pp;
}
double turn_blue(double rotate)
{
if(rotate<0) rotate+=360;
rotate-=90;
if(rotate<0) rotate+=360;
return rotate;
}
double turn_yellow(double rotate)//将系统的角度转换成黄队方坐标的角度
{
if(rotate<0) rotate+=360;//矫正角度
rotate+=90;
if(rotate>=360) rotate-=360;//再次矫正角度
return rotate;
}
double angle(Vector3D p,Vector3D p0)
{
return(angle(p.x,p.y,p0.x,p0.y));
}
double angle(double x,double y,double x0,double y0) //x,y为目的点,x0,y0为源点
{
//(x,y)(x0,y0)两点连线与x轴的夹角
double dx,dy,dr;
dx=x-x0;
dy=y-y0;
dr=dist(x,y,x0,y0);
if(dr<0.0001) return 0;