ros2适用tf2报错
-
如图,创建的world帧 一直说不存在,求助各位大佬,这是怎么回事 -
@scy123 你把你的用法贴上来,命令行还是代码?
-
@小鱼 就用的官方的命令行 ros2 run tf2_ros tf2_echo world turtle1
-
@小鱼 我跑官方的demo也会有错
-
@scy123 要有发布才行,你要不先看看我的教程
-
@小鱼 我运行了broadcaster 而且一开始跑ros2 launch turtle_tf2_py turtle_tf2_demo.launch.py这个demo的时候也出错
-
-
@小鱼
这是broadcaster的import math from geometry_msgs.msg import TransformStamped import numpy as np import rclpy from rclpy.node import Node from tf2_ros import TransformBroadcaster from turtlesim.msg import Pose def quaternion_from_euler(ai, aj, ak): ai /= 2.0 aj /= 2.0 ak /= 2.0 ci = math.cos(ai) si = math.sin(ai) cj = math.cos(aj) sj = math.sin(aj) ck = math.cos(ak) sk = math.sin(ak) cc = ci*ck cs = ci*sk sc = si*ck ss = si*sk q = np.empty((4, )) q[0] = cj*sc - sj*cs q[1] = cj*ss + sj*cc q[2] = cj*cs - sj*sc q[3] = cj*cc + sj*ss return q class FramePublisher(Node): def __init__(self): super().__init__('broad') self.turtlename = self.declare_parameter('turtlename', 'turtle').get_parameter_value().string_value self.tf_broadcaster = TransformBroadcaster(self) self.subscription = self.create_subscription(Pose,'broad1',self.handle_turtle_pose,10) def handle_turtle_pose(self, msg): t = TransformStamped() t.header.stamp = self.get_clock().now().to_msg() t.header.frame_id = 'world' t.child_frame_id = self.turtlename t.transform.translation.x = msg.x t.transform.translation.y = msg.y t.transform.translation.z = 0.0 q = quaternion_from_euler(0, 0, msg.theta) t.transform.rotation.x = q[0] t.transform.rotation.y = q[1] t.transform.rotation.z = q[2] t.transform.rotation.w = q[3] self.tf_broadcaster.sendTransform(t) def main(): rclpy.init() node = FramePublisher() try: rclpy.spin(node) except KeyboardInterrupt: pass rclpy.shutdown() launch的 from launch import LaunchDescription from launch_ros.actions import Node def generate_launch_description(): return LaunchDescription([ Node( package='turtlesim', executable='turtlesim_node', name='sim' ), Node( package='scy', executable='broad', name='broadcaster1', parameters=[ {'turtlename': 'turtle1'} ] ), ])
然后我运行launch后在命令窗口运行命令行ros2 run tf2_ros tf2_echo world turtle1
就出错
[tf2_echo]: Waiting for transform world -> turtle1: Invalid frame ID "world" passed to canTransform argument target_frame - frame does not exist -
@scy123 再贴一下rqt tf的图
-
@小鱼 图上说 no tf data received
-
@小鱼 小鱼老师,我还想再问一下,我的功能包老是本来能成功运行,然后过一段时间修改代码,然后重新编译再运行,就会说找不到功能包,这是怎么回事呀