@@ -15,14 +15,25 @@ namespace am
15
15
class AMLifeCycle
16
16
{
17
17
private:
18
+ static constexpr double DEFAULT_OK_THROTTLE_S = 10.0 ;
19
+ static constexpr double DEFAULT_WARN_THROTTLE_S = 2.0 ;
20
+ static constexpr double DEFAULT_ERROR_THROTTLE_S = 1.0 ;
21
+
18
22
LifeCycleState state_;
19
23
LifeCycleStatus status_;
24
+ double ok_throttle_s_ = DEFAULT_OK_THROTTLE_S;
25
+ double warn_throttle_s_ = DEFAULT_WARN_THROTTLE_S;
26
+ double error_throttle_s_ = DEFAULT_ERROR_THROTTLE_S;
20
27
21
- public:
22
- LifeCycleState getState () const ;
23
28
void setState (const LifeCycleState state);
24
- LifeCycleStatus getStatus () const ;
25
- void setStatus (const LifeCycleStatus status);
29
+
30
+ void transition (std::string transition_name, LifeCycleState initial_state, LifeCycleState transition_state,
31
+ LifeCycleState new_state, std::function<void (void )> on_function);
32
+ void doTransition (std::string transition_name, bool success, LifeCycleState success_state,
33
+ LifeCycleState failure_state);
34
+
35
+ public:
36
+ static constexpr std::string_view BROADCAST_NODE_NAME = " " ;
26
37
27
38
static constexpr std::string_view STATE_INVALID_STRING = " INVALID" ;
28
39
static constexpr std::string_view STATE_UNCONFIGURED_STRING = " UNCONFIGURED" ;
@@ -39,17 +50,33 @@ class AMLifeCycle
39
50
static constexpr std::string_view STATUS_WARN_STRING = " WARN" ;
40
51
static constexpr std::string_view STATUS_ERROR_STRING = " ERROR" ;
41
52
53
+ static constexpr std::string_view COMMAND_CREATE_STRING = " CREATE" ;
54
+ static constexpr std::string_view COMMAND_CONFIGURE_STRING = " CONFIGURE" ;
55
+ static constexpr std::string_view COMMAND_CLEANUP_STRING = " CLEANUP" ;
56
+ static constexpr std::string_view COMMAND_ACTIVATE_STRING = " ACTIVATE" ;
57
+ static constexpr std::string_view COMMAND_DEACTIVATE_STRING = " DEACTIVATE" ;
58
+ static constexpr std::string_view COMMAND_SHUTDOWN_STRING = " SHUTDOWN" ;
59
+ static constexpr std::string_view COMMAND_DESTROY_STRING = " DESTROY" ;
60
+
61
+ static constexpr std::string_view EMPTY_STRING = " " ;
62
+
42
63
static const std::string_view& stateToString (LifeCycleState state);
64
+ static bool stringToState (std::string& state_str, LifeCycleState& state);
43
65
static const std::string_view& statusToString (LifeCycleStatus status);
66
+ static bool stringToStatus (std::string& status_str, LifeCycleStatus& status);
67
+ static const std::string_view& commandToString (LifeCycleCommand command);
68
+ static bool stringToCommand (std::string& status_str, LifeCycleCommand& command);
44
69
45
70
protected:
71
+ std::string node_name_;
72
+
46
73
diagnostic_updater::Updater updater_;
47
74
AMStatList stats_list_;
48
75
49
76
ros::NodeHandle nh_;
50
77
ros::Timer heartbeat_timer_;
51
78
ros::Publisher state_pub_;
52
-
79
+ ros::Subscriber lifecycle_sub_;
53
80
/* *
54
81
* @brief Default constructor
55
82
*/
@@ -60,51 +87,72 @@ class AMLifeCycle
60
87
*/
61
88
virtual ~AMLifeCycle ();
62
89
63
- virtual void configure ();
64
- virtual void cleanup ();
65
- virtual void activate ();
66
- virtual void deactivate ();
67
- virtual void shutdown ();
68
- virtual void destroy ();
69
-
70
90
/* *
71
91
* @brief Function to be defined by the user.
72
- * Called at the end of transition from UNCONFIGURED to INACTIVE .
92
+ * Called at the end of transition from INACTIVE to ACTIVE .
73
93
*/
74
- virtual void onConfigure ();
94
+ void activate ();
95
+ virtual void onActivate ();
96
+ void doActivate (bool success);
75
97
76
98
/* *
77
99
* @brief Function to be defined by the user.
78
100
* Called at the end of transition from INACTIVE to UNCONFIGURED.
79
101
*/
80
- virtual void onCleanUp ();
102
+ void cleanup ();
103
+ virtual void onCleanup ();
104
+ void doCleanup (bool success);
81
105
82
106
/* *
83
107
* @brief Function to be defined by the user.
84
- * Called at the end of transition from INACTIVE to ACTIVE .
108
+ * Called at the end of transition from UNCONFIGURED to INACTIVE .
85
109
*/
86
- virtual void onActivate ();
110
+ void configure ();
111
+ virtual void onConfigure ();
112
+ void doConfigure (bool success);
87
113
88
114
/* *
89
115
* @brief Function to be defined by the user.
90
116
* Called at the end of transition from ACTIVE to INACTIVE.
91
117
*/
118
+ void deactivate ();
92
119
virtual void onDeactivate ();
120
+ void doDeactivate (bool success);
93
121
94
122
/* *
95
123
* @brief Function to be defined by the user.
96
- * Called at the end of transition from INACTIVE to FINALIZED .
124
+ * Called at the end of transition from FINALIZED to power off .
97
125
*/
98
- virtual void onShutdown ();
126
+ virtual void destroy ();
127
+ virtual void onDestroy ();
128
+ void doDestroy (bool success);
99
129
100
130
/* *
101
131
* @brief Function to be defined by the user.
102
- * Called after an error and may transition to UNCONFIGURED or FINALIZED.
132
+ * Called at any time and transitions to UNCONFIGURED or FINALIZED.
103
133
*/
134
+ void error ();
104
135
virtual void onError ();
136
+ void doError (bool success);
137
+
138
+ /* *
139
+ * @brief Function to be defined by the user.
140
+ * Called at the end of transition from INACTIVE to FINALIZED.
141
+ */
142
+ void shutdown ();
143
+ virtual void onShutdown ();
144
+ void doShutdown (bool success);
105
145
106
146
virtual void addStatistics (diagnostic_updater::DiagnosticStatusWrapper& dsw);
107
147
virtual void heartbeatCB (const ros::TimerEvent& event);
148
+ void sendNodeUpdate ();
149
+ void lifecycleCB (const brain_box_msgs::LifeCycleCommand::ConstPtr msg);
150
+
151
+ LifeCycleState getState () const ;
152
+ LifeCycleStatus getStatus () const ;
153
+ void setStatus (const LifeCycleStatus status);
154
+ double getThrottleS () const ;
155
+ void setThrottleS (const double throttleS);
108
156
109
157
}; // class AMLifeCycle
110
158
0 commit comments