Skip to content

Commit daa3294

Browse files
authored
Merge pull request #87 from naturerobots/feature/on-demand-publishing
Re-publish Static Cost Layers on when a new subscriber appears
2 parents f0546b7 + 6c83ed1 commit daa3294

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

mesh_map/include/mesh_map/mesh_map.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ class MeshMap
531531

532532
//! publisher for vertex costs
533533
rclcpp::Publisher<mesh_msgs::msg::MeshVertexCostsStamped>::SharedPtr vertex_costs_pub;
534+
rclcpp::TimerBase::SharedPtr vertex_costs_subscribe_checker_;
535+
size_t vertex_costs_sub_count_ = 0;
534536
rclcpp::Publisher<mesh_msgs::msg::MeshVertexCostsSparseStamped>::SharedPtr vertex_costs_update_pub_;
535537

536538
//! publisher for vertex colors

mesh_map/src/mesh_map.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,6 @@ namespace fs = std::filesystem;
8484
namespace mesh_map
8585
{
8686

87-
// std::shared_ptr<lvr2::BaseMesh<Vector> > createHemByName(std::string hem_impl, lvr2::MeshBufferPtr mesh_buffer)
88-
// {
89-
// if(hem_impl == "pmp")
90-
// {
91-
// return std::make_shared<lvr2::PMPMesh<Vector> >(mesh_buffer);
92-
// }
93-
// else if(hem_impl == "lvr")
94-
// {
95-
// return std::make_shared<lvr2::HalfEdgeMesh<Vector> >(mesh_buffer);
96-
// }
97-
98-
// std::stringstream error_msg;
99-
// error_msg << "'" << hem_impl << "' not known." << std::endl;
100-
// throw std::runtime_error(error_msg.str());
101-
// }
102-
10387
using HDF5MeshIO = lvr2::Hdf5Build<lvr2::hdf5features::MeshIO>;
10488

10589
MeshMap::MeshMap(tf2_ros::Buffer& tf, const rclcpp::Node::SharedPtr& node)
@@ -147,6 +131,17 @@ MeshMap::MeshMap(tf2_ros::Buffer& tf, const rclcpp::Node::SharedPtr& node)
147131
marker_pub = node->create_publisher<visualization_msgs::msg::Marker>("~/marker", 100);
148132
mesh_geometry_pub = node->create_publisher<mesh_msgs::msg::MeshGeometryStamped>("~/mesh", rclcpp::QoS(1).transient_local());
149133
vertex_costs_pub = node->create_publisher<mesh_msgs::msg::MeshVertexCostsStamped>("~/vertex_costs", rclcpp::QoS(1).transient_local());
134+
// we dont want to publish static costs all the time.
135+
// therefore we have to check if someone newly subscribed to the topic
136+
vertex_costs_subscribe_checker_ = node->create_wall_timer(std::chrono::milliseconds(200), [this, node]{
137+
const size_t count = vertex_costs_pub->get_subscription_count() + vertex_costs_pub->get_intra_process_subscription_count();
138+
if (count > vertex_costs_sub_count_)
139+
{
140+
RCLCPP_INFO(node->get_logger(), "New cost layer subscriber detected. Publishing vertex costs once...");
141+
publishCostLayers(node->now());
142+
}
143+
vertex_costs_sub_count_ = count;
144+
});
150145
vertex_costs_update_pub_ = node->create_publisher<mesh_msgs::msg::MeshVertexCostsSparseStamped>(std::string(vertex_costs_pub->get_topic_name()) + "/updates", rclcpp::QoS(10).transient_local());
151146
vertex_colors_pub = node->create_publisher<mesh_msgs::msg::MeshVertexColorsStamped>("~/vertex_colors", rclcpp::QoS(1).transient_local());
152147
vector_field_pub = node->create_publisher<visualization_msgs::msg::Marker>("~/vector_field", rclcpp::QoS(1).transient_local());

0 commit comments

Comments
 (0)