6#include <rm_msgs/DebugData.h>
7#include <unordered_map>
22 explicit DebugDataPublisher(ros::NodeHandle& nh,
const std::string& topic =
"debug_data",
int queue_size = 5)
24 debug_data_pub_ = nh.advertise<rm_msgs::DebugData>(topic, queue_size);
32 void add(
const std::string& name,
double value)
34 auto it = index_map_.find(name);
35 if (it != index_map_.end())
38 debug_data_.stamp[it->second] = ros::Time::now();
39 debug_data_.value[it->second] = value;
44 index_map_[name] = debug_data_.name.size();
45 debug_data_.stamp.push_back(ros::Time::now());
46 debug_data_.name.push_back(name);
47 debug_data_.value.push_back(value);
57 void add(
const std::string& name,
double value,
const ros::Time& stamp)
59 auto it = index_map_.find(name);
60 if (it != index_map_.end())
62 debug_data_.stamp[it->second] = stamp;
63 debug_data_.value[it->second] = value;
67 index_map_[name] = debug_data_.name.size();
68 debug_data_.stamp.push_back(stamp);
69 debug_data_.name.push_back(name);
70 debug_data_.value.push_back(value);
79 if (!debug_data_.name.empty())
81 debug_data_pub_.publish(debug_data_);
91 if (!debug_data_.name.empty())
93 debug_data_pub_.publish(debug_data_);
102 debug_data_.stamp.clear();
103 debug_data_.name.clear();
104 debug_data_.value.clear();
109 ros::Publisher debug_data_pub_;
110 rm_msgs::DebugData debug_data_;
111 std::unordered_map<std::string, size_t> index_map_;
Debug data publisher. Supports adding/updating named variables and batch publishing.
Definition DebugDataPublisher.h:14
DebugDataPublisher(ros::NodeHandle &nh, const std::string &topic="debug_data", int queue_size=5)
Construct and initialize the publisher.
Definition DebugDataPublisher.h:22
void add(const std::string &name, double value)
Add or update a debug variable, stamped at current time.
Definition DebugDataPublisher.h:32
void clear()
Clear all stored debug data.
Definition DebugDataPublisher.h:100
void publishAndKeep()
Publish accumulated debug data without clearing. Useful for persistent variables.
Definition DebugDataPublisher.h:89
void publish()
Publish accumulated debug data and clear.
Definition DebugDataPublisher.h:77
void add(const std::string &name, double value, const ros::Time &stamp)
Add or update a debug variable with a custom timestamp.
Definition DebugDataPublisher.h:57