Skip to content

Commit 5d3f2d6

Browse files
author
Aaron Roller
committed
fix: avoid status change when in error AM-695/error-methods
1 parent 8647d34 commit 5d3f2d6

4 files changed

Lines changed: 50 additions & 30 deletions

File tree

include/super_lib/am_life_cycle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ class AMLifeCycle
193193
* */
194194
AMStatReset& configureHzStats(AMStatReset& stats);
195195

196+
/** Called periodically by a timer defaulting to 1 second.
197+
* Useful for checking health regularly, but not during
198+
* callbacks which can affect performance and be too granular
199+
*/
196200
virtual void heartbeatCB(const ros::TimerEvent& event);
197201

198202
void lifecycleCB(const brain_box_msgs::LifeCycleCommand::ConstPtr msg);

rostest/error_forced/error_forced_rostest.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ class LifeCycleErrorTest : public RostestBase, public am::AMLifeCycle
99
LifeCycleErrorTest() :
1010
RostestBase()
1111
{}
12+
13+
14+
void onConfigure()
15+
{
16+
//do nothing...stay in configure
17+
}
1218
};
1319

1420
TEST_F(LifeCycleErrorTest, testStatus_Error)
1521
{
16-
waitUntil(LifeCycleState::UNCONFIGURED);
22+
waitUntil(LifeCycleState::CONFIGURING,"3K3K");
1723
ASSERT_EQ(LifeCycleStatus::OK,getStatus());
18-
error("NNAQ",true);
19-
waitUntil(LifeCycleState::ERROR_PROCESSING);
24+
errorTerminal("forcing error during configuration", "NNAQ");
25+
waitUntil(LifeCycleState::ERROR_PROCESSING,"NAKW");
2026
waitUntil(LifeCycleStatus::ERROR,"IUIU");
2127
}
2228

src/am_super/am_super.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,37 +304,37 @@ class AMSuper : AMLifeCycle
304304
SuperNodeMediator::SuperNodeInfo& nr = it->second;
305305
if (!nr.online)
306306
{
307-
ROS_INFO_STREAM("manifested node '" << node_name << "' came online");
307+
ROS_INFO_STREAM("manifested node '" << node_name << "' came online [PGPG]");
308308
nr.online = true;
309309
nodes_changed = true;
310310
}
311311
if (nr.state != state)
312312
{
313-
ROS_INFO_STREAM(node_name << " changed state to = " << life_cycle_mediator_.stateToString(state));
313+
ROS_INFO_STREAM(node_name << " changed state to = " << life_cycle_mediator_.stateToString(state) << " [38S8]");
314314
nr.state = state;
315315
nodes_changed = true;
316316
}
317317
if (nr.status != status)
318318
{
319-
ROS_INFO_STREAM(node_name << " changed status to = " << life_cycle_mediator_.statusToString(status));
319+
ROS_INFO_STREAM(node_name << " changed status to = " << life_cycle_mediator_.statusToString(status) << " [09SI]");
320320
nr.status = status;
321321
nodes_changed = true;
322322
if(nr.manifested && nr.status == LifeCycleStatus::ERROR)
323323
{
324324
supervisor_.status_error = true;
325-
ROS_ERROR_STREAM("Manifested node " << nr.name << " changed status to ERROR. Shutting down nodes..");
325+
ROS_ERROR_STREAM("Manifested node " << nr.name << " changed status to ERROR. Shutting down nodes... [JHRE]");
326326
}
327327
}
328328
if (nr.pid != pid)
329329
{
330330
//process id = 0 observed to be a node coming online. -1 appears to be offline
331331
if(pid == 0)
332332
{
333-
ROS_INFO_STREAM(node_name << " process is alive");
333+
ROS_INFO_STREAM(node_name << " process is alive [UIRE]");
334334
}
335335
else
336336
{
337-
ROS_WARN_STREAM(node_name << " changed process id from: " << nr.pid << " to: " << pid);
337+
ROS_WARN_STREAM(node_name << " changed process id from: " << nr.pid << " to: " << pid << " [WNEW]");
338338
}
339339
nr.pid = pid;
340340
nodes_changed = true;

src/super_lib/am_life_cycle.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void AMLifeCycle::lifecycleCB(const brain_box_msgs::LifeCycleCommand::ConstPtr m
103103
configure();
104104
break;
105105
case LifeCycleCommand::CREATE:
106-
ROS_WARN_STREAM("illegal command " << life_cycle_mediator_.commandToString(LifeCycleCommand::CREATE));
106+
ROS_WARN_STREAM("illegal command " << life_cycle_mediator_.commandToString(LifeCycleCommand::CREATE) << " [7YT8]");
107107
break;
108108
case LifeCycleCommand::DEACTIVATE:
109109
transition("deactivate", LifeCycleState::ACTIVE, LifeCycleState::DEACTIVATING, LifeCycleState::INACTIVE,
@@ -124,17 +124,17 @@ void AMLifeCycle::transition(std::string transition_name, LifeCycleState initial
124124
{
125125
if (life_cycle_info_.state == initial_state)
126126
{
127-
ROS_INFO_STREAM(transition_name << ", current state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state));
127+
ROS_INFO_STREAM(transition_name << ", current state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << " [ASWU]");
128128
setState(transition_state);
129129
on_function();
130130
}
131131
else if (life_cycle_info_.state == transition_state || life_cycle_info_.state == final_state)
132132
{
133-
ROS_DEBUG_STREAM("ignoring redundant " << transition_name);
133+
ROS_DEBUG_STREAM("ignoring redundant " << transition_name << " [0393]");
134134
}
135135
else
136136
{
137-
ROS_WARN_STREAM("received illegal " << transition_name << " in state " << life_cycle_mediator_.stateToString(life_cycle_info_.state));
137+
ROS_WARN_STREAM("received illegal " << transition_name << " in state " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << " [JGV5]");
138138
}
139139
}
140140

@@ -237,12 +237,12 @@ void AMLifeCycle::destroy()
237237
{
238238
if (life_cycle_mediator_.illegalDestroy(life_cycle_info_))
239239
{
240-
ROS_INFO_STREAM("received illegal activate in state " << life_cycle_mediator_.stateToString(life_cycle_info_.state));
240+
ROS_INFO_STREAM("received illegal activate in state " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << " [45RT]");
241241
}
242242
/* This condition is hit only if state equals FINALIZED. Checking SHUTTING_DOWN is redundant */
243243
else
244244
{
245-
ROS_INFO_STREAM("current state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state));
245+
ROS_INFO_STREAM("current state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << " [RE45]");
246246
onDestroy();
247247
}
248248
}
@@ -281,22 +281,29 @@ void AMLifeCycle::error(std::string error_code, bool forced)
281281

282282
void AMLifeCycle::error(std::string message, std::string error_code, bool forced)
283283
{
284-
std::string error_code_message = " [" + error_code + "] ";
285-
if (!forced && life_cycle_mediator_.redundantError(life_cycle_info_))
286-
{
287-
ROS_WARN_STREAM("Error called again, but previously reported." << error_code_message);
288-
}
289-
else if(!forced && withinConfigureTolerance())
284+
std::string error_code_message = " Error[" + error_code + "] ";
285+
if(withinConfigureTolerance() && !forced)
290286
{
291-
ROS_WARN_STREAM_THROTTLE(throttle_info_.warn_throttle_s,"Ignoring" << error_code_message << " during configure tolerance of " << configure_tolerance_s << " seconds [GFRT]");
287+
ROS_WARN_STREAM_THROTTLE(throttle_info_.warn_throttle_s,"Ignoring tolerant error for (" << configure_tolerance_s << "s) `" << message << "` " << error_code_message << "[GFRT]");
292288
}
293289
else
294290
{
295-
std::string forced_prefix = forced?"Terminal ":"";
296-
ROS_ERROR_STREAM(message << " state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << error_code_message << " [R45Y]" );
297-
setState(LifeCycleState::ERROR_PROCESSING);
298-
setStatus(LifeCycleStatus::ERROR);
299-
onError();
291+
std::string forced_prefix = forced?"Terminal ":"";
292+
std::string repeat_prefix = "";
293+
294+
//only change the state if
295+
if(!life_cycle_mediator_.redundantError(life_cycle_info_))
296+
{
297+
setState(LifeCycleState::ERROR_PROCESSING);
298+
setStatus(LifeCycleStatus::ERROR);
299+
onError();
300+
}
301+
else
302+
{
303+
repeat_prefix = "Repeated ";
304+
}
305+
std::string error_explanation=forced_prefix + repeat_prefix + error_code_message;
306+
ROS_ERROR_STREAM(message << " state: " << life_cycle_mediator_.stateToString(life_cycle_info_.state) << error_explanation << " [R45Y]" );
300307
}
301308
}
302309

@@ -371,7 +378,11 @@ void AMLifeCycle::addStatistics(diagnostic_updater::DiagnosticStatusWrapper& dsw
371378
}
372379
else
373380
{
374-
setStatus(status);
381+
//only report status if not already errored
382+
if(!life_cycle_mediator_.redundantError(life_cycle_info_))
383+
{
384+
setStatus(status);
385+
}
375386

376387
//configuring is a special case where tolerance for errors is allowed
377388
if(getState() == LifeCycleState::CONFIGURING)
@@ -495,9 +506,8 @@ bool AMLifeCycle::setStatus(const LifeCycleStatus status)
495506
//if we are in error and want to leave it
496507
if(life_cycle_info_.status == LifeCycleStatus::ERROR && status != LifeCycleStatus::ERROR)
497508
{
498-
ROS_WARN_STREAM_THROTTLE(getThrottle(), "requested to change status from ERROR to " << life_cycle_mediator_.statusToString(status));
509+
ROS_WARN_STREAM_THROTTLE(getThrottle(), "requested to change status from ERROR to " << life_cycle_mediator_.statusToString(status) << " [DFRE]");
499510
}
500-
501511
else if (life_cycle_mediator_.setStatus(status, life_cycle_info_))
502512
{
503513
sendNodeUpdate();

0 commit comments

Comments
 (0)