ROS2 TF publisher not publishing anything
Hi All,
I'm new to ROS2 I coded a publisher in C++ colcon build ran successfully and the topic publishes but I don't see any TF messages my cod is below. Any idea why it wont work?
#include "rclcpp/rclcpp.hpp"
#include "tf2/LinearMath/Quaternion.h"
#include "tf2_ros/transform_broadcaster.h"
#include "geometry_msgs/msg/transform_stamped.hpp"
class OmniBroadcastnode : public rclcpp::Node
{
public:
OmniBroadcastnode()
: Node("omni_tf2_broadcaster_node")
{
tf2_broadcaster_ = std::make_unique<tf2_ros::TransformBroadcaster>(this);
}
private:
void spin()
{
geometry_msgs::msg::TransformStamped transform_;
rclcpp::Rate loop_rate(100);
while (rclcpp::ok())
{
transform_.header.stamp = this->get_clock()->now();
transform_.header.frame_id = "base_link";
transform_.child_frame_id = "base_laser";
transform_.transform.translation.x = 0.0;
transform_.transform.translation.y = 0.025;
transform_.transform.translation.z = 0.2;
tf2::Quaternion q;
q.setRPY(0, 0, 0);
transform_.transform.rotation.x = q.x();
transform_.transform.rotation.y = q.y();
transform_.transform.rotation.z = q.z();
transform_.transform.rotation.w = q.w();
tf2_broadcaster_->sendTransform(transform_);
loop_rate.sleep();
}
}
std::unique_ptr<tf2_ros::TransformBroadcaster> tf2_broadcaster_;
};
int main(int argc, char * argv[]){
rclcpp::init(argc, argv);
//rclcpp::spin(std::make_shared<OmniBroadcastnode>());
auto omni_tf2_broadcaster_node = std::make_shared<OmniBroadcastnode>();
rclcpp::spin(omni_tf2_broadcaster_node);
rclcpp::shutdown();
return 0;
}