ROS 2 rclcpp + rcl - lyrical  lyrical
ROS 2 C++ Client Library with ROS Client Library
parameter_descriptor_wrapper.cpp
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 
15 #include "rclcpp/parameter_descriptor_wrapper.hpp"
16 
17 namespace rclcpp
18 {
19 
20 ParameterDescription::ParameterDescription()
21 {
22  // Need to set this in the constructor, but it doesn't necessarily need to be used
23  parameter_descriptor.type = rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET;
24 }
25 
26 rcl_interfaces::msg::ParameterDescriptor ParameterDescription::build() const
27 {
28  // Return some some sort message
29  return parameter_descriptor;
30 }
31 
32 // Builder methods which set up the original class
33 // They all follow the same format of initing the value given within the base class
34 // then returning the current class
35 ParameterDescription & ParameterDescription::set_name(const std::string & name)
36 {
37  parameter_descriptor.name = name;
38  return *this;
39 }
40 
41 ParameterDescription & ParameterDescription::set_type(std::uint8_t type)
42 {
43  parameter_descriptor.type = type;
44  return *this;
45 }
46 
47 ParameterDescription & ParameterDescription::set_description_text(const std::string & description)
48 {
49  parameter_descriptor.description = description;
50  return *this;
51 }
52 
53 ParameterDescription & ParameterDescription::set_additional_constraints(
54  const std::string & constraints)
55 {
56  parameter_descriptor.additional_constraints = constraints;
57  return *this;
58 }
59 
60 ParameterDescription & ParameterDescription::set_read_only(bool read_only)
61 {
62  parameter_descriptor.read_only = read_only;
63  return *this;
64 }
65 
66 ParameterDescription & ParameterDescription::set_dynamic_typing(bool dynamic_typing)
67 {
68  parameter_descriptor.dynamic_typing = dynamic_typing;
69  return *this;
70 }
71 
72 // Here is the Specific range function for this parameter description
73 ParameterDescription & ParameterDescription::set_floating_point_description_range(
74  float min, float max, float step)
75 {
76  if (parameter_descriptor.type == rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE) {
77  parameter_descriptor.floating_point_range.resize(1);
78  parameter_descriptor.floating_point_range.at(0).from_value = min;
79  parameter_descriptor.floating_point_range.at(0).to_value = max;
80  parameter_descriptor.floating_point_range.at(0).step = step;
81  }
82  return *this;
83 }
84 
85 ParameterDescription & ParameterDescription::set_integer_description_range(
86  int min, int max, int step)
87 {
88  if (parameter_descriptor.type == rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER) {
89  parameter_descriptor.integer_range.resize(1);
90  parameter_descriptor.integer_range.at(0).from_value = min;
91  parameter_descriptor.integer_range.at(0).to_value = max;
92  parameter_descriptor.integer_range.at(0).step = step;
93  }
94  return *this;
95 }
96 
97 } // namespace rclcpp
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.