Thunderbots Project
Loading...
Searching...
No Matches
pass_defender_fsm.h
1#pragma once
2
3#include "proto/tactic.pb.h"
4#include "shared/constants.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/tactic.h"
8#include "software/logger/logger.h"
9
11{
12 class BlockPassState;
13 class InterceptBallState;
14
15 // This struct defines the unique control parameters that the PassDefenderFSM requires
16 // in its update
18 {
19 // The location on the field to block enemy passes from
20 Point position_to_block_from;
21 // The pass defender's aggressiveness towards the ball
22 TbotsProto::BallStealMode ball_steal_mode;
23 };
24
30 explicit PassDefenderFSM(const TbotsProto::AiConfig& ai_config)
31 : pass_defender_config(ai_config.pass_defender_config())
32 {
33 }
34
35
36 DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
37
38 // The minimum speed of the ball for it to be considered a pass
39 static constexpr double MIN_PASS_SPEED = 0.5;
40
41 // The maximum angle difference to determine if ball has been kicked in
42 // the approximate direction of the defender
43 static constexpr Angle MAX_PASS_ANGLE_DIFFERENCE = Angle::fromDegrees(30);
44
45 // The minimum angle difference between a ball's trajectory and
46 // pass_orientation for which we can consider a pass to be deflected
47 static constexpr Angle MIN_DEFLECTION_ANGLE = Angle::fromDegrees(30);
48
56 bool passStarted(const Update& event);
57
68 bool ballDeflected(const Update& event);
69
75 void blockPass(const Update& event);
76
84 void interceptBall(const Update& event);
85
94 bool ballNearbyWithoutThreat(const Update& event);
95
101 void prepareGetPossession(const Update& event,
102 boost::sml::back::process<DribbleFSM::Update> processEvent);
103
104
105 auto operator()()
106 {
107 using namespace boost::sml;
108
109 DEFINE_SML_STATE(BlockPassState)
110 DEFINE_SML_STATE(InterceptBallState)
111
112 DEFINE_SML_EVENT(Update)
113
114 DEFINE_SML_GUARD(passStarted)
115 DEFINE_SML_GUARD(ballDeflected)
116
117 DEFINE_SML_ACTION(blockPass)
118 DEFINE_SML_ACTION(interceptBall)
119
120 DEFINE_SML_STATE(DribbleFSM)
121 DEFINE_SML_GUARD(ballNearbyWithoutThreat)
122 DEFINE_SML_SUB_FSM_UPDATE_ACTION(prepareGetPossession, DribbleFSM)
123
124 return make_transition_table(
125 // src_state + event [guard] / action = dest_state
126 *BlockPassState_S + Update_E[passStarted_G] / interceptBall_A =
127 InterceptBallState_S,
128 BlockPassState_S + Update_E / blockPass_A,
129 InterceptBallState_S + Update_E[ballDeflected_G] / blockPass_A =
130 BlockPassState_S,
131 InterceptBallState_S + Update_E[ballNearbyWithoutThreat_G] /
132 prepareGetPossession_A = DribbleFSM_S,
133 DribbleFSM_S + Update_E[!ballNearbyWithoutThreat_G] / blockPass_A =
134 BlockPassState_S,
135 DribbleFSM_S + Update_E / prepareGetPossession_A,
136 InterceptBallState_S + Update_E / interceptBall_A,
137 X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
138 }
139
140 private:
141 Angle pass_orientation;
142 TbotsProto::PassDefenderConfig pass_defender_config;
143};
Definition angle.h:15
static constexpr Angle fromDegrees(double deg)
Definition angle.h:408
Definition point.h:14
Definition defender_fsm_base.h:10
Definition dribble_fsm.h:14
Definition pass_defender_fsm.h:18
Definition pass_defender_fsm.h:11
bool passStarted(const Update &event)
Definition pass_defender_fsm.cpp:7
void prepareGetPossession(const Update &event, boost::sml::back::process< DribbleFSM::Update > processEvent)
Definition pass_defender_fsm.cpp:117
void interceptBall(const Update &event)
Definition pass_defender_fsm.cpp:57
bool ballDeflected(const Update &event)
Definition pass_defender_fsm.cpp:29
bool ballNearbyWithoutThreat(const Update &event)
Definition pass_defender_fsm.cpp:110
PassDefenderFSM(const TbotsProto::AiConfig &ai_config)
Definition pass_defender_fsm.h:30
void blockPass(const Update &event)
Definition pass_defender_fsm.cpp:40