Easy Navigation
Loading...
Searching...
No Matches
RobotGeometry.hpp
Go to the documentation of this file.
1// Copyright 2026 Intelligent Robotics Lab
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
17
18#ifndef EASYNAV_COMMON__ROBOTGEOMETRY_HPP_
19#define EASYNAV_COMMON__ROBOTGEOMETRY_HPP_
20
21#include <mutex>
22#include <set>
23#include <string>
24
25#include "rclcpp/rclcpp.hpp"
26
30
31namespace easynav
32{
33
41class RobotGeometryRegistry : public Singleton<RobotGeometryRegistry>
42{
43public:
45
48 {
49 std::lock_guard<std::mutex> lock(mutex_);
50 return geometry_;
51 }
52
54 bool is_configured(const std::string & field) const
55 {
56 std::lock_guard<std::mutex> lock(mutex_);
57 return configured_.count(field) > 0;
58 }
59
61 void set_geometry(const RobotGeometry & geometry, const std::set<std::string> & configured = {})
62 {
63 std::lock_guard<std::mutex> lock(mutex_);
64 geometry_ = geometry;
65 configured_ = configured;
66 }
67
68private:
69 RobotGeometry geometry_;
70 std::set<std::string> configured_;
71 mutable std::mutex mutex_;
72
74};
75
86template<typename NodeT>
88{
89 auto registry = RobotGeometryRegistry::getInstance();
90 RobotGeometry geometry = registry->get_geometry();
91
92 auto apply = [&](const std::string & name, const std::string & field, double & value) {
93 if (name.empty()) {
94 return;
95 }
96 const auto & overrides = node.get_node_parameters_interface()->get_parameter_overrides();
97 if (overrides.count(name) == 0 && !node.has_parameter(name)) {
98 return;
99 }
100 double legacy_value = value;
101 declare_parameter_if_absent(node, name, legacy_value);
102 node.get_parameter(name, legacy_value);
103
104 const auto replacement = "system_node.robot_geometry." + field;
105 if (registry->is_configured(field)) {
106 RCLCPP_WARN(
107 node.get_logger(), "'%s' is deprecated and ignored: '%s' takes precedence",
108 name.c_str(), replacement.c_str());
109 return;
110 }
111 RCLCPP_WARN(
112 node.get_logger(), "'%s' is deprecated: configure '%s' instead. It will stop working soon.",
113 name.c_str(), replacement.c_str());
114 value = legacy_value;
115 };
116
117 apply(legacy.radius, "radius", geometry.radius);
118 apply(legacy.inscribed_radius, "inscribed_radius", geometry.inscribed_radius);
119 apply(legacy.height, "height", geometry.height);
120 return geometry;
121}
122
123} // namespace easynav
124
125#endif // EASYNAV_COMMON__ROBOTGEOMETRY_HPP_
Parameter helpers for plugins that may be initialized several times on the same node.
#define SINGLETON_DEFINITIONS(ClassName)
Definition Singleton.hpp:82
void set_geometry(const RobotGeometry &geometry, const std::set< std::string > &configured={})
Sets the robot's geometry, and which fields were configured explicitly.
Definition RobotGeometry.hpp:61
RobotGeometry get_geometry() const
The robot's geometry.
Definition RobotGeometry.hpp:47
bool is_configured(const std::string &field) const
Whether "robot_geometry.<field>" was configured explicitly.
Definition RobotGeometry.hpp:54
static RobotGeometryRegistry * getInstance(Args &&... args)
Definition Singleton.hpp:30
Definition CircularBuffer.hpp:24
RobotGeometry get_robot_geometry(NodeT &node, const LegacyRobotGeometryNames &legacy={})
The robot's geometry ("system_node.robot_geometry.*").
Definition RobotGeometry.hpp:87
void declare_parameter_if_absent(NodeT &node, const std::string &name, const T &default_value)
Declares name with default_value unless it already exists.
Definition Parameters.hpp:34
std::mutex Singleton< C >::mutex_
Definition Singleton.hpp:80
The robot's shape, shared by everything that needs it.
Definition RobotGeometry.hpp:34
double inscribed_radius
Largest circle inside the robot (m). Defaults to radius.
Definition RobotGeometry.hpp:36
double radius
Circumscribed: smallest circle containing the robot (m).
Definition RobotGeometry.hpp:35
double height
Top of the robot, above the robot frame (m).
Definition RobotGeometry.hpp:37
Deprecated parameter names (full names on the node, "" = none) for each field.
Definition RobotGeometry.hpp:48
The robot's shape, shared by everything that needs it.
Definition RobotGeometry.hpp:34
Declaration of RobotGeometry and LegacyRobotGeometryNames.