Skip to content

Commit c703c9e

Browse files
committed
Changing Node State
Signed-off-by: CursedRock17 <[email protected]>
1 parent 474e461 commit c703c9e

File tree

2 files changed

+46
-58
lines changed

2 files changed

+46
-58
lines changed

rclcpp/include/rclcpp/parameter_descriptor_wrapper.hpp

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
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

1421
namespace 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+
}
88121
private:
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

rclcpp/src/rclcpp/parameter_descriptor_wrapper.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ParameterDescription::ParameterDescription(){}
1313
// First the build methods to connect to the base class in the builder
1414
ParameterDescription ParameterDescription::build() const
1515
{
16+
// Return some some sort message
1617
return ParameterDescription(m_name, parameter_descriptor.type, m_description, m_additional_constraints, m_read_only, m_dynamic_typing)
1718
}
1819

@@ -54,43 +55,6 @@ ParameterDescription& ParameterDescription::SetDynamicTyping(bool dynamic_typing
5455
return *this;
5556
}
5657

57-
// These are the extension for this class that don't have access in the main class so we'll initialize here
58-
ParameterDescription& ParameterDescription::SetMin(float min)
59-
{
60-
m_min_float = min;
61-
return *this;
62-
}
63-
64-
ParameterDescription& ParameterDescription::SetMax(float max)
65-
{
66-
m_max_float = max;
67-
return *this;
68-
}
69-
70-
ParameterDescription& ParameterDescription::SetStep(float step)
71-
{
72-
m_step_float = step;
73-
return *this;
74-
}
75-
76-
ParameterDescription& ParameterDescription::SetMin(int min)
77-
{
78-
m_min_int = min;
79-
return *this;
80-
}
81-
82-
ParameterDescription& ParameterDescription::SetMax(int max)
83-
{
84-
m_max_int = max;
85-
return *this;
86-
}
87-
88-
ParameterDescription& ParameterDescription::SetStep(int step)
89-
{
90-
m_step_int = step;
91-
return *this;
92-
}
93-
9458
// Here is the Specific range function for this parameter description
9559
ParameterDescription& ParameterDescription::SetFloatingPointDescriptionRange(float min, float max, float step)
9660
{

0 commit comments

Comments
 (0)