15 #ifndef NAV2_UTIL__LIFECYCLE_NODE_HPP_
16 #define NAV2_UTIL__LIFECYCLE_NODE_HPP_
22 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
23 #include "nav2_util/node_thread.hpp"
24 #include "rclcpp_lifecycle/lifecycle_node.hpp"
25 #include "rclcpp/rclcpp.hpp"
26 #include "bondcpp/bond.hpp"
27 #include "bond/msg/constants.hpp"
32 using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
48 const std::string & node_name,
49 const std::string & ns =
"",
50 const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
76 const std::string & name,
const rclcpp::ParameterValue & default_value,
77 const std::string & description =
"",
const std::string & additional_constraints =
"",
78 bool read_only =
false)
80 auto descriptor = rcl_interfaces::msg::ParameterDescriptor();
82 descriptor.name = name;
83 descriptor.description = description;
84 descriptor.additional_constraints = additional_constraints;
85 descriptor.read_only = read_only;
87 declare_parameter(descriptor.name, default_value, descriptor);
100 const std::string & name,
const rclcpp::ParameterValue & default_value,
102 const std::string & description =
"",
const std::string & additional_constraints =
"",
103 bool read_only =
false)
105 auto descriptor = rcl_interfaces::msg::ParameterDescriptor();
107 descriptor.name = name;
108 descriptor.description = description;
109 descriptor.additional_constraints = additional_constraints;
110 descriptor.read_only = read_only;
111 descriptor.floating_point_range.resize(1);
112 descriptor.floating_point_range[0].from_value = fp_range.from_value;
113 descriptor.floating_point_range[0].to_value = fp_range.to_value;
114 descriptor.floating_point_range[0].step = fp_range.step;
116 declare_parameter(descriptor.name, default_value, descriptor);
129 const std::string & name,
const rclcpp::ParameterValue & default_value,
131 const std::string & description =
"",
const std::string & additional_constraints =
"",
132 bool read_only =
false)
134 auto descriptor = rcl_interfaces::msg::ParameterDescriptor();
136 descriptor.name = name;
137 descriptor.description = description;
138 descriptor.additional_constraints = additional_constraints;
139 descriptor.read_only = read_only;
140 descriptor.integer_range.resize(1);
141 descriptor.integer_range[0].from_value = int_range.from_value;
142 descriptor.integer_range[0].to_value = int_range.to_value;
143 descriptor.integer_range[0].step = int_range.step;
145 declare_parameter(descriptor.name, default_value, descriptor);
153 return std::static_pointer_cast<nav2_util::LifecycleNode>(
154 rclcpp_lifecycle::LifecycleNode::shared_from_this());
163 nav2_util::CallbackReturn
on_error(
const rclcpp_lifecycle::State & )
167 "Lifecycle node %s does not have error state implemented", get_name());
168 return nav2_util::CallbackReturn::SUCCESS;
205 std::unique_ptr<rclcpp::PreShutdownCallbackHandle> rcl_preshutdown_cb_handle_{
nullptr};
213 std::unique_ptr<bond::Bond> bond_{
nullptr};
214 double bond_heartbeat_period;
215 rclcpp::TimerBase::SharedPtr autostart_timer_;
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
void register_rcl_preshutdown_callback()
void autostart()
Automatically configure and active the node.
void add_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const floating_point_range fp_range, const std::string &description="", const std::string &additional_constraints="", bool read_only=false)
Declare a parameter that has a floating point range constraint.
void add_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const std::string &description="", const std::string &additional_constraints="", bool read_only=false)
Declare a parameter that has no integer or floating point range constraints.
void add_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const integer_range int_range, const std::string &description="", const std::string &additional_constraints="", bool read_only=false)
Declare a parameter that has an integer range constraint.
LifecycleNode(const std::string &node_name, const std::string &ns="", const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
A lifecycle node constructor.
void printLifecycleNodeNotification()
Print notifications for lifecycle node.
nav2_util::CallbackReturn on_error(const rclcpp_lifecycle::State &)
Abstracted on_error state transition callback, since unimplemented as of 2020 in the managed ROS2 nod...
std::shared_ptr< nav2_util::LifecycleNode > shared_from_this()
Get a shared pointer of this.
virtual void on_rcl_preshutdown()
Perform preshutdown activities before our Context is shutdown. Note that this is related to our Conte...
void createBond()
Create bond connection to lifecycle manager.
void destroyBond()
Destroy bond connection to lifecycle manager.