diff --git a/docs/fsm-diagrams.md b/docs/fsm-diagrams.md index e7eaacc78a..88d30fdf4b 100644 --- a/docs/fsm-diagrams.md +++ b/docs/fsm-diagrams.md @@ -429,7 +429,7 @@ Terminate:::terminate --> Terminate:::terminate : SET_STOP_PRIMITIVE_ACTION GetBehindBallFSM GetBehindBallFSM --> GetBehindBallFSM : updateGetBehindBall -GetBehindBallFSM --> KickState -KickState --> GetBehindBallFSM : [shouldRealignWithBall]\nupdateGetBehindBall -KickState --> KickState : [!ballChicked]\nupdateKick -KickState --> Terminate:::terminate : [ballChicked]\nSET_STOP_PRIMITIVE_ACTION +GetBehindBallFSM --> KickOrChipState +KickOrChipState --> GetBehindBallFSM : [shouldRealignWithBall]\nupdateGetBehindBall +KickOrChipState --> KickOrChipState : [!ballChicked]\nkickOrChipBall +KickOrChipState --> Terminate:::terminate : [ballChicked]\nSET_STOP_PRIMITIVE_ACTION Terminate:::terminate --> Terminate:::terminate : SET_STOP_PRIMITIVE_ACTION ``` @@ -489,11 +489,11 @@ classDef terminate fill:white,color:black,font-weight:bold direction LR [*] --> DribbleFSM DribbleFSM --> DribbleFSM : [!takePenaltyShot]\nupdateApproachKeeper -DribbleFSM --> KickFSM : [timeOutApproach]\nshoot +DribbleFSM --> KickOrChipFSM : [timeOutApproach]\nshoot DribbleFSM --> DribbleFSM : adjustOrientationForShot -DribbleFSM --> KickFSM -KickFSM --> KickFSM : shoot -KickFSM --> Terminate:::terminate +DribbleFSM --> KickOrChipFSM +KickOrChipFSM --> KickOrChipFSM : shoot +KickOrChipFSM --> Terminate:::terminate Terminate:::terminate --> Terminate:::terminate : SET_STOP_PRIMITIVE_ACTION ``` diff --git a/src/proto/tactic.proto b/src/proto/tactic.proto index afc537c1b4..208cdb4f1e 100644 --- a/src/proto/tactic.proto +++ b/src/proto/tactic.proto @@ -13,15 +13,14 @@ message AssignedTacticPlayControlParams message Tactic { + reserved 2, 7; oneof tactic { AttackerTactic attacker = 1; - ChipTactic chip = 2; CreaseDefenderTactic crease_defender = 3; DribbleTactic dribble = 4; GetBehindBallTactic get_behind_ball = 5; GoalieTactic goalie = 6; - KickTactic kick = 7; MoveGoalieToGoalLineTactic move_goalie_to_goal_line = 8; MoveTactic move = 9; PenaltyKickTactic penalty_kick = 10; @@ -30,6 +29,7 @@ message Tactic ShadowEnemyTactic shadow_enemy = 13; HaltTactic halt = 14; PassDefenderTactic pass_defender = 15; + KickOrChipTactic kick_or_chip = 16; } } @@ -44,16 +44,6 @@ message AttackerTactic optional Point chip_target = 3; } -message ChipTactic -{ - // The location where the chip will be taken from - required Point chip_origin = 1; - // The direction the Robot will chip in - required Angle chip_direction = 2; - // The distance the robot will chip to - required double chip_distance_meters = 3; -} - enum CreaseDefenderAlignment { LEFT = 0; @@ -106,16 +96,6 @@ message GoalieTactic required MaxAllowedSpeedMode max_allowed_speed_mode = 1; } -message KickTactic -{ - // The location where the kick will be taken from - required Point kick_origin = 1; - // The direction the Robot will kick in - required Angle kick_direction = 2; - // How fast the Robot will kick the ball in meters per second - required double kick_speed_meters_per_second = 3; -} - message MoveGoalieToGoalLineTactic {} message MoveTactic @@ -177,3 +157,13 @@ message ShadowEnemyTactic } message HaltTactic {} + +message KickOrChipTactic +{ + // The location where the kick or chip will be taken from + required Point kick_or_chip_origin = 1; + // The direction the Robot will kick or chip in + required Angle kick_or_chip_direction = 2; + // How the robot will chip or kick the ball + required AutoChipOrKick auto_chip_or_kick = 3; +} diff --git a/src/software/ai/hl/stp/play/free_kick/BUILD b/src/software/ai/hl/stp/play/free_kick/BUILD index 80c9bc2114..72bce77758 100644 --- a/src/software/ai/hl/stp/play/free_kick/BUILD +++ b/src/software/ai/hl/stp/play/free_kick/BUILD @@ -19,9 +19,9 @@ cc_library( "//software/ai/evaluation:possession", "//software/ai/hl/stp/play", "//software/ai/hl/stp/play/defense:defense_play", - "//software/ai/hl/stp/tactic/chip:chip_tactic", "//software/ai/hl/stp/tactic/crease_defender:crease_defender_tactic", "//software/ai/hl/stp/tactic/goalie:goalie_tactic", + "//software/ai/hl/stp/tactic/kick_or_chip:kick_or_chip_tactic", "//software/ai/hl/stp/tactic/move:move_tactic", "//software/ai/hl/stp/tactic/receiver:receiver_tactic", "//software/ai/passing:eighteen_zone_pitch_division", diff --git a/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.cpp b/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.cpp index 2d6f1687d3..375241c806 100644 --- a/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.cpp +++ b/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.cpp @@ -4,9 +4,8 @@ FreeKickPlayFSM::FreeKickPlayFSM( std::shared_ptr ai_config_ptr) : PlayFSM(ai_config_ptr), align_to_ball_tactic(std::make_shared(ai_config_ptr)), - shoot_tactic(std::make_shared(ai_config_ptr)), - chip_tactic(std::make_shared(ai_config_ptr)), - passer_tactic(std::make_shared(ai_config_ptr)), + kick_or_chip_tactic(std::make_shared(ai_config_ptr)), + passer_tactic(std::make_shared(ai_config_ptr)), receiver_tactic(std::make_shared(ai_config_ptr)), receiver_positioning_tactics({std::make_shared(ai_config_ptr), std::make_shared(ai_config_ptr)}), @@ -146,12 +145,14 @@ void FreeKickPlayFSM::shootBall(const Update& event) LOG(INFO) << "Shooting ball."; PriorityTacticVector tactics_to_run = {{}}; - Point ball_pos = event.common.world_ptr->ball().position(); + Point ball_pos = event.common.world_ptr->ball().position(); + AutoChipOrKick auto_chip_or_kick = {AutoChipOrKickMode::AUTOKICK, + BALL_MAX_SPEED_METERS_PER_SECOND}; - shoot_tactic->updateControlParams( + kick_or_chip_tactic->updateControlParams( ball_pos, (shot->getPointToShootAt() - ball_pos).orientation(), - BALL_MAX_SPEED_METERS_PER_SECOND); - tactics_to_run[0].emplace_back(shoot_tactic); + auto_chip_or_kick); + tactics_to_run[0].emplace_back(kick_or_chip_tactic); event.common.set_tactics(tactics_to_run); } @@ -200,9 +201,10 @@ void FreeKickPlayFSM::chipBall(const Update& event) } } - chip_tactic->updateControlParams(event.common.world_ptr->ball().position(), - chip_target); - tactics_to_run[0].emplace_back(chip_tactic); + AutoChipOrKick auto_chip_or_kick = {AutoChipOrKickMode::AUTOCHIP, + (chip_target - ball_pos).length()}; + kick_or_chip_tactic->updateControlParams(ball_pos, chip_target, auto_chip_or_kick); + tactics_to_run[0].emplace_back(kick_or_chip_tactic); event.common.set_tactics(tactics_to_run); } @@ -288,8 +290,9 @@ void FreeKickPlayFSM::passBall(const Update& event) Pass pass = best_pass_and_score_so_far.pass; + AutoChipOrKick auto_chip_or_kick = {AutoChipOrKickMode::AUTOKICK, pass.speed()}; passer_tactic->updateControlParams(pass.passerPoint(), pass.passerOrientation(), - pass.speed()); + auto_chip_or_kick); receiver_tactic->updateControlParams(pass); tactics_to_run[0].emplace_back(passer_tactic); tactics_to_run[0].emplace_back(receiver_tactic); @@ -304,7 +307,7 @@ void FreeKickPlayFSM::passBall(const Update& event) bool FreeKickPlayFSM::shotDone(const Update& event) { - return shoot_tactic->done(); + return kick_or_chip_tactic->done(); } bool FreeKickPlayFSM::passDone(const FreeKickPlayFSM::Update& event) @@ -314,5 +317,5 @@ bool FreeKickPlayFSM::passDone(const FreeKickPlayFSM::Update& event) bool FreeKickPlayFSM::chipDone(const FreeKickPlayFSM::Update& event) { - return chip_tactic->done(); + return kick_or_chip_tactic->done(); } diff --git a/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.h b/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.h index 31f9a8c4fc..5519746e4e 100644 --- a/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.h +++ b/src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.h @@ -5,9 +5,8 @@ #include "software/ai/evaluation/calc_best_shot.h" #include "software/ai/hl/stp/play/defense/defense_play.h" #include "software/ai/hl/stp/play/play.h" -#include "software/ai/hl/stp/tactic/chip/chip_tactic.h" #include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h" -#include "software/ai/hl/stp/tactic/kick/kick_tactic.h" +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" #include "software/ai/hl/stp/tactic/move/move_tactic.h" #include "software/ai/hl/stp/tactic/receiver/receiver_tactic.h" #include "software/ai/passing/eighteen_zone_pitch_division.h" @@ -266,9 +265,8 @@ struct FreeKickPlayFSM : PlayFSM private: std::optional shot; std::shared_ptr align_to_ball_tactic; - std::shared_ptr shoot_tactic; - std::shared_ptr chip_tactic; - std::shared_ptr passer_tactic; + std::shared_ptr kick_or_chip_tactic; + std::shared_ptr passer_tactic; std::shared_ptr receiver_tactic; std::vector> receiver_positioning_tactics; std::shared_ptr defense_play; diff --git a/src/software/ai/hl/stp/play/kickoff_friendly/BUILD b/src/software/ai/hl/stp/play/kickoff_friendly/BUILD index 17e661499b..e00d6bb685 100644 --- a/src/software/ai/hl/stp/play/kickoff_friendly/BUILD +++ b/src/software/ai/hl/stp/play/kickoff_friendly/BUILD @@ -17,7 +17,7 @@ cc_library( "//software/ai/evaluation:enemy_threat", "//software/ai/evaluation:find_open_areas", "//software/ai/hl/stp/play", - "//software/ai/hl/stp/tactic/chip:chip_tactic", + "//software/ai/hl/stp/tactic/kick_or_chip:kick_or_chip_tactic", "//software/ai/hl/stp/tactic/move:move_tactic", "//software/logger", "//software/util/generic_factory", diff --git a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.cpp b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.cpp index 7c1afd31f9..0708c8b5cc 100644 --- a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.cpp +++ b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.cpp @@ -129,7 +129,10 @@ void KickoffFriendlyPlayFSM::chipBall(const Update& event) selected_target = best_target_it->origin(); } - kickoff_chip_tactic->updateControlParams(ball_position, selected_target); + kickoff_chip_tactic->updateControlParams( + ball_position, selected_target, + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, + (selected_target - ball_position).length()}); tactics_to_run[0].emplace_back(kickoff_chip_tactic); event.common.set_tactics(tactics_to_run); } diff --git a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.h b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.h index 28787b434b..61ac1ab620 100644 --- a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.h +++ b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_fsm.h @@ -6,7 +6,7 @@ #include "software/ai/evaluation/find_open_areas.h" #include "software/ai/hl/stp/play/play.h" #include "software/ai/hl/stp/play/play_fsm.hpp" -#include "software/ai/hl/stp/tactic/chip/chip_tactic.h" +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" #include "software/ai/hl/stp/tactic/move/move_tactic.h" #include "software/logger/logger.h" diff --git a/src/software/ai/hl/stp/play/kickoff_friendly_play.cpp b/src/software/ai/hl/stp/play/kickoff_friendly_play.cpp new file mode 100644 index 0000000000..f4c80d9d9d --- /dev/null +++ b/src/software/ai/hl/stp/play/kickoff_friendly_play.cpp @@ -0,0 +1,146 @@ +#include "software/ai/hl/stp/play/kickoff_friendly_play.h" + +#include "shared/constants.h" +#include "software/ai/evaluation/enemy_threat.h" +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" +#include "software/ai/hl/stp/tactic/move/move_tactic.h" +#include "software/util/generic_factory/generic_factory.h" + +KickoffFriendlyPlay::KickoffFriendlyPlay( + std::shared_ptr ai_config_ptr) + : Play(ai_config_ptr, true) +{ +} + +void KickoffFriendlyPlay::getNextTactics(TacticCoroutine::push_type& yield, + const WorldPtr& world_ptr) +{ + // Since we only have 6 robots at the maximum, the number one priority + // is the robot doing the kickoff up front. The goalie is the second most + // important, followed by 3 and 4 setup for offense. 5 and 6 will stay + // back near the goalie just in case the ball quickly returns to the friendly + // side of the field. + // + // +--------------------+--------------------+ + // | | | + // | 3 | | + // | | | + // +--+ 5 | +--+ + // | | | | | + // | | +-+-+ | | + // |2 | |1 | | | + // | | +-+-+ | | + // | | | | | + // +--+ 6 | +--+ + // | | | + // | 4 | | + // | | | + // +--------------------+--------------------+ + // + // This is a two part play: + // Part 1: Get into position, but don't touch the ball (ref kickoff) + // Part 2: Chip the ball over the defender (ref normal start) + + // the following positions are in the same order as the positions shown above, + // excluding the goalie for part 1 of this play + std::vector kickoff_setup_positions = { + // Robot 1 + Point(world_ptr->field().centerPoint() + + Vector(-world_ptr->field().centerCircleRadius(), 0)), + // Robot 2 + // Goalie positions will be handled by the goalie tactic + // Robot 3 + Point( + world_ptr->field().centerPoint() + + Vector(-world_ptr->field().centerCircleRadius() - 4 * ROBOT_MAX_RADIUS_METERS, + -1.0 / 3.0 * world_ptr->field().yLength())), + // Robot 4 + Point( + world_ptr->field().centerPoint() + + Vector(-world_ptr->field().centerCircleRadius() - 4 * ROBOT_MAX_RADIUS_METERS, + 1.0 / 3.0 * world_ptr->field().yLength())), + // Robot 5 + Point(world_ptr->field().friendlyGoalpostPos().x() + + world_ptr->field().defenseAreaXLength() + 2 * ROBOT_MAX_RADIUS_METERS, + world_ptr->field().friendlyGoalpostPos().y()), + // Robot 6 + Point(world_ptr->field().friendlyGoalpostNeg().x() + + world_ptr->field().defenseAreaXLength() + 2 * ROBOT_MAX_RADIUS_METERS, + world_ptr->field().friendlyGoalpostNeg().y()), + }; + + // move tactics to use to move to positions defined above + std::vector> move_tactics = { + std::make_shared(ai_config_ptr), + std::make_shared(ai_config_ptr), + std::make_shared(ai_config_ptr), + std::make_shared(ai_config_ptr), + std::make_shared(ai_config_ptr)}; + + // specific tactics + auto kickoff_chip_tactic = std::make_shared(ai_config_ptr); + + // Part 1: setup state (move to key positions) + while (world_ptr->gameState().isSetupState()) + { + auto enemy_threats = + getAllEnemyThreats(world_ptr->field(), world_ptr->friendlyTeam(), + world_ptr->enemyTeam(), world_ptr->ball(), false); + + PriorityTacticVector result = {{}}; + + // set the requirement that Robot 1 must be able to kick and chip + move_tactics.at(0)->mutableRobotCapabilityRequirements() = { + RobotCapability::Kick, RobotCapability::Chip}; + + // setup 5 kickoff positions in order of priority + for (unsigned i = 0; i < kickoff_setup_positions.size(); i++) + { + move_tactics.at(i)->updateControlParams(kickoff_setup_positions.at(i), + Angle::zero()); + result[0].emplace_back(move_tactics.at(i)); + } + + // yield the Tactics this Play wants to run, in order of priority + yield(result); + } + + // Part 2: not normal play, currently ready state (chip the ball) + while (!world_ptr->gameState().isPlaying()) + { + auto enemy_threats = + getAllEnemyThreats(world_ptr->field(), world_ptr->friendlyTeam(), + world_ptr->enemyTeam(), world_ptr->ball(), false); + + PriorityTacticVector result = {{}}; + + // TODO (#2612): This needs to be adjusted post field testing, ball needs to land + // exactly in the middle of the enemy field + Point ball_position = world_ptr->ball().position(); + Point kick_target = world_ptr->field().centerPoint() + + Vector(world_ptr->field().xLength() / 6, 0); + AutoChipOrKick auto_chip_or_kick = {AutoChipOrKickMode::AUTOCHIP, + (kick_target - ball_position).length()}; + kickoff_chip_tactic->updateControlParams(ball_position, kick_target, + auto_chip_or_kick); + result[0].emplace_back(kickoff_chip_tactic); + + // the robot at position 0 will be closest to the ball, so positions starting from + // 1 will be assigned to the rest of the robots + for (unsigned i = 1; i < kickoff_setup_positions.size(); i++) + { + move_tactics.at(i)->updateControlParams(kickoff_setup_positions.at(i), + Angle::zero()); + result[0].emplace_back(move_tactics.at(i)); + } + + // yield the Tactics this Play wants to run, in order of priority + yield(result); + } +} + + +// Register this play in the genericFactory +static TGenericFactory> + factory; diff --git a/src/software/ai/hl/stp/play/passing_sim_test.py b/src/software/ai/hl/stp/play/passing_sim_test.py index c4bf4a74d6..d9dad5c17c 100644 --- a/src/software/ai/hl/stp/play/passing_sim_test.py +++ b/src/software/ai/hl/stp/play/passing_sim_test.py @@ -111,13 +111,15 @@ def setup_pass_and_robots( # We use KickTactic since AttackerTactic shoots towards the goal instead if open # KickTactic just does the kick we want blue_tactics = {} - blue_tactics[0] = KickTactic( - kick_origin=Point( + blue_tactics[0] = KickOrChipTactic( + kick_or_chip_origin=Point( x_meters=best_pass.passerPoint().x(), y_meters=best_pass.passerPoint().y(), ), - kick_direction=Angle(radians=kick_vec.orientation().toRadians()), - kick_speed_meters_per_second=best_pass.speed(), + kick_or_chip_direction=Angle(radians=kick_vec.orientation().toRadians()), + auto_chip_or_kick=AutoChipOrKick( + autokick_speed_m_per_s=best_pass.speed(), + ), ) # if we want a friendly robot to receive the pass diff --git a/src/software/ai/hl/stp/tactic/BUILD b/src/software/ai/hl/stp/tactic/BUILD index f917792451..8f4fef2495 100644 --- a/src/software/ai/hl/stp/tactic/BUILD +++ b/src/software/ai/hl/stp/tactic/BUILD @@ -16,13 +16,12 @@ cc_library( deps = [ ":tactic", "//software/ai/hl/stp/tactic/attacker:attacker_tactic", - "//software/ai/hl/stp/tactic/chip:chip_tactic", "//software/ai/hl/stp/tactic/crease_defender:crease_defender_tactic", "//software/ai/hl/stp/tactic/dribble:dribble_tactic", "//software/ai/hl/stp/tactic/get_behind_ball:get_behind_ball_tactic", "//software/ai/hl/stp/tactic/goalie:goalie_tactic", "//software/ai/hl/stp/tactic/halt:halt_tactic", - "//software/ai/hl/stp/tactic/kick:kick_tactic", + "//software/ai/hl/stp/tactic/kick_or_chip:kick_or_chip_tactic", "//software/ai/hl/stp/tactic/move:move_tactic", "//software/ai/hl/stp/tactic/pass_defender:pass_defender_tactic", "//software/ai/hl/stp/tactic/penalty_kick:penalty_kick_tactic", diff --git a/src/software/ai/hl/stp/tactic/all_tactics.h b/src/software/ai/hl/stp/tactic/all_tactics.h index b25fe9b575..bf0a2c2a39 100644 --- a/src/software/ai/hl/stp/tactic/all_tactics.h +++ b/src/software/ai/hl/stp/tactic/all_tactics.h @@ -1,13 +1,12 @@ #pragma once #include "software/ai/hl/stp/tactic/attacker/attacker_tactic.h" -#include "software/ai/hl/stp/tactic/chip/chip_tactic.h" #include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h" #include "software/ai/hl/stp/tactic/dribble/dribble_tactic.h" #include "software/ai/hl/stp/tactic/get_behind_ball/get_behind_ball_tactic.h" #include "software/ai/hl/stp/tactic/goalie/goalie_tactic.h" #include "software/ai/hl/stp/tactic/halt/halt_tactic.h" -#include "software/ai/hl/stp/tactic/kick/kick_tactic.h" +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" #include "software/ai/hl/stp/tactic/move/move_tactic.h" #include "software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic.h" #include "software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h" diff --git a/src/software/ai/hl/stp/tactic/attacker/BUILD b/src/software/ai/hl/stp/tactic/attacker/BUILD index ce0cdbf432..6b31d3859c 100644 --- a/src/software/ai/hl/stp/tactic/attacker/BUILD +++ b/src/software/ai/hl/stp/tactic/attacker/BUILD @@ -14,7 +14,6 @@ cc_library( "//shared:constants", "//software/ai/evaluation:keep_away", "//software/ai/hl/stp/tactic", - "//software/ai/hl/stp/tactic/chip:chip_tactic", "//software/ai/hl/stp/tactic/keep_away:keep_away_tactic", "//software/ai/hl/stp/tactic/pivot_kick:pivot_kick_tactic", "//software/ai/passing:pass", diff --git a/src/software/ai/hl/stp/tactic/attacker/attacker_fsm.h b/src/software/ai/hl/stp/tactic/attacker/attacker_fsm.h index 5330131360..a0246fbb99 100644 --- a/src/software/ai/hl/stp/tactic/attacker/attacker_fsm.h +++ b/src/software/ai/hl/stp/tactic/attacker/attacker_fsm.h @@ -3,7 +3,6 @@ #include "proto/parameters.pb.h" #include "software/ai/evaluation/keep_away.h" #include "software/ai/evaluation/shot.h" -#include "software/ai/hl/stp/tactic/chip/chip_fsm.h" #include "software/ai/hl/stp/tactic/keep_away/keep_away_fsm.h" #include "software/ai/hl/stp/tactic/pivot_kick/pivot_kick_fsm.h" #include "software/ai/hl/stp/tactic/tactic_base.hpp" diff --git a/src/software/ai/hl/stp/tactic/chip/chip_fsm_test.cpp b/src/software/ai/hl/stp/tactic/chip/chip_fsm_test.cpp deleted file mode 100644 index 857f19a879..0000000000 --- a/src/software/ai/hl/stp/tactic/chip/chip_fsm_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "software/ai/hl/stp/tactic/chip/chip_fsm.h" - -#include - -#include "software/test_util/test_util.h" - -TEST(ChipFSMTest, test_transitions) -{ - std::shared_ptr world = ::TestUtil::createBlankTestingWorld(); - Robot robot = ::TestUtil::createRobotAtPos(Point(-2, -3)); - ChipFSM::ControlParams control_params{.chip_origin = Point(-2, 1.5), - .chip_direction = Angle::threeQuarter(), - .chip_distance_meters = 1.2}; - - FSM fsm{ChipFSM(std::make_shared()), - GetBehindBallFSM(std::make_shared())}; - - // Start in GetBehindBallFSM state's GetBehindBallState - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Transition to GetBehindBallFSM state's GetBehindBallState - fsm.process_event(ChipFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Robot is now behind ball - robot = Robot(0, - RobotState(Point(-2, 1.7), Vector(), Angle::threeQuarter(), - AngularVelocity::zero()), - Timestamp::fromSeconds(123)); - fsm.process_event(ChipFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - // Transition to ChipState - EXPECT_TRUE(fsm.is(boost::sml::state)); - - // Change the chip direction and expect the FSM to realign - control_params.chip_direction = Angle::quarter(); - fsm.process_event(ChipFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Robot is now behind ball in the new direction - robot = Robot( - 0, - RobotState(Point(-2, 1.3), Vector(), Angle::quarter(), AngularVelocity::zero()), - Timestamp::fromSeconds(124)); - fsm.process_event(ChipFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - // Transition to ChipState again - EXPECT_TRUE(fsm.is(boost::sml::state)); - - // Ball is now chipped - ::TestUtil::setBallVelocity(world, Vector(0, 2.1), Timestamp::fromSeconds(123)); - - EXPECT_TRUE(world->ball().hasBallBeenKicked(Angle::quarter())); - - // Tactic is done - fsm.process_event(ChipFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::X)); -} diff --git a/src/software/ai/hl/stp/tactic/chip/chip_tactic.h b/src/software/ai/hl/stp/tactic/chip/chip_tactic.h deleted file mode 100644 index c0a4ca1ea1..0000000000 --- a/src/software/ai/hl/stp/tactic/chip/chip_tactic.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include "software/ai/hl/stp/tactic/chip/chip_fsm.h" -#include "software/ai/hl/stp/tactic/tactic_base.hpp" - -/** - * The ChipTactic will move the assigned robot to the given chip origin and then - * chip the ball to the chip target. - */ - -class ChipTactic : public TacticBase -{ - public: - /** - * Creates a new ChipTactic - * - * @param ai_config_ptr shared pointer to ai_config - */ - explicit ChipTactic(std::shared_ptr ai_config_ptr); - - /** - * Updates the params for this tactic that cannot be derived from the world - * - * @param chip_origin The location where the chip will be taken - * @param chip_direction The direction the Robot will chip in - * @param chip_distance_meters The distance between the starting location - * of the chip and the location of the first bounce - */ - void updateControlParams(const Point& chip_origin, const Angle& chip_direction, - double chip_distance_meters); - - /** - * Updates the control parameters for this ChipTactic. - * - * @param chip_origin The location where the chip will be taken - * @param chip_direction The direction the Robot will chip in - */ - void updateControlParams(const Point& chip_origin, const Point& chip_target); - - void accept(TacticVisitor& visitor) const override; -}; - -// Creates a new tactic called KickoffChipTactic that is a duplicate of ChipTactic -COPY_TACTIC(KickoffChipTactic, ChipTactic) diff --git a/src/software/ai/hl/stp/tactic/goalie/BUILD b/src/software/ai/hl/stp/tactic/goalie/BUILD index 47d8f9f8af..3dfe372ef9 100644 --- a/src/software/ai/hl/stp/tactic/goalie/BUILD +++ b/src/software/ai/hl/stp/tactic/goalie/BUILD @@ -17,7 +17,6 @@ cc_library( "//software/ai/evaluation:enemy_threat", "//software/ai/evaluation:find_open_areas", "//software/ai/hl/stp/tactic", - "//software/ai/hl/stp/tactic/chip:chip_tactic", "//software/ai/hl/stp/tactic/dribble:dribble_tactic", "//software/ai/hl/stp/tactic/pivot_kick:pivot_kick_tactic", "//software/geom:line", diff --git a/src/software/ai/hl/stp/tactic/goalie/goalie_fsm.h b/src/software/ai/hl/stp/tactic/goalie/goalie_fsm.h index 9e5a1ef6de..8e8cdf1206 100644 --- a/src/software/ai/hl/stp/tactic/goalie/goalie_fsm.h +++ b/src/software/ai/hl/stp/tactic/goalie/goalie_fsm.h @@ -3,7 +3,6 @@ #include "proto/parameters.pb.h" #include "shared/constants.h" #include "software/ai/evaluation/calc_best_shot.h" -#include "software/ai/hl/stp/tactic/chip/chip_fsm.h" #include "software/ai/hl/stp/tactic/pivot_kick/pivot_kick_fsm.h" #include "software/ai/hl/stp/tactic/tactic_base.hpp" #include "software/geom/algorithms/calculate_block_cone.h" diff --git a/src/software/ai/hl/stp/tactic/kick/kick_fsm_test.cpp b/src/software/ai/hl/stp/tactic/kick/kick_fsm_test.cpp deleted file mode 100644 index f010696574..0000000000 --- a/src/software/ai/hl/stp/tactic/kick/kick_fsm_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "software/ai/hl/stp/tactic/kick/kick_fsm.h" - -#include - -#include "software/test_util/test_util.h" - -TEST(KickFSMTest, test_transitions) -{ - std::shared_ptr world = ::TestUtil::createBlankTestingWorld(); - Robot robot = ::TestUtil::createRobotAtPos(Point(-2, -3)); - KickFSM::ControlParams control_params{.kick_origin = Point(-2, 1.5), - .kick_direction = Angle::threeQuarter(), - .kick_speed_meters_per_second = 1.2}; - - FSM fsm{KickFSM(std::make_shared()), - GetBehindBallFSM(std::make_shared())}; - - // Start in GetBehindBallFSM state's GetBehindBallState - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Transition to GetBehindBallFSM state's GetBehindBallState - fsm.process_event(KickFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Robot is now behind ball - robot = Robot(0, - RobotState(Point(-2, 1.7), Vector(), Angle::threeQuarter(), - AngularVelocity::zero()), - Timestamp::fromSeconds(123)); - fsm.process_event(KickFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - // Transition to KickState - EXPECT_TRUE(fsm.is(boost::sml::state)); - - // Change the chip direction and expect the FSM to realign - control_params.kick_direction = Angle::quarter(); - fsm.process_event(KickFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); - - // Robot is now behind ball in the new direction - robot = Robot( - 0, - RobotState(Point(-2, 1.3), Vector(), Angle::quarter(), AngularVelocity::zero()), - Timestamp::fromSeconds(124)); - fsm.process_event(KickFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - // Transition to KickState again - EXPECT_TRUE(fsm.is(boost::sml::state)); - - // Ball is now kicked - ::TestUtil::setBallVelocity(world, Vector(0, 2.1), Timestamp::fromSeconds(123)); - - EXPECT_TRUE(world->ball().hasBallBeenKicked(Angle::quarter())); - - // Tactic is done - fsm.process_event(KickFSM::Update( - control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::X)); -} diff --git a/src/software/ai/hl/stp/tactic/kick/kick_tactic.h b/src/software/ai/hl/stp/tactic/kick/kick_tactic.h deleted file mode 100644 index c03c769efa..0000000000 --- a/src/software/ai/hl/stp/tactic/kick/kick_tactic.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include "software/ai/hl/stp/tactic/kick/kick_fsm.h" -#include "software/ai/hl/stp/tactic/tactic_base.hpp" - -/** - * The KickTactic will move the assigned robot to the given kick origin and then - * kick the ball to the kick target. - */ - -class KickTactic : public TacticBase -{ - public: - /** - * Creates a new KickTactic - * - * @param ai_config_ptr shared pointer to ai_config - */ - explicit KickTactic(std::shared_ptr ai_config_ptr); - - /** - * Updates the params for this tactic that cannot be derived from the world - * - * @param kick_origin The location where the kick will be taken - * @param kick_direction The direction the Robot will kick in - * @param kick_speed_meters_per_second The speed of how fast the Robot - * will kick the ball in meters per second - */ - void updateControlParams(const Point& kick_origin, const Angle& kick_direction, - double kick_speed_meters_per_second); - - /** - * Updates the control parameters for this KickTactic. - * - * @param kick_origin The location where the kick will be taken - * @param kick_direction The direction the Robot will kick in - * @param kick_speed_meters_per_second The speed of how fast the Robot - * will kick the ball in meters per second - */ - void updateControlParams(const Point& kick_origin, const Point& kick_target, - double kick_speed_meters_per_second); - - void accept(TacticVisitor& visitor) const override; -}; diff --git a/src/software/ai/hl/stp/tactic/chip/BUILD b/src/software/ai/hl/stp/tactic/kick_or_chip/BUILD similarity index 55% rename from src/software/ai/hl/stp/tactic/chip/BUILD rename to src/software/ai/hl/stp/tactic/kick_or_chip/BUILD index 250e5a2b09..a149d7310f 100644 --- a/src/software/ai/hl/stp/tactic/chip/BUILD +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/BUILD @@ -1,43 +1,46 @@ package(default_visibility = ["//visibility:public"]) cc_library( - name = "chip_tactic", + name = "kick_or_chip_tactic", srcs = [ - "chip_fsm.cpp", - "chip_tactic.cpp", + "kick_or_chip_fsm.cpp", + "kick_or_chip_tactic.cpp", ], hdrs = [ - "chip_fsm.h", - "chip_tactic.h", + "kick_or_chip_fsm.h", + "kick_or_chip_tactic.h", ], deps = [ "//shared:constants", + "//software/ai/evaluation:enemy_threat", "//software/ai/hl/stp/tactic", - "//software/ai/hl/stp/tactic:move_primitive", + "//software/ai/hl/stp/tactic/dribble:dribble_tactic", "//software/ai/hl/stp/tactic/get_behind_ball:get_behind_ball_tactic", + "//software/ai/hl/stp/tactic/move:move_tactic", + "//software/geom/algorithms", "//software/logger", ], ) cc_test( - name = "chip_fsm_test", - srcs = ["chip_fsm_test.cpp"], + name = "kick_or_chip_tactic_test", + srcs = ["kick_or_chip_tactic_test.cpp"], deps = [ - ":chip_tactic", + ":kick_or_chip_tactic", "//shared/test_util:tbots_gtest_main", + "//software/simulated_tests:simulated_er_force_sim_play_test_fixture", + "//software/simulated_tests/cpp_validation:validation_function", + "//software/simulated_tests/terminating_validation_functions", "//software/test_util", ], ) cc_test( - name = "chip_tactic_test", - srcs = ["chip_tactic_test.cpp"], + name = "kick_or_chip_fsm_test", + srcs = ["kick_or_chip_fsm_test.cpp"], deps = [ - ":chip_tactic", + ":kick_or_chip_tactic", "//shared/test_util:tbots_gtest_main", - "//software/simulated_tests:simulated_er_force_sim_play_test_fixture", - "//software/simulated_tests/cpp_validation:validation_function", - "//software/simulated_tests/terminating_validation_functions", "//software/test_util", ], ) diff --git a/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.cpp b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.cpp new file mode 100644 index 0000000000..4c2c6be01b --- /dev/null +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.cpp @@ -0,0 +1,56 @@ +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h" + +#include "shared/constants.h" +#include "software/ai/hl/stp/tactic/move_primitive.h" + +KickOrChipFSM::KickOrChipFSM(std::shared_ptr ai_config_ptr) + : TacticFSM(ai_config_ptr) +{ +} + +void KickOrChipFSM::kickOrChipBall(const Update& event) +{ + Vector direction = + Vector::createFromAngle(event.control_params.kick_or_chip_direction); + Point kick_or_chip_target = event.control_params.kick_or_chip_origin - + direction.normalize(DIST_TO_FRONT_OF_ROBOT_METERS - 0.01); + + event.common.set_primitive(std::make_unique( + event.common.robot, kick_or_chip_target, + event.control_params.kick_or_chip_direction, + TbotsProto::MaxAllowedSpeedMode::PHYSICAL_LIMIT, + TbotsProto::ObstacleAvoidanceMode::AGGRESSIVE, TbotsProto::DribblerMode::OFF, + TbotsProto::BallCollisionType::ALLOW, event.control_params.auto_chip_or_kick)); +} + +void KickOrChipFSM::updateGetBehindBall( + const Update& event, boost::sml::back::process processEvent) +{ + GetBehindBallFSM::ControlParams control_params{ + .ball_location = event.control_params.kick_or_chip_origin, + .chick_direction = event.control_params.kick_or_chip_direction}; + + // Update the get behind ball fsm + processEvent(GetBehindBallFSM::Update(control_params, event.common)); +} + +bool KickOrChipFSM::ballChicked(const Update& event) +{ + return event.common.world_ptr->ball().hasBallBeenKicked( + event.control_params.kick_or_chip_direction); +} + +bool KickOrChipFSM::shouldRealignWithBall(const Update& event) +{ + const Robot& robot = event.common.robot; + + // First check to see if it's too late to realign with the ball + if (robot.isNearDribbler(event.control_params.kick_or_chip_origin, 0.05)) + { + return false; + } + + // Check if the robot is already aligned to kick the ball + return !isRobotReadyToChick(robot, event.control_params.kick_or_chip_origin, + event.control_params.kick_or_chip_direction); +} diff --git a/src/software/ai/hl/stp/tactic/kick/kick_fsm.h b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h similarity index 59% rename from src/software/ai/hl/stp/tactic/kick/kick_fsm.h rename to src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h index 6fa9d9196d..d259d13a62 100644 --- a/src/software/ai/hl/stp/tactic/kick/kick_fsm.h +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h @@ -7,35 +7,40 @@ /** * Finite State Machine class for Kicks */ -struct KickFSM : TacticFSM +struct KickOrChipFSM : TacticFSM { - class KickState; + class KickOrChipState; struct ControlParams { + // Control params for kick // The location where the kick will be taken from - Point kick_origin; + Point kick_or_chip_origin; // The direction the Robot will kick in - Angle kick_direction; - // How fast the Robot will kick the ball in meters per second - double kick_speed_meters_per_second; + Angle kick_or_chip_direction; + + // How the robot will chip or kick the ball and its associated parameter for that + // mode. For example, if the mode is AUTOKICK, then the parameter will be the + // speed of the kick, and if the mode is AUTOCHIP, then the parameter will be the + // distance of the chip. + AutoChipOrKick auto_chip_or_kick; }; - using Update = TacticFSM::Update; + using Update = TacticFSM::Update; /** * Constructor for KickFSM * * @param ai_config_ptr shared pointer to ai_config */ - explicit KickFSM(std::shared_ptr ai_config_ptr); + explicit KickOrChipFSM(std::shared_ptr ai_config_ptr); /** - * Action that updates the MovePrimitive + * Action that updates the primitive to kick or chip the ball * * @param event KickFSM::Update event */ - void updateKick(const Update& event); + void kickOrChipBall(const Update& event); /** * Action that updates the GetBehindBallFSM @@ -66,28 +71,31 @@ struct KickFSM : TacticFSM bool shouldRealignWithBall(const Update& event); + auto operator()() { using namespace boost::sml; DEFINE_SML_STATE(GetBehindBallFSM) - DEFINE_SML_STATE(KickState) + DEFINE_SML_STATE(KickOrChipState) DEFINE_SML_EVENT(Update) DEFINE_SML_GUARD(ballChicked) DEFINE_SML_GUARD(shouldRealignWithBall) - DEFINE_SML_ACTION(updateKick) + + DEFINE_SML_ACTION(kickOrChipBall) DEFINE_SML_SUB_FSM_UPDATE_ACTION(updateGetBehindBall, GetBehindBallFSM) return make_transition_table( // src_state + event [guard] / action = dest_state *GetBehindBallFSM_S + Update_E / updateGetBehindBall_A, - GetBehindBallFSM_S = KickState_S, + GetBehindBallFSM_S = KickOrChipState_S, - KickState_S + Update_E[shouldRealignWithBall_G] / updateGetBehindBall_A = - GetBehindBallFSM_S, - KickState_S + Update_E[!ballChicked_G] / updateKick_A = KickState_S, - KickState_S + Update_E[ballChicked_G] / SET_STOP_PRIMITIVE_ACTION = X, - X + Update_E / SET_STOP_PRIMITIVE_ACTION = X); + KickOrChipState_S + Update_E[shouldRealignWithBall_G] / + updateGetBehindBall_A = GetBehindBallFSM_S, + KickOrChipState_S + Update_E[!ballChicked_G] / kickOrChipBall_A = + KickOrChipState_S, + KickOrChipState_S + Update_E[ballChicked_G] / SET_STOP_PRIMITIVE_ACTION = X, + X + Update_E / SET_STOP_PRIMITIVE_ACTION = X); } }; diff --git a/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm_test.cpp b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm_test.cpp new file mode 100644 index 0000000000..819c5e4ddb --- /dev/null +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm_test.cpp @@ -0,0 +1,131 @@ +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h" + +#include + +#include "software/test_util/test_util.h" + +TEST(KickOrChipFSMTest, test_transitions_autokick) +{ + std::shared_ptr world = ::TestUtil::createBlankTestingWorld(); + Robot robot = ::TestUtil::createRobotAtPos(Point(-2, -3)); + KickOrChipFSM::ControlParams control_params{ + .kick_or_chip_origin = Point(-2, 1.5), + .kick_or_chip_direction = Angle::threeQuarter(), + .auto_chip_or_kick = {AutoChipOrKickMode::AUTOKICK, 1.2}}; + + FSM fsm{KickOrChipFSM(std::make_shared()), + GetBehindBallFSM(std::make_shared())}; + + // Start in GetBehindBallFSM state's GetBehindBallState + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Transition to GetBehindBallFSM state's GetBehindBallState + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Robot is now behind ball + robot = Robot(0, + RobotState(Point(-2, 1.7), Vector(), Angle::threeQuarter(), + AngularVelocity::zero()), + Timestamp::fromSeconds(123)); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + // Transition to KickOrChipState + EXPECT_TRUE(fsm.is(boost::sml::state)); + + // Change the kick direction and expect the FSM to realign + control_params.kick_or_chip_direction = Angle::quarter(); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Robot is now behind ball in the new direction + robot = Robot( + 0, + RobotState(Point(-2, 1.3), Vector(), Angle::quarter(), AngularVelocity::zero()), + Timestamp::fromSeconds(124)); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + // Transition to KickOrChipState again + EXPECT_TRUE(fsm.is(boost::sml::state)); + + // Ball is now kicked + ::TestUtil::setBallVelocity(world, Vector(0, 2.1), Timestamp::fromSeconds(123)); + + EXPECT_TRUE(world->ball().hasBallBeenKicked(Angle::quarter())); + + // Tactic is done + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::X)); +} + +TEST(KickOrChipFSMTest, test_transitions_autochip) +{ + std::shared_ptr world = ::TestUtil::createBlankTestingWorld(); + Robot robot = ::TestUtil::createRobotAtPos(Point(-2, -3)); + KickOrChipFSM::ControlParams control_params{ + .kick_or_chip_origin = Point(-2, 1.5), + .kick_or_chip_direction = Angle::threeQuarter(), + .auto_chip_or_kick = {AutoChipOrKickMode::AUTOCHIP, 1.2}}; + + FSM fsm{KickOrChipFSM(std::make_shared()), + GetBehindBallFSM(std::make_shared())}; + + // Start in GetBehindBallFSM state's GetBehindBallState + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Transition to GetBehindBallFSM state's GetBehindBallState + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Robot is now behind ball + robot = Robot(0, + RobotState(Point(-2, 1.7), Vector(), Angle::threeQuarter(), + AngularVelocity::zero()), + Timestamp::fromSeconds(123)); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + // Transition to KickOrChipState + EXPECT_TRUE(fsm.is(boost::sml::state)); + + // Change the chip direction and expect the FSM to realign + control_params.kick_or_chip_direction = Angle::quarter(); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); + + // Robot is now behind ball in the new direction + robot = Robot( + 0, + RobotState(Point(-2, 1.3), Vector(), Angle::quarter(), AngularVelocity::zero()), + Timestamp::fromSeconds(124)); + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + // Transition to KickOrChipState again + EXPECT_TRUE(fsm.is(boost::sml::state)); + + // Ball is now chipped + ::TestUtil::setBallVelocity(world, Vector(0, 2.1), Timestamp::fromSeconds(123)); + + EXPECT_TRUE(world->ball().hasBallBeenKicked(Angle::quarter())); + + // Tactic is done + fsm.process_event(KickOrChipFSM::Update( + control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); + EXPECT_TRUE(fsm.is(boost::sml::X)); +} diff --git a/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.cpp b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.cpp new file mode 100644 index 0000000000..1c4d2db9ab --- /dev/null +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.cpp @@ -0,0 +1,35 @@ +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" + +#include + + +KickOrChipTactic::KickOrChipTactic( + std::shared_ptr ai_config_ptr) + : TacticBase( + {RobotCapability::Chip, RobotCapability::Move}, ai_config_ptr) +{ +} + + +void KickOrChipTactic::updateControlParams(const Point& kick_or_chip_origin, + const Angle& kick_or_chip_direction, + AutoChipOrKick auto_chip_or_kick) +{ + control_params.kick_or_chip_origin = kick_or_chip_origin; + control_params.kick_or_chip_direction = kick_or_chip_direction; + control_params.auto_chip_or_kick = auto_chip_or_kick; +} + +void KickOrChipTactic::updateControlParams(const Point& kick_or_chip_origin, + const Point& kick_or_chip_target, + AutoChipOrKick auto_chip_or_kick) +{ + updateControlParams(kick_or_chip_origin, + (kick_or_chip_target - kick_or_chip_origin).orientation(), + auto_chip_or_kick); +} + +void KickOrChipTactic::accept(TacticVisitor& visitor) const +{ + visitor.visit(*this); +} diff --git a/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h new file mode 100644 index 0000000000..0ffc644ac0 --- /dev/null +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h @@ -0,0 +1,50 @@ +#pragma once + +#include + +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h" +#include "software/ai/hl/stp/tactic/tactic_base.hpp" + +/** + * The KickOrChipTactic will move the assigned robot to the given kick origin and then + * kick or chip the ball depending on the control params passed in. + */ + +class KickOrChipTactic : public TacticBase +{ + public: + /** + * Creates a new KickOrChipTactic + * + * @param ai_config_ptr shared pointer to ai_config + */ + explicit KickOrChipTactic(std::shared_ptr ai_config_ptr); + + /** + * Updates the params for this tactic that cannot be derived from the world + * + * @param kick_or_chip_origin The location where the kick will be taken + * @param kick_or_chip_direction The direction the Robot will kick in + * @param auto_chip_or_kick The mode of how the robot will chip or kick the ball, and + * the associated parameter for that model + */ + void updateControlParams(const Point& kick_or_chip_origin, + const Angle& kick_or_chip_direction, + AutoChipOrKick auto_chip_or_kick); + /** + * Updates the control parameters for this KickTactic. + * + * @param kick_origin The location where the kick will be taken + * @param kick_or_chip_target The target location where the kick or chip will aim for + * @param auto_chip_or_kick The mode of how the robot will chip or kick the ball, and + * the associated parameter for that model + */ + void updateControlParams(const Point& kick_or_chip_origin, + const Point& kickd_or_chip_target, + AutoChipOrKick auto_chip_or_kick); + + void accept(TacticVisitor& visitor) const override; +}; + +// Creates a new tactic called KickoffChipTactic that is a duplicate of ChipTactic +COPY_TACTIC(KickoffChipTactic, KickOrChipTactic) diff --git a/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic_test.cpp b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic_test.cpp new file mode 100644 index 0000000000..cc2f7cc5e2 --- /dev/null +++ b/src/software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic_test.cpp @@ -0,0 +1,88 @@ +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_tactic.h" + +#include + +#include + +#include "software/geom/algorithms/contains.h" +#include "software/simulated_tests/simulated_er_force_sim_play_test_fixture.h" +#include "software/simulated_tests/terminating_validation_functions/ball_kicked_validation.h" +#include "software/simulated_tests/terminating_validation_functions/robot_state_validation.h" +#include "software/simulated_tests/validation/validation_function.h" +#include "software/test_util/test_util.h" +#include "software/time/duration.h" +#include "software/world/world.h" + +class KickOrChipTacticTest + : public SimulatedErForceSimPlayTestFixture, + public ::testing::WithParamInterface> +{ + protected: + TbotsProto::FieldType field_type = TbotsProto::FieldType::DIV_B; + Field field = Field::createField(field_type); +}; + +TEST_P(KickOrChipTacticTest, kick_or_chip_test) +{ + Vector ball_offset_from_robot = std::get<0>(GetParam()); + Angle angle_to_kick_at = std::get<1>(GetParam()); + AutoChipOrKick auto_chip_or_kick = std::get<2>(GetParam()); + + Point robot_position = Point(0, 0); + BallState ball_state(robot_position + ball_offset_from_robot, Vector(0, 0)); + + auto friendly_robots = + TestUtil::createStationaryRobotStatesWithId({Point(-3, 2.5), robot_position}); + auto enemy_robots = TestUtil::createStationaryRobotStatesWithId({Point(4, 0)}); + + auto tactic = + std::make_shared(std::make_shared()); + tactic->updateControlParams(robot_position + ball_offset_from_robot, angle_to_kick_at, + auto_chip_or_kick); + setTactic(1, tactic); + + std::vector terminating_validation_functions = { + [angle_to_kick_at, tactic](std::shared_ptr world_ptr, + ValidationCoroutine::push_type& yield) + { + while (!tactic->done()) + { + yield("Tactic did not complete!"); + } + ballKicked(angle_to_kick_at, world_ptr, yield); + }}; + + std::vector non_terminating_validation_functions = {}; + + runTest(field_type, ball_state, friendly_robots, enemy_robots, + terminating_validation_functions, non_terminating_validation_functions, + Duration::fromSeconds(5)); +} + +INSTANTIATE_TEST_CASE_P( + AutokickBallLocations, KickOrChipTacticTest, + ::testing::Values(std::make_tuple(Vector(0, 0.5), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOKICK, 5.0}), + std::make_tuple(Vector(0, -0.5), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOKICK, 5.0}), + std::make_tuple(Vector(0.5, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOKICK, 5.0}), + std::make_tuple(Vector(-0.5, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOKICK, 5.0}), + std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOKICK, + 5.0}))); + +INSTANTIATE_TEST_CASE_P( + AutochipBallLocations, KickOrChipTacticTest, + ::testing::Values(std::make_tuple(Vector(0, 0.5), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, 2.0}), + std::make_tuple(Vector(0, -0.5), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, 2.0}), + std::make_tuple(Vector(0.5, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, 2.0}), + std::make_tuple(Vector(-0.5, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, 2.0}), + std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero(), + AutoChipOrKick{AutoChipOrKickMode::AUTOCHIP, + 2.0}))); diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/BUILD b/src/software/ai/hl/stp/tactic/penalty_kick/BUILD index 927a632ce3..319640d438 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/BUILD +++ b/src/software/ai/hl/stp/tactic/penalty_kick/BUILD @@ -16,7 +16,7 @@ cc_library( "//software/ai/hl/stp/tactic", "//software/ai/hl/stp/tactic/dribble:dribble_tactic", "//software/ai/hl/stp/tactic/get_behind_ball:get_behind_ball_tactic", - "//software/ai/hl/stp/tactic/kick:kick_tactic", + "//software/ai/hl/stp/tactic/kick_or_chip:kick_or_chip_tactic", "//software/ai/hl/stp/tactic/move:move_tactic", "//software/geom/algorithms", "//software/logger", diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.cpp b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.cpp index 203bd7a570..0e44c80260 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.cpp +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.cpp @@ -122,13 +122,15 @@ const Point PenaltyKickFSM::evaluateNextShotPosition(std::optional enemy_ } void PenaltyKickFSM::shoot(const Update& event, - boost::sml::back::process processEvent) + boost::sml::back::process processEvent) { - KickFSM::ControlParams control_params{ - .kick_origin = event.common.world_ptr->ball().position(), - .kick_direction = shot_angle, - .kick_speed_meters_per_second = PENALTY_KICK_SHOT_SPEED}; - processEvent(KickFSM::Update(control_params, event.common)); + AutoChipOrKick auto_chip_or_kick = {AutoChipOrKickMode::AUTOKICK, + PENALTY_KICK_SHOT_SPEED}; + KickOrChipFSM::ControlParams control_params{ + .kick_or_chip_origin = event.common.world_ptr->ball().position(), + .kick_or_chip_direction = shot_angle, + .auto_chip_or_kick = auto_chip_or_kick}; + processEvent(KickOrChipFSM::Update(control_params, event.common)); } void PenaltyKickFSM::updateApproachKeeper( diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.h b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.h index 485a2c8180..1bd3711e05 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.h +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm.h @@ -2,7 +2,7 @@ #include "software/ai/hl/stp/tactic/dribble/dribble_fsm.h" #include "software/ai/hl/stp/tactic/get_behind_ball/get_behind_ball_fsm.h" -#include "software/ai/hl/stp/tactic/kick/kick_fsm.h" +#include "software/ai/hl/stp/tactic/kick_or_chip/kick_or_chip_fsm.h" #include "software/ai/hl/stp/tactic/move/move_fsm.h" #include "software/ai/hl/stp/tactic/tactic_base.hpp" #include "software/geom/algorithms/closest_point.h" @@ -59,7 +59,7 @@ struct PenaltyKickFSM : TacticFSM * @param processEvent processes the KickFSM::Update */ void shoot(const Update& event, - boost::sml::back::process processEvent); + boost::sml::back::process processEvent); /** * Action that updates the shooter's approach to the opposition net. @@ -105,24 +105,24 @@ struct PenaltyKickFSM : TacticFSM using namespace boost::sml; DEFINE_SML_STATE(DribbleFSM) - DEFINE_SML_STATE(KickFSM) + DEFINE_SML_STATE(KickOrChipFSM) DEFINE_SML_EVENT(Update) DEFINE_SML_GUARD(takePenaltyShot) DEFINE_SML_GUARD(timeOutApproach) - DEFINE_SML_SUB_FSM_UPDATE_ACTION(shoot, KickFSM) + DEFINE_SML_SUB_FSM_UPDATE_ACTION(shoot, KickOrChipFSM) DEFINE_SML_SUB_FSM_UPDATE_ACTION(updateApproachKeeper, DribbleFSM) DEFINE_SML_SUB_FSM_UPDATE_ACTION(adjustOrientationForShot, DribbleFSM) return make_transition_table( // src_state + event [guard] / action = dest state *DribbleFSM_S + Update_E[!takePenaltyShot_G] / updateApproachKeeper_A, - DribbleFSM_S + Update_E[timeOutApproach_G] / shoot_A = KickFSM_S, + DribbleFSM_S + Update_E[timeOutApproach_G] / shoot_A = KickOrChipFSM_S, DribbleFSM_S + Update_E / adjustOrientationForShot_A, - DribbleFSM_S = KickFSM_S, KickFSM_S + Update_E / shoot_A, KickFSM_S = X, - X + Update_E / SET_STOP_PRIMITIVE_ACTION = X); + DribbleFSM_S = KickOrChipFSM_S, KickOrChipFSM_S + Update_E / shoot_A, + KickOrChipFSM_S = X, X + Update_E / SET_STOP_PRIMITIVE_ACTION = X); }; private: diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm_test.cpp b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm_test.cpp index bd6b41a706..c9eb990fd4 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm_test.cpp +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_fsm_test.cpp @@ -4,8 +4,7 @@ #include "software/test_util/test_util.h" -// TODO (#2473): fix and re-enable -TEST(PenaltyKickFSM, DISABLED_test_transitions) +TEST(PenaltyKickFSM, test_transitions) { std::shared_ptr world = ::TestUtil::createBlankTestingWorld(); ::TestUtil::setBallPosition(world, world->field().friendlyPenaltyMark(), @@ -14,7 +13,7 @@ TEST(PenaltyKickFSM, DISABLED_test_transitions) FSM fsm{PenaltyKickFSM(std::make_shared()), DribbleFSM(std::make_shared()), - KickFSM(std::make_shared()), + KickOrChipFSM(std::make_shared()), GetBehindBallFSM(std::make_shared())}; PenaltyKickFSM::ControlParams control_params{}; @@ -38,20 +37,18 @@ TEST(PenaltyKickFSM, DISABLED_test_transitions) ::TestUtil::setBallPosition(world, position, Timestamp::fromSeconds(2)); fsm.process_event(PenaltyKickFSM::Update( control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( boost::sml::state)); ::TestUtil::setBallPosition(world, position + Vector(0.1, 0), Timestamp::fromSeconds(2)); fsm.process_event(PenaltyKickFSM::Update( control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); - EXPECT_TRUE(fsm.is(boost::sml::state)); - EXPECT_TRUE(fsm.is)>( - boost::sml::state)); + EXPECT_TRUE(fsm.is(boost::sml::state)); + EXPECT_TRUE(fsm.is)>( + boost::sml::state)); - ::TestUtil::setBallPosition(world, world->field().enemyGoalCenter(), - Timestamp::fromSeconds(4)); ::TestUtil::setBallVelocity(world, Vector(5, 0), Timestamp::fromSeconds(4)); fsm.process_event(PenaltyKickFSM::Update( control_params, TacticUpdate(robot, world, [](std::shared_ptr) {}))); diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.cpp b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.cpp index 28a3313aef..cc959e8c48 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.cpp +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.cpp @@ -2,7 +2,7 @@ PenaltyKickTactic::PenaltyKickTactic( std::shared_ptr ai_config_ptr) - : TacticBase( + : TacticBase( {RobotCapability::Move, RobotCapability::Dribble, RobotCapability::Kick}, ai_config_ptr) { diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h index 84480ed441..251a124ff6 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h @@ -12,7 +12,7 @@ */ class PenaltyKickTactic - : public TacticBase + : public TacticBase { public: /** diff --git a/src/software/ai/hl/stp/tactic/receiver/BUILD b/src/software/ai/hl/stp/tactic/receiver/BUILD index d9a3f89d42..43ffbc86b2 100644 --- a/src/software/ai/hl/stp/tactic/receiver/BUILD +++ b/src/software/ai/hl/stp/tactic/receiver/BUILD @@ -15,7 +15,6 @@ cc_library( "//software/ai/evaluation:calc_best_shot", "//software/ai/hl/stp/tactic", "//software/ai/hl/stp/tactic/dribble:dribble_tactic", - "//software/ai/hl/stp/tactic/kick:kick_tactic", "//software/ai/hl/stp/tactic/move:move_tactic", "//software/ai/passing:pass", "//software/logger", diff --git a/src/software/ai/hl/stp/tactic/receiver/receiver_fsm.h b/src/software/ai/hl/stp/tactic/receiver/receiver_fsm.h index fcd30d8fc3..0c80d6c518 100644 --- a/src/software/ai/hl/stp/tactic/receiver/receiver_fsm.h +++ b/src/software/ai/hl/stp/tactic/receiver/receiver_fsm.h @@ -3,7 +3,6 @@ #include "shared/constants.h" #include "software/ai/evaluation/calc_best_shot.h" #include "software/ai/hl/stp/tactic/dribble/dribble_fsm.h" -#include "software/ai/hl/stp/tactic/kick/kick_fsm.h" #include "software/ai/hl/stp/tactic/move/move_fsm.h" #include "software/ai/hl/stp/tactic/tactic_base.hpp" #include "software/ai/passing/pass.h" diff --git a/src/software/ai/hl/stp/tactic/tactic_factory.cpp b/src/software/ai/hl/stp/tactic/tactic_factory.cpp index 1fef5c21a4..d86df9e5aa 100644 --- a/src/software/ai/hl/stp/tactic/tactic_factory.cpp +++ b/src/software/ai/hl/stp/tactic/tactic_factory.cpp @@ -17,12 +17,11 @@ std::shared_ptr createTactic( switch (tactic_proto.tactic_case()) { PROTO_CREATE_TACTIC_CASE(Attacker, attacker) - PROTO_CREATE_TACTIC_CASE(Chip, chip) PROTO_CREATE_TACTIC_CASE(CreaseDefender, crease_defender) PROTO_CREATE_TACTIC_CASE(Dribble, dribble) PROTO_CREATE_TACTIC_CASE(GetBehindBall, get_behind_ball) PROTO_CREATE_TACTIC_CASE(Goalie, goalie) - PROTO_CREATE_TACTIC_CASE(Kick, kick) + PROTO_CREATE_TACTIC_CASE(KickOrChip, kick_or_chip) PROTO_CREATE_TACTIC_CASE(MoveGoalieToGoalLine, move_goalie_to_goal_line) PROTO_CREATE_TACTIC_CASE(Move, move) PROTO_CREATE_TACTIC_CASE(PassDefender, pass_defender) @@ -59,17 +58,6 @@ std::shared_ptr createTactic( return tactic; } -std::shared_ptr createTactic( - const TbotsProto::ChipTactic& tactic_proto, - std::shared_ptr ai_config_ptr) -{ - auto tactic = std::make_shared(ai_config_ptr); - tactic->updateControlParams(createPoint(tactic_proto.chip_origin()), - createAngle(tactic_proto.chip_direction()), - tactic_proto.chip_distance_meters()); - return tactic; -} - std::shared_ptr createTactic( const TbotsProto::CreaseDefenderTactic& tactic_proto, std::shared_ptr ai_config_ptr) @@ -125,13 +113,13 @@ std::shared_ptr createTactic( } std::shared_ptr createTactic( - const TbotsProto::KickTactic& tactic_proto, + const TbotsProto::KickOrChipTactic& tactic_proto, std::shared_ptr ai_config_ptr) { - auto tactic = std::make_shared(ai_config_ptr); - tactic->updateControlParams(createPoint(tactic_proto.kick_origin()), - createAngle(tactic_proto.kick_direction()), - tactic_proto.kick_speed_meters_per_second()); + auto tactic = std::make_shared(ai_config_ptr); + tactic->updateControlParams(createPoint(tactic_proto.kick_or_chip_origin()), + createAngle(tactic_proto.kick_or_chip_direction()), + createAutoChipOrKick(tactic_proto.auto_chip_or_kick())); return tactic; } diff --git a/src/software/ai/hl/stp/tactic/tactic_factory.h b/src/software/ai/hl/stp/tactic/tactic_factory.h index b402bb8dbb..ab92265d88 100644 --- a/src/software/ai/hl/stp/tactic/tactic_factory.h +++ b/src/software/ai/hl/stp/tactic/tactic_factory.h @@ -17,9 +17,6 @@ std::shared_ptr createTactic( std::shared_ptr createTactic( const TbotsProto::AttackerTactic& tactic_proto, std::shared_ptr ai_config_ptr); -std::shared_ptr createTactic( - const TbotsProto::ChipTactic& tactic_proto, - std::shared_ptr ai_config_ptr); std::shared_ptr createTactic( const TbotsProto::CreaseDefenderTactic& tactic_proto, std::shared_ptr ai_config_ptr); @@ -33,7 +30,7 @@ std::shared_ptr createTactic( const TbotsProto::GoalieTactic& tactic_proto, std::shared_ptr ai_config_ptr); std::shared_ptr createTactic( - const TbotsProto::KickTactic& tactic_proto, + const TbotsProto::KickOrChipTactic& tactic_proto, std::shared_ptr ai_config_ptr); std::shared_ptr createTactic( const TbotsProto::MoveGoalieToGoalLineTactic& tactic_proto, diff --git a/src/software/ai/hl/stp/tactic/tactic_visitor.h b/src/software/ai/hl/stp/tactic/tactic_visitor.h index 0c985c613c..125837b28d 100644 --- a/src/software/ai/hl/stp/tactic/tactic_visitor.h +++ b/src/software/ai/hl/stp/tactic/tactic_visitor.h @@ -5,14 +5,12 @@ // because tactic.h includes tactic_visitor.h, and each individual library includes // tactic.h. Note: every subclass of this visitor must include all of the classes listed // below -class ChipTactic; class CreaseDefenderTactic; class DefenseShadowEnemyTactic; class DribbleTactic; class GetBehindBallTactic; class GoalieTactic; class GoalieTestTactic; -class KickTactic; class KickoffChipTactic; class MoveTactic; class MoveTestTactic; @@ -31,6 +29,7 @@ class PlaceBallTactic; class PlaceBallMoveTactic; class WallKickoffTactic; class AvoidInterferenceTactic; +class KickOrChipTactic; /** * Refer to the docs about why we use the Visitor Design Pattern @@ -47,14 +46,12 @@ class TacticVisitor * @param tactic The tactic to visit */ - virtual void visit(const ChipTactic& tactic) = 0; virtual void visit(const CreaseDefenderTactic& tactic) = 0; virtual void visit(const DefenseShadowEnemyTactic& tactic) = 0; virtual void visit(const DribbleTactic& tactic) = 0; virtual void visit(const GetBehindBallTactic& tactic) = 0; virtual void visit(const GoalieTactic& tactic) = 0; virtual void visit(const GoalieTestTactic& tactic) = 0; - virtual void visit(const KickTactic& tactic) = 0; virtual void visit(const KickoffChipTactic& tactic) = 0; virtual void visit(const MoveTactic& tactic) = 0; virtual void visit(const MoveTestTactic& tactic) = 0; @@ -73,4 +70,5 @@ class TacticVisitor virtual void visit(const PlaceBallMoveTactic& tactic) = 0; virtual void visit(const WallKickoffTactic& tactic) = 0; virtual void visit(const AvoidInterferenceTactic& tactic) = 0; + virtual void visit(const KickOrChipTactic& tactic) = 0; }; diff --git a/src/software/ai/motion_constraint/motion_constraint_set_builder_test.cpp b/src/software/ai/motion_constraint/motion_constraint_set_builder_test.cpp index 03b6a67e19..d6cd05513d 100644 --- a/src/software/ai/motion_constraint/motion_constraint_set_builder_test.cpp +++ b/src/software/ai/motion_constraint/motion_constraint_set_builder_test.cpp @@ -34,7 +34,7 @@ std::vector, std::set()), - std::make_tuple(std::make_shared(ai_config_ptr), + std::make_tuple(std::make_shared(ai_config_ptr), std::set(), std::set()), std::make_tuple( diff --git a/src/software/ai/motion_constraint/motion_constraint_visitor.cpp b/src/software/ai/motion_constraint/motion_constraint_visitor.cpp index e116b9f504..cfe02dd308 100644 --- a/src/software/ai/motion_constraint/motion_constraint_visitor.cpp +++ b/src/software/ai/motion_constraint/motion_constraint_visitor.cpp @@ -20,10 +20,6 @@ void MotionConstraintVisitor::visit(const ShadowEnemyTactic& tactic) {} void MotionConstraintVisitor::visit(const MoveTactic& tactic) {} -void MotionConstraintVisitor::visit(const ChipTactic& tactic) {} - -void MotionConstraintVisitor::visit(const KickTactic& tactic) {} - void MotionConstraintVisitor::visit(const PivotKickTactic& tactic) {} void MotionConstraintVisitor::visit(const KickoffChipTactic& tactic) @@ -107,6 +103,8 @@ void MotionConstraintVisitor::visit(const AvoidInterferenceTactic& tactic) current_motion_constraints.clear(); } +void MotionConstraintVisitor::visit(const KickOrChipTactic& tactic) {} + void MotionConstraintVisitor::visit(const PassDefenderTactic& tactic) {} std::set diff --git a/src/software/ai/motion_constraint/motion_constraint_visitor.h b/src/software/ai/motion_constraint/motion_constraint_visitor.h index 347bf1aa27..74d6b7a01d 100644 --- a/src/software/ai/motion_constraint/motion_constraint_visitor.h +++ b/src/software/ai/motion_constraint/motion_constraint_visitor.h @@ -23,8 +23,6 @@ class MotionConstraintVisitor : public TacticVisitor void visit(const CreaseDefenderTactic& tactic) override; void visit(const ShadowEnemyTactic& tactic) override; void visit(const MoveTactic& tactic) override; - void visit(const ChipTactic& tactic) override; - void visit(const KickTactic& tactic) override; void visit(const KickoffChipTactic& tactic) override; void visit(const HaltTactic& tactic) override; void visit(const PenaltyKickTactic& tactic) override; @@ -45,6 +43,7 @@ class MotionConstraintVisitor : public TacticVisitor void visit(const WallKickoffTactic& tactic) override; void visit(const AvoidInterferenceTactic& tactic) override; void visit(const PassDefenderTactic& tactic) override; + void visit(const KickOrChipTactic& tactic) override; /** * Gets the motion constraints updated with the requirements of the tactics diff --git a/src/software/field_tests/passing_field_test.py b/src/software/field_tests/passing_field_test.py index 43785bb5d4..4336bc4803 100644 --- a/src/software/field_tests/passing_field_test.py +++ b/src/software/field_tests/passing_field_test.py @@ -42,13 +42,15 @@ def test_passing(field_test_runner): # We use KickTactic since AttackerTactic shoots towards the goal instead if open # KickTactic just does the kick we want blue_tactics = {} - blue_tactics[passer_robot_id] = KickTactic( - kick_origin=Point( + blue_tactics[passer_robot_id] = KickOrChipTactic( + kick_or_chip_origin=Point( x_meters=pass_to_test.passerPoint().x(), y_meters=pass_to_test.passerPoint().y(), ), - kick_direction=Angle(radians=kick_vec.orientation().toRadians()), - kick_speed_meters_per_second=pass_to_test.speed(), + kick_or_chip_direction=Angle(radians=kick_vec.orientation().toRadians()), + auto_chip_or_kick=AutoChipOrKick( + autokick_speed_m_per_s=pass_to_test.speed(), + ), ) # if we want a friendly robot to receive the pass