ros2中tf2的使用

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);   

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();
  }

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值