睿抗足球机器人

一、一次传球

1.现象

目前已经能够实现第一次传球是非常的顺利了,因为我加了两个判断,所以我传球机器人的所需要找的位置还有它判断踢球是相当的流畅。只是需要注意一点,我的接球机器人只要不在白线上,那么我的接球机器人的朝向还有它的位置就不会有什么偏差。所以光从传球的现象上看基本上的错误率是相当小了

2.lua脚本代码
gPlayTable.CreatePlay{
firstState = "1",
["1"] = {
  switch = function() 
   if CIsBallKick("Kicker") then
       return "2"
    end
  end,
   Kicker = task.KickerTask("cq1"),
   Receiver = task.ReceiverTask("jq1"),
},
name = "CH1" 
}
3.C++代码
(1)传球机器人的代码

 这个代码比之前的代码要进步两个方面:一方面是它的找球的错误率目前看来要小一些了,另一方面是,我直接把踢球操作写进C++里面了,没有像之前那样在lua脚本里面再写一个程序来专门控制踢球。

#include "ball.h"
#include "basevision.h"
#include "constants.h"
#include "FilteredObject.h"
#include "game_state.h"
#include "historylogger.h"
#include "matchstate.h"
#include "maths.h"
#include "PlayerTask.h"
#include "referee_commands.h"
#include "robot.h"
#include "singleton.h"
#include "util.h"
#include "vector.h"
#include "worldmodel.h"

extern "C"_declspec(dllexport) PlayerTask player_plan(const WorldModel* model, int robot_id);
PlayerTask player_plan(const WorldModel* model, int robot_id)
{
	PlayerTask task;
	int receiver_id = -7;
	for (int i = 0; i < 6; i++)
	{
		if (i == robot_id || i == model->get_our_goalie())
		{
			continue;
		}
		if (model->get_our_exist_id()[i])
		{
			receiver_id = i;
		}
	}
	//获取中场机器人的向量坐标
	const point2f& receiver_pos = model->get_our_player_pos(receiver_id);
	//获取中场球员的朝向
	const float&receiver_dir = model->get_our_player_dir(receiver_id);
	//获取前锋机器人的向量坐标
	const point2f& kicker_pos = model->get_our_player_pos(robot_id);
	//获取前锋球员的朝向
	const float&kicker_dir = model->get_our_player_dir(robot_id);
	//获取球的向量坐标 
	const point2f&ball_pos = model->get_ball_pos();
	//这里设定face_dir是前锋传球机器人朝向球的方向
	const float&face_dir = (receiver_pos - ball_pos).angle();
	//到达目标点朝向:队员正对球
	task.orientate = face_dir;
	//需要到达目标点的坐标=球的位置+向量偏移距离fac_dir反方向偏移10
	task.target_pos = ball_pos - Maths::vector2polar(50, face_dir);

	const float&receiver_to_ball = (ball_pos - receiver_pos).angle();
	const float&ball_to_passer = (kicker_pos - ball_pos).angle();
	bool get_ball = fabs(receiver_to_ball - ball_to_passer) < 0.5;
	bool pass = (ball_pos - kicker_pos).length() < get_ball_threshold - 1.5 && (fabs(anglemod(kicker_dir - (ball_pos - kicker_pos).angle())) < PI / 6);
	if (get_ball)
	{
		task.target_pos = ball_pos - Maths::vector2polar(10, face_dir);
		if (pass)
		{
			task.kickPower = 127;
			task.needKick = true;
		}
	}

	return task;
}
(2)接球机器人的代码

 我感觉这个代码还可以再优化一下,具体怎么优化还没想好,因为目前还没有bug

#include "ball.h"
#include "basevision.h"
#include "constants.h"
#include "FilteredObject.h"
#include "game_state.h"
#include "historylogger.h"
#include "matchstate.h"
#include "maths.h"
#include "PlayerTask.h"
#include "referee_commands.h"
#include "robot.h"
#include "singleton.h"
#include "util.h"
#include "vector.h"
#include "worldmodel.h"

extern "C"_declspec(dllexport) PlayerTask player_plan(const WorldModel* model, int robot_id);
PlayerTask player_plan(const WorldModel* model, int kicker_id )
{
	PlayerTask task;
	
	//获取前锋机器人的向量坐标
	const point2f& kicker_pos = model->get_opp_player_pos(kicker_id);
	//获取前锋球员的朝向
	const float&kicker_dir = model->get_opp_player_dir(kicker_id);
	
	//获取球的向量坐标
	const point2f&ball_pos = model->get_ball_pos();
	//这里设定face_dir是中场接球机器人朝向球的方向
	const float&face_dir = (kicker_pos - ball_pos).angle();
	//到达目标点朝向:队员正对球
	task.orientate = face_dir;
	//需要到达目标点的坐标=球的位置+向量偏移距离//fac_dir反方向偏移200
	task.target_pos = ball_pos - Maths::vector2polar(200, face_dir);

	return task;
}

二、二次传球代码

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值