学习视频:
18.tf坐标系广播与监听的编程实现_哔哩哔哩_bilibili
创建TF坐标系的功能包:
catkin_create_pkg ltf roscpp rospy tf turtlesim
将写好源码塞入ltf内部的src内;
下面时两个源码创建流程;
塞入源码后进行编译;
添加编译规则如下:
add_executable(turtle_tf_broadcaster src/turtle_tf_broadcaster.cpp) #将cpp文件编译为可执行文件
target_link_libraries(turtle_tf_broadcaster ${catkin_LIBRARIES}) #与可执行文件做链接
add_executable(turtle_tf_listener src/turtle_tf_listener.cpp)
target_link_libraries(turtle_tf_listener ${catkin_LIBRARIES})
添加完保存完毕回到根目录进行编译,记得保存变量环境;
后续测试运行可执行文件;
开启roscore打开海龟仿真器后运行第一个代码:
rosrun ltf turtle_tf_broadcaster __name:=turtle1_tf_broadcaster /turtle1
rosrun ltf turtle_tf_broadcaster __name:=turtle2_tf_broadcaster /turtle2
作用是给一个海龟起两个别名
rosrun ltf turtle_tf_listener
再使用键盘控制小海龟:
rosrun turtlesim turtle_teleop_key
至此测试完毕