-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathmove_fsm.h
71 lines (61 loc) · 2.36 KB
/
move_fsm.h
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
#pragma once
#include "software/ai/hl/stp/tactic/tactic.h"
struct MoveFSM
{
public:
// these classes define the states used in the transition table
// they are exposed so that tests can check if the FSM is in a particular state
class MoveState;
// this struct defines the unique control parameters that the MoveFSM requires in its
// update
struct ControlParams
{
// The point the robot is trying to move to
Point destination;
// The orientation the robot should have when it arrives at its destination
Angle final_orientation;
// How to run the dribbler
TbotsProto::DribblerMode dribbler_mode;
// How to navigate around the ball
TbotsProto::BallCollisionType ball_collision_type;
// The command to autochip or autokick
AutoChipOrKick auto_chip_or_kick;
// The maximum allowed speed mode
TbotsProto::MaxAllowedSpeedMode max_allowed_speed_mode;
// The obstacle avoidance mode
TbotsProto::ObstacleAvoidanceMode obstacle_avoidance_mode;
};
// this struct defines the only event that the MoveFSM responds to
DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
/**
* This is an Action that sets the primitive to a move primitive corresponding to the
* Update_E event
*
* @param event MoveFSM::Update event
*/
void updateMove(const Update &event);
/**
* This guard is used to check if the robot is done moving
*
* @param event MoveFSM::Update event
*
* @return if robot has reached the destination
*/
bool moveDone(const Update &event);
auto operator()()
{
using namespace boost::sml;
// MoveState_S is the _state_ used in the transition table
DEFINE_SML_STATE(MoveState)
// Update_E is the _event_ that the MoveFSM responds to
DEFINE_SML_EVENT(Update)
DEFINE_SML_GUARD(moveDone)
DEFINE_SML_ACTION(updateMove)
return make_transition_table(
// src_state + event [guard] / action = dest_state
*MoveState_S + Update_E[!moveDone_G] / updateMove_A = MoveState_S,
MoveState_S + Update_E[moveDone_G] / updateMove_A = X,
X + Update_E[!moveDone_G] / updateMove_A = MoveState_S,
X + Update_E / updateMove_A = X);
}
};