Skip to content

Commit 3cc8bdf

Browse files
thebyohazardthebyohazard
authored andcommitted
Add raise_error function to lifecycle nodeso a node can self-transition to errorProcessing
Signed-off-by: thebyohazard <[email protected]>
1 parent d62fce3 commit 3cc8bdf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface,
613613
const State &
614614
deactivate(LifecycleNodeInterface::CallbackReturn & cb_return_code);
615615

616+
RCLCPP_LIFECYCLE_PUBLIC
617+
const State &
618+
raise_error();
619+
620+
RCLCPP_LIFECYCLE_PUBLIC
621+
const State &
622+
raise_error(LifecycleNodeInterface::CallbackReturn & cb_return_code);
623+
616624
RCLCPP_LIFECYCLE_PUBLIC
617625
const State &
618626
shutdown();

rclcpp_lifecycle/src/lifecycle_node.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,28 @@ LifecycleNode::deactivate(LifecycleNodeInterface::CallbackReturn & cb_return_cod
555555
lifecycle_msgs::msg::Transition::TRANSITION_DEACTIVATE, cb_return_code);
556556
}
557557

558+
const State &
559+
LifecycleNode::raise_error()
560+
{
561+
if(get_current_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
562+
return impl_->trigger_transition(
563+
lifecycle_msgs::msg::Transition::TRANSITION_ACTIVE_ERROR);
564+
else
565+
return impl_->trigger_transition(
566+
lifecycle_msgs::msg::Transition::TRANSITION_INACTIVE_ERROR);
567+
}
568+
569+
const State &
570+
LifecycleNode::raise_error(LifecycleNodeInterface::CallbackReturn & cb_return_code)
571+
{
572+
if(get_current_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
573+
return impl_->trigger_transition(
574+
lifecycle_msgs::msg::Transition::TRANSITION_ACTIVE_ERROR, cb_return_code);
575+
else
576+
return impl_->trigger_transition(
577+
lifecycle_msgs::msg::Transition::TRANSITION_INACTIVE_ERROR, cb_return_code);
578+
}
579+
558580
const State &
559581
LifecycleNode::shutdown()
560582
{

0 commit comments

Comments
 (0)