99// Additional ROS libraries needed
1010#include " node.hpp"
1111#include " rcl_interfaces/msg/describe_parameters.hpp"
12+ #include " rclcpp/callback_group.hpp"
13+ #include " rclcpp/context.hpp"
14+ #include " macros.hpp"
1215#include " rclcpp/node.hpp"
16+ #include " node_interfaces/node_base_interface.hpp"
17+ #include " node_interfaces/node_base.hpp"
18+ #include " rcl_interfaces/srv/list_parameters.hpp"
19+ #include " rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp"
1320
1421namespace rclcpp
1522{
@@ -33,11 +40,18 @@ class ParameterDescription
3340 ParameterDescription& SetReadOnly (bool read_only);
3441 ParameterDescription& SetDynamicTyping (bool dynamic_typing);
3542
36- // Need the current node in order to begin the configuraiton state forit via the declare_parameter function which setups up the Node
43+ // Need the current node in order to begin the configuraiton state for it via the declare_parameter function which setups up the Node
3744 template <typename ParameterType>
38- ParameterDescription& DeclareParameter<ParameterType> (ParameterType default_value, std::unique_ptr< rclcpp::Node> required_node )
45+ ParameterDescription& DeclareParameter (ParameterType default_value, rclcpp::Node::SharedPtr required_node_ptr )
3946{
40- required_node->declare_parameter <ParameterType>(m_name, default_value, parameter_descriptor);
47+ required_node_ptr->declare_parameter <ParameterType>(m_name, default_value, parameter_descriptor);
48+ return *this ;
49+ }
50+
51+ template <typename ParameterType>
52+ ParameterDescription& DeclareParameter (ParameterType default_value, rclcpp_lifecycle::LifecycleNode::SharedPtr required_node_ptr)
53+ {
54+ required_node_ptr->declare_parameter <ParameterType>(m_name, default_value, parameter_descriptor);
4155 return *this ;
4256}
4357
@@ -47,7 +61,21 @@ class ParameterDescription
4761 ParameterDescription& SetFloatingPointDescriptionRange (float min = 0 .0f , float max = 1 .0f , float step = 0 .0f );
4862 // We will again need access to the current development node to declare its parameters
4963 template <typename ParameterType>
50- ParameterDescription& SetFloatingPointDescriptionRange (std::unique_ptr<rclcpp::Node> currentNode, const std::string& name, ParameterType default_value, float min = 0 .0f , float max = 1 .0f , float step = 0 .0f )
64+ ParameterDescription& SetFloatingPointDescriptionRange (rclcpp::Node::SharedPtr currentNode, const std::string& name, ParameterType default_value, float min = 0 .0f , float max = 1 .0f , float step = 0 .0f )
65+ {
66+ parameter_descriptor.floating_point_range .resize (1 );
67+ parameter_descriptor.floating_point_range .at (0 ).from_value = min;
68+ parameter_descriptor.floating_point_range .at (0 ).to_value = max;
69+ parameter_descriptor.floating_point_range .at (0 ).step = step;
70+
71+ // For this version of the function we can outright declare the parameters using the specified type
72+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
73+
74+ return *this ;
75+ }
76+
77+ template <typename ParameterType>
78+ ParameterDescription& SetFloatingPointDescriptionRange (rclcpp_lifecycle::LifecycleNode::SharedPtr currentNode, const std::string& name, ParameterType default_value, float min = 0 .0f , float max = 1 .0f , float step = 0 .0f )
5179 {
5280 parameter_descriptor.floating_point_range .resize (1 );
5381 parameter_descriptor.floating_point_range .at (0 ).from_value = min;
@@ -63,7 +91,7 @@ class ParameterDescription
6391 ParameterDescription& SetIntegerDescriptionRange (int min = 0 , int max = 1 , int step = 0 );
6492 // We will again need access to the current development node to declare its parameters
6593 template <typename ParameterType>
66- ParameterDescription& SetIntegerDescriptionRange (std::unique_ptr< rclcpp::Node> currentNode, const std::string& name, ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
94+ ParameterDescription& SetIntegerDescriptionRange (rclcpp::Node::SharedPtr currentNode, const std::string& name, ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
6795 {
6896 parameter_descriptor.integer_range .resize (1 );
6997 parameter_descriptor.integer_range .at (0 ).from_value = min;
@@ -76,15 +104,20 @@ class ParameterDescription
76104 return *this ;
77105 }
78106
79- // Extended build methods specific to the ranges, but with overloaded versions
80- ParameterDescription& SetMin (float min);
81- ParameterDescription& SetMax (float max);
82- ParameterDescription& SetStep (float step);
107+ // We will again need access to the current development node to declare its parameters
108+ template <typename ParameterType>
109+ ParameterDescription& SetIntegerDescriptionRange (rclcpp_lifecycle::LifecycleNode currentNode, const std::string& name, ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
110+ {
111+ parameter_descriptor.integer_range .resize (1 );
112+ parameter_descriptor.integer_range .at (0 ).from_value = min;
113+ parameter_descriptor.integer_range .at (0 ).to_value = max;
114+ parameter_descriptor.integer_range .at (0 ).step = step;
83115
84- ParameterDescription& SetMin (int min);
85- ParameterDescription& SetMax (int max);
86- ParameterDescription& SetStep (int step);
116+ // For this version of the function we can outright declare the parameters using the specified type
117+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
87118
119+ return *this ;
120+ }
88121private:
89122 // The main descriptor object we're meant to initialize and adjust
90123 rcl_interfaces::msg::ParameterDescriptor parameter_descriptor = {};
@@ -99,15 +132,6 @@ class ParameterDescription
99132 bool m_read_only;
100133 bool m_dynamic_typing;
101134
102- // This is a floating point so we'll use floating points in the range
103- float m_min_float {0 .0f };
104- float m_max_float {1 .0f };
105- float m_step_float {0 .0f };
106-
107- // Now here is the integer version so we'll use ints in the range
108- int m_min_int {0 };
109- int m_max_int {1 };
110- int m_step_int {0 };
111135};
112136
113137} // namespace rclcpp
0 commit comments