-
Notifications
You must be signed in to change notification settings - Fork 124
Coroutines to fsm #3613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StarrryNight
wants to merge
24
commits into
UBC-Thunderbots:master
Choose a base branch
from
StarrryNight:coroutines_to_fsm_#2359
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+517
−205
Open
Coroutines to fsm #3613
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
57919a7
add halt_test_play fsm
StarrryNight 061e6d6
update halt_test_play.h
StarrryNight 8dae978
convert halt_test_play.cpp
StarrryNight ed8a8cf
add test and update build
StarrryNight ca79647
fix bugs
StarrryNight f886ed8
pass fsm test
StarrryNight c6c8c8b
finish fsm.h for move
StarrryNight 322884f
finish constructor for move_test_play
StarrryNight de66e65
fix bugs:
StarrryNight d5f3530
update build
StarrryNight 5788d40
add test and test passes
StarrryNight dc128ef
reorganize shoot or chip
StarrryNight 9d813b8
finish shoot or chip fsm
StarrryNight d564bae
fix bugs
StarrryNight b77ad5e
fix more bugs and integrate into original shoot or chip play'
StarrryNight df3988f
finish integration
StarrryNight 5fe618c
update BUILD
StarrryNight 9bb32fc
fix import issues and all shoot_or_pass test passes
StarrryNight 59c5aea
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] ad60d5d
Fix include statement for halt_test_play_fsm.h
StarrryNight a4c9cf0
Fix include statement for move_test_play_fsm.h
StarrryNight 95d4cd4
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 015a52e
add doc comments
0b19293
remove halt tactic
StarrryNight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,62 @@ | ||
| load("@simulated_tests_deps//:requirements.bzl", "requirement") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "shoot_or_chip_play", | ||
| srcs = [ | ||
| "shoot_or_chip_play.cpp", | ||
| "shoot_or_chip_play_fsm.cpp", | ||
| ], | ||
| hdrs = [ | ||
| "shoot_or_chip_play.h", | ||
| "shoot_or_chip_play_fsm.h", | ||
| ], | ||
| deps = [ | ||
| "//proto/message_translation:tbots_protobuf", | ||
| "//shared:constants", | ||
| "//software/ai/evaluation:enemy_threat", | ||
| "//software/ai/evaluation:find_open_areas", | ||
| "//software/ai/evaluation:possession", | ||
| "//software/ai/hl/stp/play", | ||
| "//software/ai/hl/stp/tactic/attacker:attacker_tactic", | ||
| "//software/ai/hl/stp/tactic/crease_defender:crease_defender_tactic", | ||
| "//software/ai/hl/stp/tactic/halt:halt_tactic", | ||
| "//software/ai/hl/stp/tactic/move:move_tactic", | ||
| "//software/ai/hl/stp/tactic/shadow_enemy:shadow_enemy_tactic", | ||
| "//software/logger", | ||
| "//software/util/generic_factory", | ||
| "//software/world:game_state", | ||
| ], | ||
| alwayslink = True, | ||
| ) | ||
|
|
||
| cc_test( | ||
| name = "shoot_or_chip_play_cpp_test", | ||
| srcs = ["shoot_or_chip_play_test.cpp"], | ||
| deps = [ | ||
| ":shoot_or_chip_play", | ||
| "//shared/test_util:tbots_gtest_main", | ||
| "//software/simulated_tests:simulated_er_force_sim_play_test_fixture", | ||
| "//software/simulated_tests/validation:validation_function", | ||
| "//software/test_util", | ||
| "//software/time:duration", | ||
| "//software/world", | ||
| ], | ||
| ) | ||
|
|
||
| py_test( | ||
| name = "shoot_or_chip_play_test", | ||
| srcs = [ | ||
| "shoot_or_chip_play_test.py", | ||
| ], | ||
| # TODO (#2619) Remove tag to run in parallel | ||
| tags = [ | ||
| "exclusive", | ||
| ], | ||
| deps = [ | ||
| "//software:conftest", | ||
| "//software/simulated_tests:validation", | ||
| requirement("pytest"), | ||
| ], | ||
| ) |
31 changes: 31 additions & 0 deletions
31
src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play.cpp
This file contains hidden or 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,31 @@ | ||
| #include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play.h" | ||
|
|
||
| #include "proto/message_translation/tbots_protobuf.h" | ||
| #include "shared/constants.h" | ||
| #include "software/logger/logger.h" | ||
| #include "software/util/generic_factory/generic_factory.h" | ||
| #include "software/world/game_state.h" | ||
|
|
||
| ShootOrChipPlay::ShootOrChipPlay( | ||
| std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr) | ||
| : PlayBase<ShootOrChipPlayFSM>(ai_config_ptr, true) | ||
| { | ||
| } | ||
|
|
||
| void ShootOrChipPlay::getNextTactics(TacticCoroutine::push_type &yield, | ||
| const WorldPtr &world_ptr) | ||
| { | ||
| // This function doesn't get called, it should be removed once coroutines | ||
| // are phased out | ||
| } | ||
|
|
||
|
|
||
| void ShootOrChipPlay::updateTactics(const PlayUpdate &play_update) | ||
| { | ||
| fsm.process_event(ShootOrChipPlayFSM::Update(control_params, play_update)); | ||
| } | ||
|
|
||
| // Register this play in the genericFactory | ||
| static TGenericFactory<std::string, Play, ShootOrChipPlay, | ||
| std::shared_ptr<const TbotsProto::AiConfig>> | ||
| factory; | ||
This file contains hidden or 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
97 changes: 97 additions & 0 deletions
97
src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_fsm.cpp
This file contains hidden or 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,97 @@ | ||
| #include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_fsm.h" | ||
|
|
||
| #include "proto/message_translation/tbots_protobuf.h" | ||
| #include "shared/constants.h" | ||
| #include "software/ai/evaluation/enemy_threat.h" | ||
| #include "software/ai/evaluation/find_open_areas.h" | ||
| #include "software/ai/evaluation/possession.h" | ||
| #include "software/ai/hl/stp/tactic/attacker/attacker_tactic.h" | ||
| #include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h" | ||
| #include "software/ai/hl/stp/tactic/move/move_tactic.h" | ||
| #include "software/ai/hl/stp/tactic/shadow_enemy/shadow_enemy_tactic.h" | ||
|
|
||
| ShootOrChipPlayFSM::ShootOrChipPlayFSM( | ||
| std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr) | ||
| : PlayFSM<ShootOrChipPlayFSM>(ai_config_ptr), | ||
| crease_defender_tactics{ | ||
| std::make_shared<CreaseDefenderTactic>(ai_config_ptr), | ||
| std::make_shared<CreaseDefenderTactic>(ai_config_ptr), | ||
| }, | ||
| move_to_open_area_tactics{ | ||
| std::make_shared<MoveTactic>(ai_config_ptr), | ||
| std::make_shared<MoveTactic>(ai_config_ptr), | ||
| }, | ||
| attacker(std::make_shared<AttackerTactic>(ai_config_ptr)) | ||
| { | ||
| } | ||
|
|
||
| void ShootOrChipPlayFSM::updateShootOrChip(const Update& event) | ||
| { | ||
| /** | ||
| * Our general strategy here is: | ||
| * - 1 goalie | ||
| * - 2 crease defenders moving around the friendly defense box | ||
| * - 2 robots moving into the first and second largest open free space on | ||
| * the enemy half | ||
| * - 1 robot trying to shoot on the goal. If an enemy gets too close to this | ||
| * robot, it will chip to right in front of the robot in the largest open free area | ||
| */ | ||
|
|
||
| // Figure out where the fallback chip target is | ||
| // Experimentally determined to be a reasonable value | ||
| double fallback_chip_target_x_offset = 1.5; | ||
|
|
||
| Point fallback_chip_target = event.common.world_ptr->field().enemyGoalCenter() - | ||
| Vector(fallback_chip_target_x_offset, 0); | ||
|
|
||
| // Update chipper | ||
| std::optional<Point> chip_target = fallback_chip_target; | ||
|
|
||
|
|
||
| PriorityTacticVector result = {{}}; | ||
|
|
||
| // Update crease defenders | ||
| std::get<0>(crease_defender_tactics) | ||
| ->updateControlParams(event.common.world_ptr->ball().position(), | ||
| TbotsProto::CreaseDefenderAlignment::LEFT); | ||
| result[0].emplace_back(std::get<0>(crease_defender_tactics)); | ||
| std::get<1>(crease_defender_tactics) | ||
| ->updateControlParams(event.common.world_ptr->ball().position(), | ||
| TbotsProto::CreaseDefenderAlignment::RIGHT); | ||
| result[0].emplace_back(std::get<1>(crease_defender_tactics)); | ||
|
|
||
| // Update tactics moving to open areas | ||
| std::vector<Circle> chip_targets = findGoodChipTargets(*event.common.world_ptr); | ||
| for (unsigned i = 0; i < chip_targets.size() && i < move_to_open_area_tactics.size(); | ||
| i++) | ||
| { | ||
| // Face towards the ball | ||
| Angle orientation = | ||
| (event.common.world_ptr->ball().position() - chip_targets[i].origin()) | ||
| .orientation(); | ||
| // Move a bit backwards to make it more likely we'll receive the chip | ||
| Point position = | ||
| chip_targets[i].origin() - | ||
| Vector::createFromAngle(orientation).normalize(ROBOT_MAX_RADIUS_METERS); | ||
| ; | ||
| move_to_open_area_tactics[i]->updateControlParams(position, orientation); | ||
| result[0].emplace_back(move_to_open_area_tactics[i]); | ||
| } | ||
|
|
||
| if (!chip_targets.empty()) | ||
| { | ||
| chip_target = chip_targets[0].origin(); | ||
| } | ||
| attacker->updateControlParams(chip_target); | ||
|
|
||
| // We want this second in priority only to the goalie | ||
| result[0].insert(result[0].begin() + 1, attacker); | ||
|
|
||
| // set the the Tactics this Play wants to run, in order of priority | ||
| event.common.set_tactics(result); | ||
| } | ||
|
|
||
| bool ShootOrChipPlayFSM::attackerDone(const Update& event) | ||
| { | ||
| return attacker->done(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.