forked from UBC-Thunderbots/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchip_fsm.h
More file actions
89 lines (75 loc) · 2.6 KB
/
chip_fsm.h
File metadata and controls
89 lines (75 loc) · 2.6 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
87
88
89
#pragma once
#include "software/ai/hl/stp/tactic/get_behind_ball/get_behind_ball_fsm.h"
#include "software/ai/hl/stp/tactic/tactic_base.hpp"
#include "software/geom/point.h"
struct ChipFSM : TacticFSM<ChipFSM>
{
class ChipState;
struct ControlParams
{
// The location where the chip will be taken from
Point chip_origin;
// The direction the Robot will chip in
Angle chip_direction;
// The distance the robot will chip to
double chip_distance_meters;
};
using Update = TacticFSM<ChipFSM>::Update;
/**
* Constructor for ChipFSM
*
* @param ai_config_ptr Shared pointer to ai_config
*/
explicit ChipFSM(std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr);
/**
* Action that updates the MovePrimitive
*
* @param event ChipFSM::Update event
*/
void updateChip(const Update& event);
/**
* Action that updates the GetBehindBallFSM
*
* @param event ChipFSM::Update event
* @param processEvent processes the GetBehindBallFSM::Update
*/
void updateGetBehindBall(
const Update& event,
boost::sml::back::process<GetBehindBallFSM::Update> processEvent);
/**
* Guard that checks if the ball has been chicked
*
* @param event ChipFSM::Update event
*
* @return if the ball has been chicked
*/
bool ballChicked(const Update& event);
/**
* Guard that checks if the robot is aligned for the chip
*
* @param event KickFSM::Update event
*
* @return if the robot is aligned for the chip
*/
bool shouldRealignWithBall(const Update& event);
auto operator()()
{
using namespace boost::sml;
DEFINE_SML_STATE(GetBehindBallFSM)
DEFINE_SML_STATE(ChipState)
DEFINE_SML_EVENT(Update)
DEFINE_SML_GUARD(ballChicked)
DEFINE_SML_GUARD(shouldRealignWithBall)
DEFINE_SML_ACTION(updateChip)
DEFINE_SML_SUB_FSM_UPDATE_ACTION(updateGetBehindBall, GetBehindBallFSM)
return make_transition_table(
// src_state + event [guard] / action = dest_state
*GetBehindBallFSM_S + Update_E / updateGetBehindBall_A,
GetBehindBallFSM_S = ChipState_S,
ChipState_S + Update_E[shouldRealignWithBall_G] / updateGetBehindBall_A =
GetBehindBallFSM_S,
ChipState_S + Update_E[!ballChicked_G] / updateChip_A = ChipState_S,
ChipState_S + Update_E[ballChicked_G] / SET_STOP_PRIMITIVE_ACTION = X,
X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
}
};