ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Since static_transform_publisher can be used only to set up transformation between fixed (w.r.t. each other) frames you have to use something like this in your node:

int32_t publish_rate_ = 100;
tf::TransformBroadcaster tf_br_;
tf::StampedTransform tf_map_to_odom_;

// set up parent and child frames
tf_map_to_odom_.frame_id = std::string("/map");
tf_map_to_odom_.child_frame_id = std::string("/odom");

// specify actual transformation vectors from odometry
tf_map_to_odom_.setOrigin(tf::Vector3(0.0f, 0.0f, 0.0f));
tf_map_to_odom_.setRotation(tf::Quaternion(0.0f, 0.0f, 0.0f));

// set up publish rate
ros::Rate loop_rate(publish_rate_);
while (ros::ok())
{
  // broadcast transform
  tf_br_.sendTransform(tf_world_);

  ros::spinOnce();
  loop_rate.sleep();
}
click to hide/show revision 2
fixed mistakes in code

Since static_transform_publisher can be used only to set up transformation between fixed (w.r.t. each other) frames you have to use something like this in your node:

int32_t publish_rate_ = 100;
tf::TransformBroadcaster tf_br_;
tf::StampedTransform tf_map_to_odom_;

// set up parent and child frames
tf_map_to_odom_.frame_id = std::string("/map");
std::string("map");
tf_map_to_odom_.child_frame_id = std::string("/odom");
std::string("odom");

// specify actual transformation vectors from odometry
tf_map_to_odom_.setOrigin(tf::Vector3(0.0f, 0.0f, 0.0f));
tf_map_to_odom_.setRotation(tf::Quaternion(0.0f, 0.0f, 0.0f));

// set up publish rate
ros::Rate loop_rate(publish_rate_);
while (ros::ok())
{
  // broadcast transform
  tf_br_.sendTransform(tf_world_);
tf_br_.sendTransform(tf_map_to_odom_);

  ros::spinOnce();
  loop_rate.sleep();
}

Since static_transform_publisher can be used only to set up transformation between fixed (w.r.t. each other) frames you have to use something like this in your node:

int32_t publish_rate_ = 100;
tf::TransformBroadcaster tf_br_;
tf::StampedTransform tf_map_to_odom_;

// set up parent and child frames
tf_map_to_odom_.frame_id = std::string("map");
tf_map_to_odom_.child_frame_id = std::string("odom");

// set up publish rate
ros::Rate loop_rate(publish_rate_);

// main loop
while (ros::ok())
{
  // specify actual transformation vectors from odometry
 tf_map_to_odom_.setOrigin(tf::Vector3(0.0f, 0.0f, 0.0f));
 tf_map_to_odom_.setRotation(tf::Quaternion(0.0f, 0.0f, 0.0f));

// set up publish rate
ros::Rate loop_rate(publish_rate_);
while (ros::ok())
{
  // broadcast transform
  tf_br_.sendTransform(tf_map_to_odom_);

  ros::spinOnce();
  loop_rate.sleep();
}
click to hide/show revision 4
added missed line for time stamp in code snippet

Since static_transform_publisher can be used only to set up transformation between fixed (w.r.t. each other) frames you have to use something like this in your node:

int32_t publish_rate_ = 100;
tf::TransformBroadcaster tf_br_;
tf::StampedTransform tf_map_to_odom_;

// set up parent and child frames
tf_map_to_odom_.frame_id tf_map_to_odom_.frame_id_ = std::string("map");
tf_map_to_odom_.child_frame_id tf_map_to_odom_.child_frame_id_ = std::string("odom");

// set up publish rate
ros::Rate loop_rate(publish_rate_);

// main loop
while (ros::ok())
{
  // time stamp
  tf_map_to_odom_.stamp_ = ros::Time::now();

  // specify actual transformation vectors from odometry
  // NOTE: zeros have to be substituted with actual variable data
  tf_map_to_odom_.setOrigin(tf::Vector3(0.0f, 0.0f, 0.0f));
  tf_map_to_odom_.setRotation(tf::Quaternion(0.0f, 0.0f, 0.0f));

  // broadcast transform
  tf_br_.sendTransform(tf_map_to_odom_);

  ros::spinOnce();
  loop_rate.sleep();
}