1+ // Copyright 2023 Open Source Robotics Foundation, Inc.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
115#ifndef RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
216#define RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
317
418// Standard library includes
519#include < functional>
620#include < utility>
721#include < memory>
22+ #include < string>
823
924// Additional ROS libraries needed
1025#include " rcl_interfaces/msg/list_parameters_result.hpp"
@@ -27,103 +42,121 @@ namespace rclcpp
2742class ParameterDescription
2843{
2944public:
30- // List of classes the builder manages
31- ParameterDescription ();
32-
33- // Our Main build methods which will construct the base class
34- rcl_interfaces::msg::ParameterDescriptor build () const ;
35-
36- // Builder Methods - Describes the instances in a parameter_descriptionobject
37- ParameterDescription& SetName (const std::string& name);
38- ParameterDescription& SetType (std::uint8_t type);
39- ParameterDescription& SetDescriptionText (const std::string& description);
40- ParameterDescription& SetAdditionalConstraints (const std::string& constraints);
41- ParameterDescription& SetReadOnly (bool read_only);
42- ParameterDescription& SetDynamicTyping (bool dynamic_typing);
43-
44- // Need the current node in order to begin the configuraiton state for it via the declare_parameter function which setups up the Node
45- template <typename ParameterType>
46- ParameterDescription& DeclareParameter (ParameterType default_value, rclcpp::Node::SharedPtr required_node_ptr)
45+ // List of classes the builder manages
46+ ParameterDescription ();
47+
48+ // Our Main build methods which will construct the base class
49+ rcl_interfaces::msg::ParameterDescriptor build () const ;
50+
51+ // Builder Methods:
52+ // Describes the instances in a parameter_description object
53+ ParameterDescription& SetName (const std::string& name);
54+ ParameterDescription& SetType (std::uint8_t type);
55+ ParameterDescription& SetDescriptionText (const std::string& description);
56+ ParameterDescription& SetAdditionalConstraints (const std::string& constraints);
57+ ParameterDescription& SetReadOnly (bool read_only);
58+ ParameterDescription& SetDynamicTyping (bool dynamic_typing);
59+
60+ // Need the current node in order to begin the configuration state
61+ // for it via the declare_parameter function which setups the Node
62+ template <typename ParameterType>
63+ ParameterDescription&
64+ DeclareParameter (ParameterType default_value, rclcpp::Node::SharedPtr required_node_ptr)
65+ {
66+ required_node_ptr->declare_parameter <ParameterType>(parameter_descriptor.name , default_value, parameter_descriptor);
67+ return *this ;
68+ }
69+
70+ template <typename ParameterType>
71+ ParameterDescription& DeclareParameter
72+ (ParameterType default_value,
73+ rclcpp_lifecycle::LifecycleNode::SharedPtr required_node_ptr)
74+ {
75+ required_node_ptr->declare_parameter <ParameterType>
76+ (parameter_descriptor.name , default_value, parameter_descriptor);
77+ return *this ;
78+ }
79+
80+ // Simplification Methods:
81+ // The user should be able to set up ranges easily, they should then be able to call a function
82+ // this function sets up the specifics for this class
83+ // Here we will have a difference between generic types and templated types
84+ ParameterDescription& SetFloatingPointDescriptionRange
85+ (float min = 0 .0f , float max = 1 .0f , float step = 0 .0f );
86+ // We will again need access to the current development node to declare its parameters
87+ template <typename ParameterType>
88+ ParameterDescription& SetFloatingPointDescriptionRange
89+ (rclcpp::Node::SharedPtr currentNode, const std::string& name,
90+ ParameterType default_value, float min = 0 .0f ,
91+ float max = 1 .0f , float step = 0 .0f )
92+ {
93+ parameter_descriptor.floating_point_range .resize (1 );
94+ parameter_descriptor.floating_point_range .at (0 ).from_value = min;
95+ parameter_descriptor.floating_point_range .at (0 ).to_value = max;
96+ parameter_descriptor.floating_point_range .at (0 ).step = step;
97+
98+ // For this function we can outright declare the parameters using the specified type
99+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
100+
101+ return *this ;
102+ }
103+
104+ template <typename ParameterType>
105+ ParameterDescription& SetFloatingPointDescriptionRange
106+ (rclcpp_lifecycle::LifecycleNode::SharedPtr currentNode,
107+ const std::string& name, ParameterType default_value,
108+ float min = 0 .0f , float max = 1 .0f , float step = 0 .0f )
47109{
48- required_node_ptr->declare_parameter <ParameterType>(m_name, default_value, parameter_descriptor);
49- return *this ;
110+ parameter_descriptor.floating_point_range .resize (1 );
111+ parameter_descriptor.floating_point_range .at (0 ).from_value = min;
112+ parameter_descriptor.floating_point_range .at (0 ).to_value = max;
113+ parameter_descriptor.floating_point_range .at (0 ).step = step;
114+
115+ // For this function we can outright declare the parameters using the specified type
116+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
117+
118+ return *this ;
50119}
51120
52- template <typename ParameterType>
53- ParameterDescription& DeclareParameter (ParameterType default_value, rclcpp_lifecycle::LifecycleNode::SharedPtr required_node_ptr)
121+ ParameterDescription& SetIntegerDescriptionRange (int min = 0 , int max = 1 , int step = 0 );
122+ // We will again need access to the current development node to declare its parameters
123+ template <typename ParameterType>
124+ ParameterDescription& SetIntegerDescriptionRange
125+ (rclcpp::Node::SharedPtr currentNode, const std::string& name,
126+ ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
54127{
55- required_node_ptr->declare_parameter <ParameterType>(m_name, default_value, parameter_descriptor);
56- return *this ;
128+ parameter_descriptor.integer_range .resize (1 );
129+ parameter_descriptor.integer_range .at (0 ).from_value = min;
130+ parameter_descriptor.integer_range .at (0 ).to_value = max;
131+ parameter_descriptor.integer_range .at (0 ).step = step;
132+
133+ // For this version of the function we can outright declare the parameters using the specified type
134+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
135+
136+ return *this ;
57137}
58138
59- // Simplification Methods - The user should be able to set up ranges easily, they should then be able to call a function which sets up the specifics for this class (The floating point range for parameter description)
60- // Here we will have a difference between generic types and templated types
61- // Also we can use default values for min, max, and float. The other option is to utilize SetMin methods and similar and check if we have a range, if not, then we should resize one
62- ParameterDescription& SetFloatingPointDescriptionRange (float min = 0 .0f , float max = 1 .0f , float step = 0 .0f );
63- // We will again need access to the current development node to declare its parameters
64- template <typename ParameterType>
65- 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 )
66- {
67- parameter_descriptor.floating_point_range .resize (1 );
68- parameter_descriptor.floating_point_range .at (0 ).from_value = min;
69- parameter_descriptor.floating_point_range .at (0 ).to_value = max;
70- parameter_descriptor.floating_point_range .at (0 ).step = step;
71-
72- // For this version of the function we can outright declare the parameters using the specified type
73- currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
74-
75- return *this ;
76- }
77-
78- template <typename ParameterType>
79- 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 )
80- {
81- parameter_descriptor.floating_point_range .resize (1 );
82- parameter_descriptor.floating_point_range .at (0 ).from_value = min;
83- parameter_descriptor.floating_point_range .at (0 ).to_value = max;
84- parameter_descriptor.floating_point_range .at (0 ).step = step;
85-
86- // For this version of the function we can outright declare the parameters using the specified type
87- currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
88-
89- return *this ;
90- }
91-
92- ParameterDescription& SetIntegerDescriptionRange (int min = 0 , int max = 1 , int step = 0 );
93- // We will again need access to the current development node to declare its parameters
94- template <typename ParameterType>
95- ParameterDescription& SetIntegerDescriptionRange (rclcpp::Node::SharedPtr currentNode, const std::string& name, ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
96- {
97- parameter_descriptor.integer_range .resize (1 );
98- parameter_descriptor.integer_range .at (0 ).from_value = min;
99- parameter_descriptor.integer_range .at (0 ).to_value = max;
100- parameter_descriptor.integer_range .at (0 ).step = step;
101-
102- // For this version of the function we can outright declare the parameters using the specified type
103- currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
104-
105- return *this ;
106- }
107-
108- // We will again need access to the current development node to declare its parameters
109- template <typename ParameterType>
110- ParameterDescription& SetIntegerDescriptionRange (rclcpp_lifecycle::LifecycleNode currentNode, const std::string& name, ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
111- {
112- parameter_descriptor.integer_range .resize (1 );
113- parameter_descriptor.integer_range .at (0 ).from_value = min;
114- parameter_descriptor.integer_range .at (0 ).to_value = max;
115- parameter_descriptor.integer_range .at (0 ).step = step;
116-
117- // For this version of the function we can outright declare the parameters using the specified type
118- currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
119-
120- return *this ;
121- }
139+ // We will again need access to the current development node to declare its parameters
140+ template <typename ParameterType>
141+ ParameterDescription& SetIntegerDescriptionRange
142+ (rclcpp_lifecycle::LifecycleNode currentNode, const std::string& name,
143+ ParameterType default_value, int min = 0 , int max = 1 , int step = 0 )
144+ {
145+ parameter_descriptor.integer_range .resize (1 );
146+ parameter_descriptor.integer_range .at (0 ).from_value = min;
147+ parameter_descriptor.integer_range .at (0 ).to_value = max;
148+ parameter_descriptor.integer_range .at (0 ).step = step;
149+
150+ // For this function we can outright declare the parameters using the specified type
151+ currentNode->declare_parameter <ParameterType>(name, default_value, parameter_descriptor);
152+
153+ return *this ;
154+ }
122155private:
123- // The main descriptor object we're meant to initialize and adjust
124- rcl_interfaces::msg::ParameterDescriptor parameter_descriptor = {};
156+ // The main descriptor object we're meant to initialize and adjust
157+ rcl_interfaces::msg::ParameterDescriptor parameter_descriptor = {};
125158};
126159
127- } // namespace rclcpp
160+ } // namespace rclcpp
128161
129- #endif // headerguards for parameter_descriptor
162+ #endif // RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
0 commit comments