Skip to content

Commit

Permalink
[Core] update touch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Apr 15, 2024
1 parent 61650a7 commit 9d83b7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions Core/src/MotionControl/CMmotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void compute_motion_2d(CVector x0, CVector v0, CVector v1,

traj_accel = CVector(traj_accel_x, traj_accel_y);
traj_accel = traj_accel.rotate(rotangle);
traj_accel = Utils::Polar2Vector(std::min(traj_accel.mod(),a_max), traj_accel.dir());
if(time_x < 1e-5 || time_x > 50) time_x = 0;
if(time_y < 1e-5 || time_y > 50) time_y = 0;
time = std::max(time_x, time_y);
Expand Down
17 changes: 9 additions & 8 deletions Core/tactics/skill/Touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ void CTouch::plan(const CVisionModule* pVision){

// stupid version of getballPos
CGeoPoint bestPos = BallSpeedModel::instance()->poseForTime(1.0).Pos();
for(double dist = 0; dist < 3000; dist += 100){
for(double dist = 0; dist < 3000; dist += 20){
auto pos = ballPos + Utils::Polar2Vector(dist, ballVelDir);
double t1 = predictedTimeWithRawVel(me, pos);
double t2 = BallSpeedModel::Instance()->timeForDist(dist);
GDebugEngine::Instance()->gui_debug_x(pos,COLOR_GREEN);
GDebugEngine::Instance()->gui_debug_msg(pos, fmt::format("t:{:.2f},{:.2f}", t1, t2), COLOR_GREEN);
if (DEBUG_SWITCH){
GDebugEngine::Instance()->gui_debug_x(pos,COLOR_GREEN);
GDebugEngine::Instance()->gui_debug_msg(pos, fmt::format("t:{:.1f}", t1-t2), COLOR_GREEN, 0, 30);
}
if(t1 < t2 || t1 < 0.1){
bestPos = pos;
break;
Expand All @@ -65,7 +67,7 @@ void CTouch::plan(const CVisionModule* pVision){
const double ballVel_ball2Target_ad = ballVelMod > 300 ? angleDiff(ballVelDir, (target - ballPos).dir()) : 180;
const bool angleCanTouch = std::abs(ballVel_ball2Target_ad) > 100 / 180.0 * PARAM::Math::PI;

const CVector targetRunVel = canWaitForBall ? CVector(0, 0) : Utils::Polar2Vector(200, ballVelDir);
// const CVector targetRunVel = canWaitForBall ? CVector(0, 0) : Utils::Polar2Vector(200, ballVelDir);
const CGeoPoint targetMousePos = canWaitForBall ? projectionMousePos : predictPos;
const double targetRunDir = (useInter || !angleCanTouch) ? Utils::Normalize(ballVelDir + PARAM::Math::PI) : (target - targetMousePos).dir();
const CGeoPoint targetRunPos = targetMousePos + Utils::Polar2Vector(PARAM::Vehicle::V2::PLAYER_CENTER_TO_BALL_CENTER, targetRunDir + PARAM::Math::PI);
Expand All @@ -82,7 +84,7 @@ void CTouch::plan(const CVisionModule* pVision){

const auto diff4avoid_ball = std::abs(angleDiff(me2target.dir(), (targetMousePos - ballPos).dir()));
const auto needAvoidDynamic = !BALL_STATIC && me2TargetSeg.IsPointOnLineOnSegment(ballPos) && diff4avoid_ball < 90 / 180.0 * PARAM::Math::PI;
const auto avoidDistDynamic = needAvoidDynamic ? 3*clip(90-diff4avoid_ball *180.0 / PARAM::Math::PI,0.0,90.0) : 0;
const auto avoidDistDynamic = needAvoidDynamic ? 0.5*clip(90-diff4avoid_ball *180.0 / PARAM::Math::PI,0.0,90.0)+20 : 0;

double avoid_dist = 0;
if (toBallDist > 120 && (needAvoidStatic || needAvoidDynamic)){
Expand All @@ -93,15 +95,14 @@ void CTouch::plan(const CVisionModule* pVision){
TaskT newTask(task());
newTask.player.pos = targetRunPos;
newTask.player.angle = targetRunDir;
newTask.player.vel = targetRunVel;
// newTask.player.vel = targetRunVel;
newTask.player.flag = taskFlag;
newTask.ball.avoid_dist = 300;
newTask.ball.avoid_dist = avoid_dist;
setSubTask("SmartGoto", newTask);

if(DEBUG_SWITCH){
auto endPos = ballPos + Utils::Polar2Vector(ballVelMod,ballVelDir);
GDebugEngine::Instance()->gui_debug_line(ballPos,endPos,4);
GDebugEngine::Instance()->gui_debug_msg(targetRunPos, fmt::format("TVel:{:.0f},me2SegT:{:3.1f},b2SegT:{:3.1f}", targetRunVel.mod(), me2segTime, ball2segTime));
GDebugEngine::Instance()->gui_debug_msg(targetRunPos+CVector(0,120), fmt::format("modeDif:{:.1f}", ballVel_ball2Target_ad / PARAM::Math::PI * 180.0));
}

Expand Down

0 comments on commit 9d83b7a

Please sign in to comment.