Thunderbots Project
Loading...
Searching...
No Matches
tactic_fsm.h
1
#pragma once
2
3
#include <functional>
4
5
#include "proto/primitive/primitive_msg_factory.h"
6
#include "proto/tbots_software_msgs.pb.h"
7
#include "software/ai/hl/stp/tactic/primitive.h"
8
#include "software/ai/hl/stp/tactic/stop_primitive.h"
9
#include "software/util/sml_fsm/sml_fsm.h"
10
#include "software/world/world.h"
11
12
using
SetPrimitiveCallback = std::function<void(std::shared_ptr<Primitive>)>;
13
14
// The tactic update struct is used to update tactics and set the new primitive
15
struct
TacticUpdate
16
{
17
TacticUpdate
(
const
Robot
&robot,
const
WorldPtr &world_ptr,
18
const
SetPrimitiveCallback &set_primitive_fun)
19
: robot(robot), world_ptr(world_ptr), set_primitive(set_primitive_fun)
20
{
21
}
22
23
// updated robot that tactic is assigned to
24
Robot
robot;
25
// updated world
26
WorldPtr world_ptr;
27
// callback to return the next primitive
28
SetPrimitiveCallback set_primitive;
29
};
30
38
#define DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS \
39
struct Update \
40
{ \
41
Update(const ControlParams &control_params, const TacticUpdate &common) \
42
: control_params(control_params), common(common) \
43
{ \
44
} \
45
ControlParams control_params; \
46
TacticUpdate common; \
47
};
48
49
#define DEFINE_TACTIC_DONE_AND_GET_FSM_STATE \
50
bool done() const override \
51
{ \
52
bool is_done = false; \
53
if (last_execution_robot.has_value()) \
54
{ \
55
is_done = fsm_map.at(last_execution_robot.value())->is(boost::sml::X); \
56
} \
57
return is_done; \
58
} \
59
\
60
std::string getFSMState() const override \
61
{ \
62
std::string state_str = ""; \
63
if (last_execution_robot.has_value()) \
64
state_str = \
65
getCurrentFullStateName(*fsm_map.at(last_execution_robot.value())); \
66
return state_str; \
67
}
68
69
#define SET_STOP_PRIMITIVE_ACTION \
70
[this](auto event) { event.common.set_primitive(std::make_unique<StopPrimitive>()); }
Robot
Definition
robot.h:16
TacticUpdate
Definition
tactic_fsm.h:16
src
software
ai
hl
stp
tactic
tactic_fsm.h
Generated by
1.9.8