系统环境
ubuntu 20.04
ros-noetic
一、构建工作空间 catkin_ws
mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
二、创建package,包名字为:robot_tf2,在src文件夹目录下,执行以下指令。
catkin_create_pkg robot_tf2 roscpp rospy tf2 tf2_ros tf2_geometry_msgs
三、写launch文件
cd robot_tf2
mkdir launch
cd launch
写 launch文件.
vim static_tf.launch
launch文件内容如下:
<launch>
<!-- 发布 base_footprint 到 base_link 的静态变换 -->
<!-- 参数说明: x y z yaw pitch roll parent_frame child_frame -->
<node pkg="tf2_ros" type="static_transform_publisher" name="base_footprint_broadcaster"
args="0 0 0.1 0 0 0 base_footprint base_link" />
<!-- 可选: 发布 odom 到 base_footprint 的静态变换 (仅用于测试) -->
<node pkg="tf2_ros" type="static_transform_publisher" name="odom_broadcaster"
args="0 0 0 0 0 0 odom base_footprint" />
</launch>
四、编译包
回到工作空间目录 catkin_ws,执行以下指令。
catkin_make
五、加载环境变量
source devel/setup.bash
六、运行launch脚本
roslaunch robot_tf2 static_tf.launch
七、查看发布 tf 的 topic
rostopic echo tf_static
输出结果如下:
transforms:
-
header:
seq: 0
stamp:
secs: 1751734669
nsecs: 626066038
frame_id: "odom"
child_frame_id: "base_footprint"
transform:
translation:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
---
transforms:
-
header:
seq: 0
stamp:
secs: 1751734669
nsecs: 623734317
frame_id: "base_footprint"
child_frame_id: "base_link"
transform:
translation:
x: 0.0
y: 0.0
z: 0.1
rotation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
---