-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |