Skip to content

Commit 712c057

Browse files
galouGaël Écorchard
and
Gaël Écorchard
authored
Exit earlier on failure in generatePlan (#2726)
With this change, the `PlanningPipeline::generatePlan()` exits as soon as a failure is detected. Before this, `break` was used to exit the current loop of request adapters, planners, or response adapters, but the function continued to the next loop. For example, if a planner would fail, the response adapters would still be executed. Signed-off-by: Gaël Écorchard <gael@km-robotics.cz> Co-authored-by: Gaël Écorchard <gael@km-robotics.cz>
1 parent 5887eb0 commit 712c057

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

moveit_ros/planning/planning_pipeline/src/planning_pipeline.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ bool PlanningPipeline::generatePlan(const planning_scene::PlanningSceneConstPtr&
286286
RCLCPP_ERROR(node_->get_logger(),
287287
"PlanningRequestAdapter '%s' failed, because '%s'. Aborting planning pipeline.",
288288
req_adapter->getDescription().c_str(), status.message.c_str());
289-
break;
289+
active_ = false;
290+
return false;
290291
}
291292
}
292293

@@ -309,7 +310,8 @@ bool PlanningPipeline::generatePlan(const planning_scene::PlanningSceneConstPtr&
309310
"Failed to create PlanningContext for planner '%s'. Aborting planning pipeline.",
310311
planner->getDescription().c_str());
311312
res.error_code = moveit::core::MoveItErrorCode::PLANNING_FAILED;
312-
break;
313+
active_ = false;
314+
return false;
313315
}
314316

315317
// Run planner
@@ -320,8 +322,10 @@ bool PlanningPipeline::generatePlan(const planning_scene::PlanningSceneConstPtr&
320322
// If planner does not succeed, break chain and return false
321323
if (!res.error_code)
322324
{
323-
RCLCPP_ERROR(node_->get_logger(), "Planner '%s' failed", planner->getDescription().c_str());
324-
break;
325+
RCLCPP_ERROR(node_->get_logger(), "Planner '%s' failed with error code %s", planner->getDescription().c_str(),
326+
errorCodeToString(res.error_code).c_str());
327+
active_ = false;
328+
return false;
325329
}
326330
}
327331

@@ -338,9 +342,10 @@ bool PlanningPipeline::generatePlan(const planning_scene::PlanningSceneConstPtr&
338342
// If adapter does not succeed, break chain and return false
339343
if (!res.error_code)
340344
{
341-
RCLCPP_ERROR(node_->get_logger(), "PlanningResponseAdapter '%s' failed",
342-
res_adapter->getDescription().c_str());
343-
break;
345+
RCLCPP_ERROR(node_->get_logger(), "PlanningResponseAdapter '%s' failed with error code %s",
346+
res_adapter->getDescription().c_str(), errorCodeToString(res.error_code).c_str());
347+
active_ = false;
348+
return false;
344349
}
345350
}
346351
}
@@ -365,7 +370,7 @@ bool PlanningPipeline::generatePlan(const planning_scene::PlanningSceneConstPtr&
365370

366371
// Set planning pipeline to inactive
367372
active_ = false;
368-
return bool(res);
373+
return static_cast<bool>(res);
369374
}
370375

371376
void PlanningPipeline::terminate() const

0 commit comments

Comments
 (0)