Thunderbots Project
Loading...
Searching...
No Matches
receiver_fsm.h
1#pragma once
2
3#include "shared/constants.h"
4#include "software/ai/evaluation/calc_best_shot.h"
5#include "software/ai/hl/stp/tactic/dribble/dribble_fsm.h"
6#include "software/ai/hl/stp/tactic/kick/kick_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/passing/pass.h"
10#include "software/geom/algorithms/closest_point.h"
11#include "software/logger/logger.h"
12
14{
20 explicit ReceiverFSM(TbotsProto::ReceiverTacticConfig receiver_tactic_config)
21 : receiver_tactic_config(receiver_tactic_config)
22 {
23 }
24
25 class OneTouchShotState;
26 class ReceiveAndDribbleState;
27 class WaitingForPassState;
28
30 {
31 // The pass to receive
32 std::optional<Pass> pass = std::nullopt;
33
34 // If set to true, we will only receive and dribble
35 bool disable_one_touch_shot = false;
36 };
37
38 DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
39
40 static constexpr double MIN_PASS_START_SPEED_M_PER_SEC = 0.02;
41 static constexpr double BALL_MIN_MOVEMENT_SPEED_M_PER_SEC = 0.04;
42
43 // The minimum angle between a ball's trajectory and the ball-receiver_point vector
44 // for which we can consider a pass to be stray (i.e it won't make it to the receiver)
45 static constexpr Angle MIN_STRAY_PASS_ANGLE = Angle::fromDegrees(60);
46
47 // the minimum speed required for a pass to be considered stray
48 static constexpr double MIN_STRAY_PASS_SPEED = 0.3;
49
57 static Angle getOneTouchShotDirection(const Ray& shot, const Ball& ball);
58
68 const Ball& ball,
69 const Point& best_shot_target);
70
71 /*
72 * Finds a shot that is greater than min_open_angle_for_one_touch_deg and
73 * respects max_deflection_for_one_touch_deg for the highest chance
74 * of scoring with a one-touch shot. If neither of those are true, return a nullopt
75 *
76 * @param world The world to find a feasible shot on
77 * @param assigned_robot The robot that will be performing the one-touch
78 */
79 std::optional<Shot> findFeasibleShot(const World& world, const Robot& assigned_robot);
80
87 bool onetouchPossible(const Update& event);
88
98 void updateOnetouch(const Update& event);
99
105 void updateReceive(const Update& event);
106
115 void adjustReceive(const Update& event);
116
124 bool passStarted(const Update& event);
125
133 bool passFinished(const Update& event);
134
142 bool strayPass(const Update& event);
143
144 auto operator()()
145 {
146 using namespace boost::sml;
147
148 DEFINE_SML_STATE(ReceiveAndDribbleState)
149 DEFINE_SML_STATE(OneTouchShotState)
150 DEFINE_SML_STATE(WaitingForPassState)
151 DEFINE_SML_EVENT(Update)
152
153 DEFINE_SML_GUARD(onetouchPossible)
154 DEFINE_SML_GUARD(passStarted)
155 DEFINE_SML_GUARD(passFinished)
156 DEFINE_SML_GUARD(strayPass)
157
158 DEFINE_SML_ACTION(updateOnetouch)
159 DEFINE_SML_ACTION(updateReceive)
160 DEFINE_SML_ACTION(adjustReceive)
161
162 return make_transition_table(
163 // src_state + event [guard] / action = dest_state
164 *WaitingForPassState_S + Update_E[!passStarted_G] / updateReceive_A,
165 WaitingForPassState_S + Update_E[passStarted_G && onetouchPossible_G] /
166 updateOnetouch_A = OneTouchShotState_S,
167 WaitingForPassState_S + Update_E[passStarted_G && !onetouchPossible_G] /
168 updateReceive_A = ReceiveAndDribbleState_S,
169 ReceiveAndDribbleState_S + Update_E[!passFinished_G] / adjustReceive_A,
170 OneTouchShotState_S +
171 Update_E[!passFinished_G && !strayPass_G] / updateOnetouch_A,
172 OneTouchShotState_S + Update_E[!passFinished_G && strayPass_G] /
173 adjustReceive_A = ReceiveAndDribbleState_S,
174 ReceiveAndDribbleState_S + Update_E[passFinished_G] / adjustReceive_A = X,
175 OneTouchShotState_S + Update_E[passFinished_G] / updateOnetouch_A = X,
176 X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
177 }
178
179 private:
180 // the receiver tactic config
181 TbotsProto::ReceiverTacticConfig receiver_tactic_config;
182};
Definition angle.h:15
static constexpr Angle fromDegrees(double deg)
Definition angle.h:408
Definition ball.h:11
Definition point.h:14
Definition ray.h:6
Definition robot.h:16
Definition shot.h:6
Definition world.h:23
Definition receiver_fsm.h:30
Definition receiver_fsm.h:14
bool passStarted(const Update &event)
Definition receiver_fsm.cpp:177
static Angle getOneTouchShotDirection(const Ray &shot, const Ball &ball)
Definition receiver_fsm.cpp:5
void updateOnetouch(const Update &event)
Definition receiver_fsm.cpp:112
bool strayPass(const Update &event)
Definition receiver_fsm.cpp:190
void adjustReceive(const Update &event)
Definition receiver_fsm.cpp:150
ReceiverFSM(TbotsProto::ReceiverTacticConfig receiver_tactic_config)
Definition receiver_fsm.h:20
static Shot getOneTouchShotPositionAndOrientation(const Robot &robot, const Ball &ball, const Point &best_shot_target)
Definition receiver_fsm.cpp:35
void updateReceive(const Update &event)
Definition receiver_fsm.cpp:136
bool onetouchPossible(const Update &event)
Definition receiver_fsm.cpp:104
bool passFinished(const Update &event)
Definition receiver_fsm.cpp:183