ros coordinate transform using tf

korkhg15·2022년 6월 17일
0

ROS

목록 보기
6/7

In this article, we use ros_tf header to transform coordinate odom to map

#include <ros/ros.h>
#include <tf/transform_broadcaster.h>

int main(int argc, char** argv)
{
  ros::init(argc, argv, "transform");
  ros::NodeHandle nh;
  double yaw_rotation=0.0;
  int32_t publish_rate_ = 100;
  tf::TransformBroadcaster tf_br_;
  tf::StampedTransform tf_map_to_odom_;
  if(nh.getParam("/yaw", yaw_rotation)){
    ROS_INFO("Got param: %d\n", yaw_rotation);
  }
  else{
    ROS_ERROR("Failed to get param\n");
  }
  tf_map_to_odom_.frame_id_ = std::string("map");
  tf_map_to_odom_.child_frame_id_ = std::string("odom");

  ros::Rate loop_rate(publish_rate_);
  
  while(ros::ok())
  {
    tf_map_to_odom_.stamp_ = ros::Time::now();

    tf_map_to_odom_.setOrigin(tf::Vector3(0.0f, 0.0f, 0.0f));
    tf_map_to_odom_.setRotation(tf::Quaternion(0.0, 0.0, yaw_rotation));

    tf_br_.sendTransform(tf_map_to_odom_);

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

  return 0;
}

You can set initial pose with changing setOrigin or setRotation

0개의 댓글