Skip to content

Commit bb2ada4

Browse files
Used utility function to simplify namespace calls.
Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com>
1 parent 0955616 commit bb2ada4

File tree

5 files changed

+6
-37
lines changed

5 files changed

+6
-37
lines changed

nav2_costmap_2d/include/nav2_costmap_2d/costmap_layer.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,6 @@ class CostmapLayer : public Layer, public Costmap2D
194194
*/
195195
CombinationMethod combination_method_from_int(const int value);
196196

197-
/**
198-
* Joins the specified topic with the parent namespace of the costmap node.
199-
* If the topic has an absolute path, it is returned instead.
200-
*
201-
* This is necessary for user defined relative topics to work as expected since costmap layers
202-
* add a an additional `costmap_name` namespace to the topic.
203-
* For example:
204-
* * User chosen namespace is `tb4`.
205-
* * User chosen topic is `scan`.
206-
* * Costmap node namespace will be `/tb4/global_costmap`.
207-
* * Without this function, the topic would be `/tb4/global_costmap/scan`.
208-
* * With this function, topic will be remapped to `/tb4/scan`.
209-
* Use global topic `/scan` if you do not wish the node namespace to apply
210-
*
211-
* @param topic the topic to parse
212-
*/
213-
std::string joinWithParentNamespace(const std::string & topic);
214-
215197
private:
216198
double extra_min_x_, extra_max_x_, extra_min_y_, extra_max_y_;
217199
};

nav2_costmap_2d/plugins/obstacle_layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "pluginlib/class_list_macros.hpp"
4747
#include "sensor_msgs/point_cloud2_iterator.hpp"
4848
#include "nav2_costmap_2d/costmap_math.hpp"
49+
#include "nav2_costmap_2d/costmap_utils.hpp"
4950
#include "rclcpp/version.h"
5051

5152
PLUGINLIB_EXPORT_CLASS(nav2_costmap_2d::ObstacleLayer, nav2_costmap_2d::Layer)
@@ -190,7 +191,7 @@ void ObstacleLayer::onInitialize()
190191
node->get_parameter(name_ + "." + source + "." + "raytrace_min_range", raytrace_min_range);
191192
node->get_parameter(name_ + "." + source + "." + "raytrace_max_range", raytrace_max_range);
192193

193-
topic = joinWithParentNamespace(topic);
194+
topic = joinWithParentNamespace(node_, topic);
194195

195196
RCLCPP_DEBUG(
196197
logger_,

nav2_costmap_2d/plugins/range_sensor_layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "pluginlib/class_list_macros.hpp"
4444
#include "geometry_msgs/msg/point_stamped.hpp"
4545
#include "nav2_costmap_2d/range_sensor_layer.hpp"
46+
#include "nav2_costmap_2d/costmap_utils.hpp"
4647

4748
PLUGINLIB_EXPORT_CLASS(nav2_costmap_2d::RangeSensorLayer, nav2_costmap_2d::Layer)
4849

@@ -130,7 +131,7 @@ void RangeSensorLayer::onInitialize()
130131

131132
// Traverse the topic names list subscribing to all of them with the same callback method
132133
for (auto & topic_name : topic_names) {
133-
topic_name = joinWithParentNamespace(topic_name);
134+
topic_name = joinWithParentNamespace(node_, topic_name);
134135
if (input_sensor_type == InputSensorType::VARIABLE) {
135136
processRangeMessageFunc_ = std::bind(
136137
&RangeSensorLayer::processVariableRangeMsg, this,

nav2_costmap_2d/plugins/static_layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "tf2/convert.hpp"
4747
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
4848
#include "nav2_util/validate_messages.hpp"
49+
#include "nav2_costmap_2d/costmap_utils.hpp"
4950

5051
PLUGINLIB_EXPORT_CLASS(nav2_costmap_2d::StaticLayer, nav2_costmap_2d::Layer)
5152

@@ -150,7 +151,7 @@ StaticLayer::getParameters()
150151
node->get_parameter(name_ + "." + "footprint_clearing_enabled", footprint_clearing_enabled_);
151152
node->get_parameter(name_ + "." + "restore_cleared_footprint", restore_cleared_footprint_);
152153
node->get_parameter(name_ + "." + "map_topic", map_topic_);
153-
map_topic_ = joinWithParentNamespace(map_topic_);
154+
map_topic_ = joinWithParentNamespace(node, map_topic_);
154155
node->get_parameter(
155156
name_ + "." + "map_subscribe_transient_local",
156157
map_subscribe_transient_local_);

nav2_costmap_2d/src/costmap_layer.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,4 @@ CombinationMethod CostmapLayer::combination_method_from_int(const int value)
273273
return CombinationMethod::Max;
274274
}
275275
}
276-
277-
std::string CostmapLayer::joinWithParentNamespace(const std::string & topic)
278-
{
279-
auto node = node_.lock();
280-
if (!node) {
281-
throw std::runtime_error{"Failed to lock node"};
282-
}
283-
284-
if (topic[0] != '/') {
285-
std::string node_namespace = node->get_namespace();
286-
std::string parent_namespace = node_namespace.substr(0, node_namespace.rfind("/"));
287-
return parent_namespace + "/" + topic;
288-
}
289-
290-
return topic;
291-
}
292276
} // namespace nav2_costmap_2d

0 commit comments

Comments
 (0)