Add identity publisher.

This commit is contained in:
James Pace 2026-09-16 19:56:11 -04:00
parent a80d602ac3
commit f003c19b5c
1 changed files with 36 additions and 0 deletions

36
src/IdentityPublisher.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>
#include <cstdlib>
#include <chrono>
using namespace std::chrono_literals;
namespace j7s {
class IdentityPublisher : public rclcpp::Node {
public:
IdentityPublisher(const rclcpp::NodeOptions& options);
private:
std::shared_ptr<rclcpp::Publisher<std_msgs::msg::String>> m_publisher;
rclcpp::TimerBase::SharedPtr m_timer;
};
};
namespace j7s {
IdentityPublisher::IdentityPublisher(const rclcpp::NodeOptions& options):
Node("identity_publisher", options),
m_publisher(this->create_publisher<std_msgs::msg::String>("identity", 1)),
m_timer{}
{
const std::string identity = "namespace: data_simulator\njaus_id: 123.1.1";
m_timer = this->create_timer(1000ms, [this, identity]() -> void {
std_msgs::msg::String msg;
msg.data = identity;
m_publisher->publish(msg);
});
}
};
#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(j7s::IdentityPublisher)