odom_broadcaster; //定义发布器odom_broadcaster = std::make_unique
当前位置:   article > 正文

ros2中tf2的使用_ros2中的 tf.transformbroadcaster()

ros2中的 tf.transformbroadcaster()

tf2_ros::TransformBroadcaster

#include "tf2_ros/transform_broadcaster.h" 
auto node = rclcpp::Node::make_shared("test");

std::shared_ptr<tf2_ros::TransformBroadcaster> odom_broadcaster;   //定义发布器

odom_broadcaster = std::make_unique<tf2_ros::TransformBroadcaster>(node);

geometry_msgs::msg::TransformStamped odom_trans;

odom_broadcaster->sendTransform(odom_trans);   

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

tf2_ros::TransformListener

#include "tf2_ros/transform_listener.h"
auto node = rclcpp::Node::make_shared("test");
tf2_ros::Buffer *tf_buffer;
tf_buffer = new tf2_ros::Buffer(node->get_clock());
tf2_ros::TransformListener *tf_listener = new tf2_ros::TransformListener(*tf_buffer,node);
geometry_msgs::msg::TransformStamped lis_trans;
rclcpp::WallRate loop(1);

while (rclcpp::ok())
  {
  try
        {
            lis_trans = tf_buffer->lookupTransform(map_frame_,base_frame_,tf2::TimePointZero );

            RCLCPP_INFO(node->get_logger(),"%d %d %d",lis_trans.transform.translation.x,lis_trans.transform.translation.y,lis_trans.transform.translation.z);
        }
        catch(tf2::TransformException &ex)
        {
            RCLCPP_WARN(node->get_logger(),"%s",ex.what());
        }
        loop.sleep();
  }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签