forked from UBC-Thunderbots/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattacker_fsm.h
More file actions
86 lines (74 loc) · 2.89 KB
/
attacker_fsm.h
File metadata and controls
86 lines (74 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include "proto/parameters.pb.h"
#include "software/ai/evaluation/keep_away.h"
#include "software/ai/evaluation/shot.h"
#include "software/ai/hl/stp/tactic/chip/chip_fsm.h"
#include "software/ai/hl/stp/tactic/keep_away/keep_away_fsm.h"
#include "software/ai/hl/stp/tactic/pivot_kick/pivot_kick_fsm.h"
#include "software/ai/hl/stp/tactic/tactic_base.hpp"
#include "software/ai/passing/pass.h"
struct AttackerFSM : TacticFSM<AttackerFSM>
{
struct ControlParams
{
// The best pass so far
std::optional<Pass> best_pass_so_far;
// whether we have committed to the pass and will be taking it
bool pass_committed;
// The shot to take
std::optional<Shot> shot;
// The point the robot will chip towards if it is unable to shoot and is in danger
// of losing the ball to an enemy
std::optional<Point> chip_target;
};
using Update = TacticFSM<AttackerFSM>::Update;
/**
* Constructor for AttackerFSM
*
* @param ai_config_ptr Shared pointer to ai_config
*/
explicit AttackerFSM(std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr);
/**
* Action that updates the PivotKickFSM to shoot or pass
*
* @param event AttackerFSM::Update event
* @param processEvent processes the PivotKickFSM::Update
*/
void pivotKick(const Update& event,
boost::sml::back::process<PivotKickFSM::Update> processEvent);
/**
* Action that updates the KeepAwayFSM to keep the ball away
*
* @param event AttackerFSM::Update event
* @param processEvent processes the KeepAwayFSM::Update
*/
void keepAway(const Update& event,
boost::sml::back::process<KeepAwayFSM::Update> processEvent);
/**
* Guard that checks if the ball should be kicked, which is when there's a nearby
* enemy or a good pass/shot
*
* @param event AttackerFSM::Update event
*
* @return if the ball should be kicked
*/
bool shouldKick(const Update& event);
auto operator()()
{
using namespace boost::sml;
DEFINE_SML_STATE(PivotKickFSM)
DEFINE_SML_STATE(KeepAwayFSM)
DEFINE_SML_STATE(DribbleFSM)
DEFINE_SML_EVENT(Update)
DEFINE_SML_GUARD(shouldKick)
DEFINE_SML_SUB_FSM_UPDATE_ACTION(pivotKick, PivotKickFSM)
DEFINE_SML_SUB_FSM_UPDATE_ACTION(keepAway, KeepAwayFSM)
return make_transition_table(
*DribbleFSM_S + Update_E[shouldKick_G] / pivotKick_A = PivotKickFSM_S,
DribbleFSM_S + Update_E[!shouldKick_G] / keepAway_A = KeepAwayFSM_S,
KeepAwayFSM_S + Update_E[shouldKick_G] / pivotKick_A = PivotKickFSM_S,
KeepAwayFSM_S + Update_E / keepAway_A, KeepAwayFSM_S = DribbleFSM_S,
PivotKickFSM_S + Update_E / pivotKick_A, PivotKickFSM_S = X,
X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
}
};