StaticTransformBroadcaster does not broadcast
Hey, I tried to implement a simple StaticTransformBroadcaster with the following code:
#include <ros/ros.h>
#include <tf2_ros/static_transform_broadcaster.h>
#include <tf2/transform_datatypes.h>
#include <geometry_msgs/TransformStamped.h>
#include <geometry_msgs/Transform.h>
void publishStaticTransformation();
int main (int argc, char** argv)
{
ros::init(argc, argv, "StaticBroadcaster");
ROS_INFO("StaticBroadcaster started");
publishStaticTransformation();
ros::spin();
}
void publishStaticTransformation()
{
tf2_ros::StaticTransformBroadcaster staticBroadcaster2;
geometry_msgs::TransformStamped msg;
msg.header.stamp = ros::Time::now();
msg.header.frame_id = "base_link";
msg.child_frame_id = "child_2";
msg.transform.rotation.x = 2.0;
msg.transform.rotation.y = 2.0;
msg.transform.rotation.z = 0.0;
msg.transform.rotation.w = 1.0;
msg.transform.translation.x = 0;
msg.transform.translation.y = 0;
msg.transform.translation.z = 0;
staticBroadcaster2.sendTransform(msg);
ROS_INFO_STREAM("published");
}
This doesn't work but i don't know why. "published" is printed on the Console but rqt_graph shows no connection between my broadcaster and the tf_static topic. However, wehn I Create the StaticTransformBroadcaster first and pass it as an argument to my publishStaticTransformation-method it works.
#include <ros/ros.h>
#include <tf2_ros/static_transform_broadcaster.h>
#include <tf2/transform_datatypes.h>
#include <geometry_msgs/TransformStamped.h>
#include <geometry_msgs/Transform.h>
void publishStaticTransformation(tf2_ros::StaticTransformBroadcaster &staticBroadcaster);
int main (int argc, char** argv)
{
ros::init(argc, argv, "StaticBroadcaster");
ROS_INFO("StaticBroadcaster started");
tf2_ros::StaticTransformBroadcaster staticBroadcaster;
publishStaticTransformation(staticBroadcaster);
ros::spin();
}
void publishStaticTransformation(tf2_ros::StaticTransformBroadcaster &staticBroadcaster)
{
geometry_msgs::TransformStamped msg;
msg.header.stamp = ros::Time::now();
msg.header.frame_id = "base_link";
msg.child_frame_id = "child_2";
msg.transform.rotation.x = 2.0;
msg.transform.rotation.y = 2.0;
msg.transform.rotation.z = 0.0;
msg.transform.rotation.w = 1.0;
msg.transform.translation.x = 0;
msg.transform.translation.y = 0;
msg.transform.translation.z = 0;
staticBroadcaster.sendTransform(msg);
}
Does anyone know, what I'm doing wrong?
Any help is appreciated