|
| 1 | +#ifndef RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_ |
| 2 | +#define RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_ |
| 3 | + |
| 4 | +// Standard library includes |
| 5 | +#include <functional> |
| 6 | +#include <utility> |
| 7 | +#include <memory> |
| 8 | + |
| 9 | +// Additional ROS libraries needed |
| 10 | +#include "node.hpp" |
| 11 | +#include "rcl_interfaces/msg/describe_parameters.hpp" |
| 12 | +#include "rclcpp/node.hpp" |
| 13 | + |
| 14 | +namespace rclcpp |
| 15 | +{ |
| 16 | + |
| 17 | +// Implments ParameterDesription class with builder design pattern |
| 18 | +class ParameterDescription |
| 19 | +{ |
| 20 | +public: |
| 21 | + // List of classes the builder manages |
| 22 | + class FloatingPointDescription; |
| 23 | + |
| 24 | + // Two constructors in case certain methods don't need to declare_parameters with a Type T in the form of a template |
| 25 | + ParameterDescription(std::string name, std::uint8_t type, std::string description, std::string additional_constraints, bool read_only. bool dynamic_typing) : m_name{name}, parameter_descriptor.type{type}, m_description{description}, m_additional_constraints{additional_constraints}, read_only{read_only}, dyanmic_typing{m_dyanmic_typing}{}; |
| 26 | + |
| 27 | +private: |
| 28 | + // The main descriptor object we're meant to adjust |
| 29 | + rcl_interfaces::msg::ParameterDescriptor parameter_descriptor = {}; |
| 30 | + |
| 31 | + // Copies all the information in ParameterDescriptor.msg - https://github.com/ros2/rcl_interfaces/blob/rolling/rcl_interfaces/msg/ParameterDescriptor.msg |
| 32 | + std::string m_name; |
| 33 | + std::string m_description; |
| 34 | + |
| 35 | + // Parameter Constraints |
| 36 | + std::string m_additional_constraints; |
| 37 | + bool m_read_only; |
| 38 | + bool m_dynamic_typing; |
| 39 | + |
| 40 | +}; |
| 41 | + |
| 42 | +class ParameterDescription::FloatingPointDescription |
| 43 | +{ |
| 44 | +public: |
| 45 | + // Our Main build methods which will construct the base class |
| 46 | + ParameterDescription build() const; |
| 47 | + |
| 48 | + //Builder Method - Mains |
| 49 | + FloatingPointDescription& SetName(std::string name); |
| 50 | + FloatingPointDescription& SetType(std::uint8_t type); |
| 51 | + FloatingPointDescription& SetDescription(std::string description); |
| 52 | + FloatingPointDescription& SetAdditionalConstraints(std::string constraints); |
| 53 | + FloatingPointDescription& SetReadOnly(bool read_only); |
| 54 | + FloatingPointDescription& SetDynamicTyping(bool dynamic_typing); |
| 55 | + |
| 56 | + // Need the current node in order to begin the configuraiton state forit via the declare_parameter function which setups up the Node |
| 57 | + template<typename ParameterType> |
| 58 | + FloatingPointDescription& DeclareParameter<ParameterType>(ParameterType default_value, std::shared_ptr<rclcpp::Node> required_node) |
| 59 | +{ |
| 60 | + required_node->declare_parameter<ParameterType>(m_name, default_value, parameter_descriptor); |
| 61 | + return *this; |
| 62 | +} |
| 63 | + // Extended build methods specific to this class |
| 64 | + FloatingPointDescription& SetMin(float min); |
| 65 | + FloatingPointDescription& SetMax(float max); |
| 66 | + FloatingPointDescription& SetStep(float step); |
| 67 | + |
| 68 | + // Simplification Method - Outside of the base clss that the user should be able to set up easily, they should then be able to call a function which setups up the specifics for this class (The floating point parameter description) |
| 69 | + // Here we will have a difference between generic types and templated types |
| 70 | + FloatingPointDescription& SetFloatingPointDescription(float min, float max, float step); |
| 71 | + // We will again need access to the current development node to declare its parameters |
| 72 | + template<typename ParameterType> |
| 73 | + FloatingPointDescription& SetFloatingPointDescription(std::string name, ParameterType default_value, float min, float max, float step) |
| 74 | + { |
| 75 | + parameter_descriptor.floating_point_range.resize(1); |
| 76 | + parameter_descriptor.floating_point_range.at(0).from_value = min; |
| 77 | + parameter_descriptor.floating_point_range.at(0).to_value = max; |
| 78 | + parameter_descriptor.floating_point_range.at(0).step = step; |
| 79 | + |
| 80 | + return *this; |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | +private: |
| 85 | + rcl_interfaces::msg::ParameterDescriptor parameter_descriptor = {}; |
| 86 | + std::string m_name{""}; |
| 87 | + parameter_descriptor.type{rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET}; |
| 88 | + std::string m_description{""}; |
| 89 | + |
| 90 | + std::string m_additional_constraints{""}; |
| 91 | + bool m_read_only{false}; |
| 92 | + bool m_dynamic_typing{false}; |
| 93 | + |
| 94 | + // This is a floating point so we'll use floating points in the range |
| 95 | + float m_min{0.0f}; |
| 96 | + float m_max{1.0f}; |
| 97 | + float m_step{0.0f}; |
| 98 | +}; |
| 99 | + |
| 100 | +} // namespace rclcpp |
| 101 | + |
| 102 | +#endif // headerguards for parameter_descriptor |
0 commit comments