The ROS2 publisher in class diagnostic_updater::DiagnosedPublisher currently supports messages of type diagnostic_msgs::msg::DiagnosticArray only:
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr publisher_; (https://github.com/ros/diagnostics/blob/eloquent/diagnostic_updater/include/diagnostic_updater/publisher.hpp, line 247).
This way, only messages of type diagnostic_msgs::msg::DiagnosticArray can be published by diagnostic_updater::DiagnosedPublisher. With a templetatized publisher this class could monitor messages of all types.
Example for a DiagnosedPublisher with template publisher:
namespace diagnostic_updater
{
template <class DiagnosedPublisherT> class DiagnosedPublisher : public TopicDiagnostic
{
public:
template <typename PublisherType> DiagnosedPublisher(PublisherType publisher, diagnostic_updater::Updater & diag,
const diagnostic_updater::FrequencyStatusParam & freq, const diagnostic_updater::TimeStampStatusParam & stamp)
: diagnostic_updater::TopicDiagnostic(publisher->get_topic_name(), diag, freq, stamp), publisher_(publisher)
{
}
template <typename MessageType> void publish(const std::shared_ptr<MessageType> & message)
{
publish(*message);
}
template <typename MessageType> void publish(const MessageType & message)
{
tick(message.header.stamp);
publisher_->publish(message);
}
protected:
DiagnosedPublisherT publisher_;
};
} // namespace diagnostic_updater
Usage example:
rclcpp::Node::SharedPtr nh = rclcpp::Node::make_shared("my_node", "");
double min_frequency = 10.0, max_frequency = 20.0;
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloudPub = nh->create_publisher<sensor_msgs::msg::PointCloud2>("cloud", rclcpp::SystemDefaultsQoS());
diagnostic_updater::Updater diagnostics(nh);
DiagnosedPublisher<rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr>* diagnosticPub
= new DiagnosedPublisher<rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr>(
pointcloudPub,
diagnostics,
diagnostic_updater::FrequencyStatusParam(&min_frequency, &max_frequency),
diagnostic_updater::TimeStampStatusParam());
I'd like to suggest to make publisher_ in class diagnostic_updater::DiagnosedPublisher a template to support messages of all types.
The ROS2 publisher in class diagnostic_updater::DiagnosedPublisher currently supports messages of type diagnostic_msgs::msg::DiagnosticArray only:
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr publisher_;(https://github.com/ros/diagnostics/blob/eloquent/diagnostic_updater/include/diagnostic_updater/publisher.hpp, line 247).This way, only messages of type
diagnostic_msgs::msg::DiagnosticArraycan be published bydiagnostic_updater::DiagnosedPublisher. With a templetatized publisher this class could monitor messages of all types.Example for a DiagnosedPublisher with template publisher:
Usage example:
I'd like to suggest to make
publisher_in classdiagnostic_updater::DiagnosedPublishera template to support messages of all types.