Thunderbots Project
Loading...
Searching...
No Matches
penalty_kick_fsm.h
1#pragma once
2
3#include "software/ai/hl/stp/tactic/dribble/dribble_fsm.h"
4#include "software/ai/hl/stp/tactic/get_behind_ball/get_behind_ball_fsm.h"
5#include "software/ai/hl/stp/tactic/kick/kick_fsm.h"
6#include "software/ai/hl/stp/tactic/move/move_fsm.h"
7#include "software/ai/hl/stp/tactic/tactic.h"
8#include "software/geom/algorithms/closest_point.h"
9#include "software/geom/algorithms/intersection.h"
10
12{
17
19 {
20 };
21
22 DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
23
35 static bool evaluatePenaltyShot(std::optional<Robot> enemy_goalie, Field field,
36 Point ball_position, Robot robot);
37
47 static const Point evaluateNextShotPosition(std::optional<Robot> enemy_goalie,
48 Field field);
49
56 void shoot(const Update &event,
57 boost::sml::back::process<KickFSM::Update> processEvent);
58
65 void updateApproachKeeper(const Update &event,
66 boost::sml::back::process<DribbleFSM::Update> processEvent);
67
75 const Update &event, boost::sml::back::process<DribbleFSM::Update> processEvent);
76
85 bool takePenaltyShot(const Update &event);
86
95 bool timeOutApproach(const Update &event);
96
97
98 auto operator()()
99 {
100 using namespace boost::sml;
101
102 DEFINE_SML_STATE(DribbleFSM)
103 DEFINE_SML_STATE(KickFSM)
104
105 DEFINE_SML_EVENT(Update)
106
107 DEFINE_SML_GUARD(takePenaltyShot)
108 DEFINE_SML_GUARD(timeOutApproach)
109
110 DEFINE_SML_SUB_FSM_UPDATE_ACTION(shoot, KickFSM)
111 DEFINE_SML_SUB_FSM_UPDATE_ACTION(updateApproachKeeper, DribbleFSM)
112 DEFINE_SML_SUB_FSM_UPDATE_ACTION(adjustOrientationForShot, DribbleFSM)
113
114 return make_transition_table(
115 // src_state + event [guard] / action = dest state
116 *DribbleFSM_S + Update_E[!takePenaltyShot_G] / updateApproachKeeper_A,
117 DribbleFSM_S + Update_E[timeOutApproach_G] / shoot_A = KickFSM_S,
118 DribbleFSM_S + Update_E / adjustOrientationForShot_A,
119 DribbleFSM_S = KickFSM_S, KickFSM_S + Update_E / shoot_A, KickFSM_S = X,
120 X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
121 };
122
123 private:
124 static constexpr double PENALTY_KICK_POST_OFFSET = 0.03;
125 static constexpr double PENALTY_KICK_SHOT_SPEED = 5.0;
126
127 // expected maximum acceleration of the opposition goalie robot
128 static constexpr double PENALTY_KICK_GOALIE_MAX_ACC = 1.5;
129 static constexpr double SSL_VISION_DELAY = 0.30; // seconds
130
131 // the fraction of the enemy side of the field that we define to be the lower limit of
132 // where we choose to shoot in other words, it helps define the minimum distance at
133 // which we decide to potentially shoot
134 static constexpr double PENALTY_KICK_MIN_SHOT_X_DISTANCE_FACTOR = 1.0 / 3.0;
135
136 // timeout that forces a shot after the robot approaches the ball and advances
137 // towards the keeper
138 // these two timeouts together must be <= 9 seconds
139 static const inline Duration PENALTY_FORCE_SHOOT_TIMEOUT = Duration::fromSeconds(4);
140 static const inline Duration PENALTY_FINISH_APPROACH_TIMEOUT =
142
143 private:
144 std::optional<Timestamp> complete_approach;
145 Angle shot_angle;
146};
Definition angle.h:15
Definition duration.h:12
static const Duration fromSeconds(double seconds)
Definition duration.cpp:13
Definition field.h:36
Definition point.h:14
Definition robot.h:16
Definition dribble_fsm.h:14
Definition kick_fsm.h:7
Definition penalty_kick_fsm.h:19
Definition penalty_kick_fsm.h:12
static DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS bool evaluatePenaltyShot(std::optional< Robot > enemy_goalie, Field field, Point ball_position, Robot robot)
Definition penalty_kick_fsm.cpp:5
void adjustOrientationForShot(const Update &event, boost::sml::back::process< DribbleFSM::Update > processEvent)
Definition penalty_kick_fsm.cpp:147
PenaltyKickFSM()
Definition penalty_kick_fsm.cpp:3
static const Point evaluateNextShotPosition(std::optional< Robot > enemy_goalie, Field field)
Definition penalty_kick_fsm.cpp:97
bool takePenaltyShot(const Update &event)
Definition penalty_kick_fsm.cpp:162
void shoot(const Update &event, boost::sml::back::process< KickFSM::Update > processEvent)
Definition penalty_kick_fsm.cpp:119
bool timeOutApproach(const Update &event)
Definition penalty_kick_fsm.cpp:187
void updateApproachKeeper(const Update &event, boost::sml::back::process< DribbleFSM::Update > processEvent)
Definition penalty_kick_fsm.cpp:129