Skip to content

Commit

Permalink
[Skill] add CircleRun
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Apr 11, 2024
1 parent d5c0c49 commit 2eb4c9d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Core/tactics/skill/CircleRun.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <fmt/core.h>
#include <algorithm>
#include "VisionModule.h"
#include "DribbleStatus.h"
#include <CommandFactory.h>
#include "RobotCapability.h"
#include "CircleRun.h"
namespace {
const double MAX_ACC = 6000;//mm/s^2
const double MAX_ROT_ACC = 50;
}
void CCircleRun::plan(const CVisionModule* pVision){
return ;
}
CPlayerCommand* CCircleRun::execute(const CVisionModule* pVision){
const int vecNumber = task().executor;
const CGeoPoint center = task().player.pos; // rotate center in robot coordinate
const double targetRotVel = task().player.rotvel; // omega

const PlayerVisionT& me = pVision->ourPlayer(vecNumber);
const CVector meVel = me.Vel().rotate(-me.Dir());
const double meRotVel = me.RotVel();
const double dRotVel = std::clamp(targetRotVel - meRotVel, -MAX_ROT_ACC/PARAM::Vision::FRAME_RATE, MAX_ROT_ACC/PARAM::Vision::FRAME_RATE);
const double rotVel = meRotVel + dRotVel;
const CVector me2center = center - CGeoPoint(0,0);
const double targetVelMod = me2center.mod() * rotVel;
const double targetVelDir = me2center.rotate(-std::copysign(PARAM::Math::PI/2, targetRotVel)).dir();
const CVector targetVel = Utils::Polar2Vector(targetVelMod, targetVelDir);

const CVector velDiff = targetVel - meVel;

const CVector dv = Utils::Polar2Vector(std::min(velDiff.mod(), MAX_ACC/PARAM::Vision::FRAME_RATE), velDiff.dir());

const CVector localVel = meVel + dv;

const bool needDribble = task().player.flag & PlayerStatus::DRIBBLING;
auto dribblePower = DribbleStatus::Instance()->getDribbleCommand(vecNumber);
if (needDribble) {
dribblePower = DRIBBLE_HIGHEST;
}
GDebugEngine::instance()->gui_debug_msg(me.Pos(), fmt::format("localVel: ({:.2f}, {:.2f}), rotVel: {:.2f}", localVel.x(), localVel.y(), rotVel), COLOR_GREEN);
GDebugEngine::instance()->gui_debug_line(me.Pos(), me.Pos() + localVel.rotate(me.Dir()), COLOR_GREEN);
GDebugEngine::instance()->gui_debug_line(me.Pos(), me.Pos() + me2center.rotate(me.Dir()), COLOR_GREEN);
GDebugEngine::instance()->gui_debug_x(me.Pos() + me2center.rotate(me.Dir()), COLOR_GREEN);
return CmdFactory::Instance()->newCommand(CPlayerSpeedV2(vecNumber, localVel.x(), localVel.y(), rotVel, dribblePower));
}
14 changes: 14 additions & 0 deletions Core/tactics/skill/CircleRun.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "skill_registry.h"

class CCircleRun : public CPlayerTask{
public:
CCircleRun() = default;
virtual void plan(const CVisionModule* pVision);
virtual CPlayerCommand* execute(const CVisionModule* pVision);
virtual void toStream(std::ostream& os) const { os << "CircleRun"; }
private:
int _lastCycle;
};

REGISTER_SKILL(CircleRun, CCircleRun);
22 changes: 22 additions & 0 deletions Core/tactics/skill/CircleRun.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function CircleRun(task)
matchPos = function()
return ball.pos()
end

execute = function(runner)
task_param = TaskT:new_local()
task_param.executor = runner
task_param.player.pos = CGeoPoint(100,100)
task_param.player.rotvel = 4
return skillapi:run("CircleRun", task_param)
end

return execute, matchPos
end

gSkillTable.CreateSkill{
name = "CircleRun",
execute = function (self)
print("This is in skill"..self.name)
end
}

0 comments on commit 2eb4c9d

Please sign in to comment.