Thunderbots Project
Loading...
Searching...
No Matches
crease_defender_fsm.h
1#pragma once
2
3#include "proto/parameters.pb.h"
4#include "proto/tactic.pb.h"
5#include "software/ai/hl/stp/tactic/defender/defender_fsm_base.h"
6#include "software/ai/hl/stp/tactic/dribble/dribble_fsm.h"
7#include "software/ai/hl/stp/tactic/move/move_fsm.h"
8#include "software/ai/hl/stp/tactic/tactic.h"
9#include "software/ai/hl/stp/tactic/transition_conditions.h"
10#include "software/geom/algorithms/contains.h"
11#include "software/geom/algorithms/convex_angle.h"
12#include "software/geom/algorithms/intersection.h"
13#include "software/geom/ray.h"
14#include "software/logger/logger.h"
15
17{
18 public:
19 // this struct defines the unique control parameters that the CreaseDefenderFSM
20 // requires in its update
22 {
23 // The origin point of the enemy threat
24 Point enemy_threat_origin;
25 // The crease defender alignment with respect to the enemy threat
26 TbotsProto::CreaseDefenderAlignment crease_defender_alignment;
27 // The maximum allowed speed mode
28 TbotsProto::MaxAllowedSpeedMode max_allowed_speed_mode;
29 // The crease defender's aggressiveness towards the ball
30 TbotsProto::BallStealMode ball_steal_mode;
31 };
32
33 // this struct defines the only event that the CreaseDefenderFSM responds to
34 DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
35
46 static std::optional<Point> findBlockThreatPoint(
47 const Field& field, const Point& enemy_threat_origin,
48 const TbotsProto::CreaseDefenderAlignment& crease_defender_alignment,
49 double robot_obstacle_inflation_factor);
50
56 explicit CreaseDefenderFSM(const TbotsProto::AiConfig& ai_config)
57 : robot_navigation_obstacle_config(ai_config.robot_navigation_obstacle_config()),
58 crease_defender_config(ai_config.crease_defender_config())
59 {
60 }
61
71 bool ballNearbyWithoutThreat(const Update& event);
72
78 void prepareGetPossession(const Update& event,
79 boost::sml::back::process<DribbleFSM::Update> processEvent);
80
86 void blockThreat(const Update& event,
87 boost::sml::back::process<MoveFSM::Update> processEvent);
88
89 auto operator()()
90 {
91 using namespace boost::sml;
92
93 DEFINE_SML_STATE(MoveFSM)
94 DEFINE_SML_EVENT(Update)
95 DEFINE_SML_SUB_FSM_UPDATE_ACTION(blockThreat, MoveFSM)
96 DEFINE_SML_STATE(DribbleFSM)
97 DEFINE_SML_GUARD(ballNearbyWithoutThreat)
98 DEFINE_SML_SUB_FSM_UPDATE_ACTION(prepareGetPossession, DribbleFSM)
99
100 return make_transition_table(
101 // src_state + event [guard] / action = dest_state
102 *MoveFSM_S + Update_E[ballNearbyWithoutThreat_G] / prepareGetPossession_A =
103 DribbleFSM_S,
104 MoveFSM_S + Update_E / blockThreat_A, MoveFSM_S = X,
105 DribbleFSM_S + Update_E[!ballNearbyWithoutThreat_G] / blockThreat_A =
106 MoveFSM_S,
107 DribbleFSM_S + Update_E / prepareGetPossession_A,
108 X + Update_E[ballNearbyWithoutThreat_G] / prepareGetPossession_A =
109 DribbleFSM_S,
110 X + Update_E / blockThreat_A = MoveFSM_S);
111 }
112
113 private:
114 static constexpr double DETECT_THREAT_AHEAD_SHAPE_LENGTH_M = 1;
115 static constexpr double DETECT_THREAT_AHEAD_SHAPE_RADIUS_M = 0.25;
128 static std::optional<Point> findDefenseAreaIntersection(
129 const Field& field, const Ray& ray, double robot_obstacle_inflation_factor);
130
138 static bool isAnyEnemyInZone(const Update& event, const Stadium& zone);
139
140 TbotsProto::RobotNavigationObstacleConfig robot_navigation_obstacle_config;
141 TbotsProto::CreaseDefenderConfig crease_defender_config;
142};
Definition field.h:36
Definition point.h:14
Definition ray.h:6
Definition stadium.h:12
Definition crease_defender_fsm.h:22
Definition crease_defender_fsm.h:17
void prepareGetPossession(const Update &event, boost::sml::back::process< DribbleFSM::Update > processEvent)
Definition crease_defender_fsm.cpp:210
void blockThreat(const Update &event, boost::sml::back::process< MoveFSM::Update > processEvent)
Definition crease_defender_fsm.cpp:46
bool ballNearbyWithoutThreat(const Update &event)
Definition crease_defender_fsm.cpp:201
static DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS std::optional< Point > findBlockThreatPoint(const Field &field, const Point &enemy_threat_origin, const TbotsProto::CreaseDefenderAlignment &crease_defender_alignment, double robot_obstacle_inflation_factor)
Definition crease_defender_fsm.cpp:9
CreaseDefenderFSM(const TbotsProto::AiConfig &ai_config)
Definition crease_defender_fsm.h:56
Definition defender_fsm_base.h:10
Definition dribble_fsm.h:14
Definition move_fsm.h:6