紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
ROS2的命名空间问题以及在RViz中不显示模型图像
-
标题:ROS2的命名空间问题以及在RViz中不显示模型图像
问题描述及具体细节:
我需要将两款机械臂同时显示在RViz中,但是我运行.launch.py文件之后只显示了一个机械臂的每个关节的坐标轴,另一个机械臂没有显示出来。
下面这两张图为运行.launch.py文件之后的效果图:以下是我的.launch.py文件的全部代码:
import os from ament_index_python import get_package_share_path from launch import LaunchDescription from launch_ros.actions import Node from launch.substitutions import LaunchConfiguration, Command from launch_ros.substitutions import FindPackageShare from launch_ros.substitutions import FindPackageShare from ament_index_python.packages import get_package_share_directory from launch.actions import DeclareLaunchArgument def generate_launch_description(): # 获取包路径 myarm_m750_description_pkg = FindPackageShare('myarm_m750').find('myarm_m750') # myarm_c650_description_pkg = FindPackageShare('myarm_c650').find('myarm_c650') mycobot_description_pkg = FindPackageShare('mycobot_description').find('mycobot_description') # 定义 URDF 文件路径 urdf_m750 = os.path.join(mycobot_description_pkg, 'urdf','myarm_m750', 'myarm_m750.urdf.xacro') urdf_c650 = os.path.join(mycobot_description_pkg, 'urdf','myarm_c650', 'myarm_c650.urdf.xacro') # 定义 RViz 配置文件路径 rviz_config_file = os.path.join(myarm_m750_description_pkg, 'config', 'myarm_m750_with_myarm_c650.rviz') ns1_arg = LaunchConfiguration('ns1') ns2_arg = LaunchConfiguration('ns2') return LaunchDescription([ # 定义是否使用仿真时间参数 DeclareLaunchArgument('use_sim_time', default_value='false', description='Use simulation (Gazebo) clock if true'), # myarm_m750 的 robot_state_publisher 节点 Node( package='robot_state_publisher', executable='robot_state_publisher', namespace='myarm_m750', parameters=[{ 'use_sim_time': LaunchConfiguration('use_sim_time'), 'robot_description': Command(['xacro ', urdf_m750]) }], output='screen', ), # myarm_m750 的 joint_state_publisher_gui 节点 Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', namespace='myarm_m750', parameters=[{'use_sim_time': LaunchConfiguration('use_sim_time')}], output='screen', ), # myarm_c650 的 robot_state_publisher 节点 Node( package='robot_state_publisher', executable='robot_state_publisher', namespace='myarm_c650', parameters=[{ 'use_sim_time': LaunchConfiguration('use_sim_time'), 'robot_description': Command(['xacro ', urdf_c650]) }], output='screen', ), # myarm_c650 的 joint_state_publisher_gui 节点 Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', namespace='myarm_c650', parameters=[{'use_sim_time': LaunchConfiguration('use_sim_time')}], output='screen', ), # RViz 节点 Node( package='rviz2', executable='rviz2', name='rviz2', output='screen', arguments=['-d', rviz_config_file], ), # 静态 TF 发布节点 DeclareLaunchArgument( 'ns1', default_value='myarm_m750', description='Namespace 1' ), DeclareLaunchArgument( 'ns2', default_value='myarm_c650', description='Namespace 2' ), # Transform for ns2 Node( package='tf2_ros', executable='static_transform_publisher', name='static_transform_publisher1_ns2', output='screen', arguments=['0', '-0.5', '0', '0', '0', '0', '/map', [ns2_arg, '/base']] ), # Transform for ns1 Node( package='tf2_ros', executable='static_transform_publisher', name='static_transform_publisher1_ns1', output='screen', arguments=['0', '0.5', '0', '0', '0', '0', '/map', [ns1_arg, '/base']] ) ])
运行这个代码之后,终端的报错信息是这样的:
尝试过的解决方法:
- 我用GPT将实现同样功能的ROS1版本的launch文件中的内容转换成ROS2的.launch.py文件,但是还是报错了。求大佬出手相助!