小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
ROS2-humble下使用gazebo仿真多个机器人
-
我需要仿真两个ur机械臂,区分为right和left,单独一个机械臂在启动时不会发生任何异常,日志及效果均正常。但是我在gazebo中仿真两个机械臂时出现了一下错误,此时我先启动的是gazebo和right机械臂。
当我启动left机械臂时出现如下报错:[gazebo-1] [INFO] [1721305630.545883012] [gazebo_ros2_control]: Loading gazebo_ros2_control plugin [gazebo-1] [INFO] [1721305630.548942789] [right_ur_ft.left_gazebo_ros2_control]: Starting gazebo_ros2_control plugin in namespace: /right_ur_ft [gazebo-1] [INFO] [1721305630.548969012] [right_ur_ft.left_gazebo_ros2_control]: Starting gazebo_ros2_control plugin in ros 2 node: left_gazebo_ros2_control [gazebo-1] [INFO] [1721305630.551234947] [right_ur_ft.left_gazebo_ros2_control]: connected to service!! robot_state_publisher [gazebo-1] [INFO] [1721305630.551447028] [right_ur_ft.left_gazebo_ros2_control]: Received urdf from param server, parsing... [gazebo-1] [INFO] [1721305630.551465845] [right_ur_ft.left_gazebo_ros2_control]: Loading parameter files /home/pc/Documents/code/my_project/install/dual_ur_ft_description/share/dual_ur_ft_description/config/left_controllers.yaml [gazebo-1] [WARN] [1721305630.553943330] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_shoulder_pan_joint' which is not in the gazebo model. [gazebo-1] [WARN] [1721305630.553980206] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_shoulder_lift_joint' which is not in the gazebo model. [gazebo-1] [WARN] [1721305630.553987412] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_elbow_joint' which is not in the gazebo model. [gazebo-1] [WARN] [1721305630.553993509] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_wrist_1_joint' which is not in the gazebo model. [gazebo-1] [WARN] [1721305630.553999327] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_wrist_2_joint' which is not in the gazebo model. [gazebo-1] [WARN] [1721305630.554005002] [right_ur_ft.left_gazebo_ros2_control]: Skipping joint in the URDF named 'right_wrist_3_joint' which is not in the gazebo model. [gazebo-1] [INFO] [1721305630.554012707] [resource_manager]: Initialize hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554027646] [resource_manager]: Successful initialization of hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554034086] [resource_manager]: 'configure' hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554038544] [resource_manager]: Successful 'configure' of hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554041070] [resource_manager]: 'activate' hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554044007] [resource_manager]: Successful 'activate' of hardware 'right_ur_ft' [gazebo-1] [INFO] [1721305630.554075380] [right_ur_ft.left_gazebo_ros2_control]: Loading controller_manager [gazebo-1] [WARN] [1721305630.566282520] [right_ur_ft.left_gazebo_ros2_control]: Desired controller update period (0.01 s) is slower than the gazebo simulation period (0.001 s). [gazebo-1] [INFO] [1721305630.566433146] [right_ur_ft.left_gazebo_ros2_control]: Loaded gazebo_ros2_control. [gazebo-1] [INFO] [1721305630.721421170] [left_ur_ft.controller_manager]: Loading controller 'left_ur_arm_controller' [gazebo-1] [WARN] [1721305630.727062472] [left_ur_ft.left_ur_arm_controller]: [Deprecated]: "allow_nonzero_velocity_at_trajectory_end" is set to true. The default behavior will change to false. [gazebo-1] [INFO] [1721305630.738388252] [left_ur_ft.controller_manager]: Configuring controller 'left_ur_arm_controller' [gazebo-1] [INFO] [1721305630.738528990] [left_ur_ft.left_ur_arm_controller]: No specific joint names are used for command interfaces. Using 'joints' parameter. [gazebo-1] [INFO] [1721305630.738544047] [left_ur_ft.left_ur_arm_controller]: Command interfaces are [position] and state interfaces are [position velocity]. [gazebo-1] [INFO] [1721305630.738551237] [left_ur_ft.left_ur_arm_controller]: Using 'splines' interpolation method. [gazebo-1] [INFO] [1721305630.738881576] [left_ur_ft.left_ur_arm_controller]: Controller state will be published at 100.00 Hz. [gazebo-1] [INFO] [1721305630.739418360] [left_ur_ft.left_ur_arm_controller]: Action status changes will be monitored at 20.00 Hz. [gazebo-1] [ERROR] [1721305630.747940453] [resource_manager]: Not acceptable command interfaces combination: [gazebo-1] Start interfaces: [gazebo-1] [ [gazebo-1] left_shoulder_pan_joint/position [gazebo-1] left_shoulder_lift_joint/position [gazebo-1] left_elbow_joint/position [gazebo-1] left_wrist_1_joint/position [gazebo-1] left_wrist_2_joint/position [gazebo-1] left_wrist_3_joint/position [gazebo-1] ] [gazebo-1] Stop interfaces: [gazebo-1] [ [gazebo-1] ] [gazebo-1] Not existing: [gazebo-1] [ [gazebo-1] left_shoulder_pan_joint/position [gazebo-1] left_shoulder_lift_joint/position [gazebo-1] left_elbow_joint/position [gazebo-1] left_wrist_1_joint/position [gazebo-1] left_wrist_2_joint/position [gazebo-1] left_wrist_3_joint/position [gazebo-1] ] [gazebo-1] [gazebo-1] [ERROR] [1721305630.747965277] [left_ur_ft.controller_manager]: Could not switch controllers since prepare command mode switch was rejected. [gazebo-1] [INFO] [1721305631.166267831] [left_ur_ft.controller_manager]: Loading controller 'left_joint_state_broadcaster' [gazebo-1] [INFO] [1721305631.178641120] [left_ur_ft.controller_manager]: Configuring controller 'left_joint_state_broadcaster' [gazebo-1] [INFO] [1721305631.178682137] [left_ur_ft.left_joint_state_broadcaster]: 'joints' or 'interfaces' parameter is empty. All available state interfaces will be published [gazebo-1] [ERROR] [1721305631.197295835] [left_ur_ft.left_joint_state_broadcaster]: None of requested interfaces exist. Controller will not run. [gazebo-1] [WARN] [1721305631.197377359] [left_ur_ft.left_joint_state_broadcaster]: Error occurred while doing error handling. [gazebo-1] [ERROR] [1721305631.197411498] [left_ur_ft.controller_manager]: After activation, controller 'left_joint_state_broadcaster' is in state 'unconfigured' (1), expected 'active' (3).
[spawner-3] [INFO] [1721305630.737579996] [spawner_left_ur_arm_controller]: Loaded left_ur_arm_controller [spawner-3] [ERROR] [1721305630.748434297] [spawner_left_ur_arm_controller]: Failed to activate controller [ERROR] [spawner-3]: process has died [pid 21171, exit code 1, cmd '/opt/ros/humble/lib/controller_manager/spawner left_ur_arm_controller -c /left_ur_ft/controller_manager --ros-args']. [spawner-2] [INFO] [1721305631.177883333] [spawner_left_joint_state_broadcaster]: Loaded left_joint_state_broadcaster [spawner-2] [INFO] [1721305631.207880602] [spawner_left_joint_state_broadcaster]: Configured and activated left_joint_state_broadcaster [INFO] [spawner-2]: process has finished cleanly [pid 21169]
我可以确定的是我的命名空间没有问题,单独启动任意一个都是正常的。但是在启动第二个机械臂(left)出现了使用第一个机械臂(right)命名空间的情况,这个有可能是因为抢占资源引起的,但是我没有办法解决。
我在github上找到了几个解决方案但是因为对二进制编译和源码编译的不熟悉,我修改后出现了更大的错误。不知道作者有没有找到好的解决方案
附上我找到的解决方案链接:
https://github.com/ros-controls/ros2_control/issues/1177
https://github.com/ros-controls/ros2_control/pull/1391我在github上找到了几个解决方案但是因为对二进制编译和源码编译的不熟悉,我修改后出现了更大的错误。希望有大佬能够解答
PS:我将两个机械臂写在一个models里面是可以进行控制的,但是我目前的需求是在gazebo中有两个models
附上我找到的解决方案链接:
https://github.com/ros-controls/ros2_control/issues/1177
https://github.com/ros-controls/ros2_control/pull/1391 -
从您提供的错误信息和上下文来看,您遇到的问题似乎与在ROS 2的Gazebo环境中同时加载和配置两个独立的机器人(在这里是UR机械臂)的控制器有关。问题可能出在以下几个方面:
-
命名空间冲突:您已经注意到在启动第二个机械臂(left)时,似乎使用了第一个机械臂(right)的命名空间。这可能是由于在启动或配置第二个机械臂时,命名空间没有被正确设置或传递。确保在启动和配置第二个机械臂时,所有相关的节点、服务、参数和命名空间都是独立和明确的。
-
资源冲突:可能有两个或多个控制器试图使用相同的硬件资源(例如,URDF中定义的关节)。在这种情况下,您需要确保每个控制器仅访问其被授权访问的资源。
-
URDF/SRDF配置:确保每个机械臂的URDF/SRDF文件都是独立的,并且正确描述了各自的关节、链接和控制器接口。
-
启动顺序和参数传递:检查您的启动脚本和配置文件,确保在启动每个机械臂时都正确传递了所有必要的参数和命名空间。
-
硬件接口:
ros2_control
使用hardware_interface
来定义机器人硬件的接口。确保您的硬件接口配置对于每个机械臂都是唯一的,并且没有重复或冲突的接口。 -
ROS 2节点命名:ROS 2中的节点名称需要在整个系统中是唯一的。如果两个节点具有相同的名称,它们将无法正确通信。
针对您的情况,以下是一些可能的解决方案:
- 确保命名空间和参数文件是独立的:为每个机械臂创建单独的命名空间、URDF/SRDF文件和控制器配置文件。
- 修改启动脚本:在启动脚本中,为每个机械臂的
gazebo_ros2_control
插件和控制器管理器指定不同的命名空间。 - 检查URDF/SRDF文件:确保URDF/SRDF文件中定义的关节和链接名称在两个机械臂之间是唯一的,并且没有重复。
- 检查硬件接口配置:确保每个机械臂的硬件接口配置都是唯一的,并且没有冲突。
- 使用不同的节点名称:确保在ROS 2中启动的每个节点都具有唯一的名称。
最后,如果您对源码编译和二进制编译不熟悉,那么直接修改
ros2_control
或相关库的源码可能会引入更多的复杂性。在尝试这些高级操作之前,建议先确保您的配置和启动脚本是正确的,并且遵循了ROS 2和ros2_control
的最佳实践。如果问题仍然存在,考虑在ROS社区或相关论坛中寻求帮助。
以上为生成回答,仅供参考~
-
-
@小伊 命名空间不存在冲突,左右机械臂都可以单独运行。资源冲突并不是机械臂资源冲突,而是后一个启动的机械臂的gazebo_ros2_control plugin使用了前一个的gazebo_ros2_control plugin的命名空间导致资源冲突
-
您描述的问题似乎与ROS 2和Gazebo的集成使用中的命名空间冲突有关。当您在Gazebo中模拟两个或更多的机械臂,并且每个机械臂都使用
gazebo_ros2_control
插件时,确保每个插件都正确配置在它们自己的命名空间中是非常重要的。这里有几个步骤和建议,可以帮助您解决资源冲突问题:
-
明确命名空间:
- 确保每个机械臂在URDF或SDF文件中都有唯一的命名空间。
- 在启动文件中,为每个机械臂的ROS 2节点明确设置命名空间。
-
独立启动:
- 不要在一个启动文件中同时启动两个机械臂,除非您已经明确配置了它们的命名空间。
- 分别启动每个机械臂,以确保它们不会意外地共享资源或命名空间。
-
检查
gazebo_ros2_control
插件配置:- 在Gazebo的插件标签中,为每个
gazebo_ros2_control
插件指定正确的命名空间。 - 确保每个插件都加载了正确的参数文件,这些参数文件为控制器、状态发布器等定义了正确的命名空间。
- 在Gazebo的插件标签中,为每个
-
使用ROS 2的参数服务器:
- 如果您使用参数服务器来配置控制器,确保每个控制器都在其自己的命名空间中注册参数。
- 使用
ros2 param
命令来检查和修改参数,以确保它们位于正确的命名空间中。
-
查看ROS 2话题和服务:
- 使用
ros2 topic list
和ros2 service list
命令来查看正在发布的话题和提供的服务。 - 验证这些话题和服务是否都在它们应该存在的命名空间中。
- 使用
-
检查日志:
- 仔细检查ROS 2和Gazebo的日志文件,以查找任何关于命名空间或资源冲突的错误或警告。
-
清理和重置:
- 如果可能的话,在尝试新的配置或修复之前,完全关闭Gazebo和ROS 2,并清理任何可能残留的状态或配置。
-
参考文档和示例:
- 查阅
gazebo_ros2_control
、ROS 2和Gazebo的官方文档,以了解如何正确配置和使用这些工具。 - 查找并研究类似的示例或项目,以了解他们如何处理命名空间和多机械臂模拟。
- 查阅
-
社区支持:
- 如果您仍然遇到问题,考虑在ROS 2或Gazebo的社区论坛、GitHub仓库或邮件列表中寻求帮助。
通过遵循这些步骤和建议,您应该能够解决由命名空间冲突导致的资源冲突问题,并成功地在Gazebo中模拟多个机械臂。
以上为生成回答,仅供参考~
-
-
问题已解决,如需帮助请与我联系
-
@1393399898 您好,请问解决了命名空间后还需要做什么工作才可以正常运行?我现在是在humble的gazebo试图加载三台turtlebot3,下面是日志:
lab1@lab1-colorful:~/ros2_ws$ ros2 launch rl_turtlebot_launch multi_turtlebot3.launch.py [INFO] [launch]: All log files can be found below /home/lab1/.ros/log/2024-07-19-09-22-44-801730-lab1-colorful-263368 [INFO] [launch]: Default logging verbosity is set to INFO urdf_file_name : turtlebot3_waffle.urdf urdf_file_name : turtlebot3_waffle.urdf [INFO] [gzserver-1]: process started with pid [263381] [INFO] [gzclient-2]: process started with pid [263383] [INFO] [robot_state_publisher-3]: process started with pid [263385] [INFO] [spawn_entity.py-4]: process started with pid [263387] [INFO] [spawn_entity.py-5]: process started with pid [263389] [INFO] [spawn_entity.py-6]: process started with pid [263391] [spawn_entity.py-5] [INFO] [1721352166.060579777] [spawn_entity]: Spawn Entity started [spawn_entity.py-5] [INFO] [1721352166.060771871] [spawn_entity]: Loading entity XML from file /home/lab1/ros2_ws/install/rl_turtlebot_launch/share/rl_turtlebot_launch/urdf/turtlebot3_waffle.urdf [spawn_entity.py-5] [INFO] [1721352166.062016813] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-5] [INFO] [1721352166.062347773] [spawn_entity]: Waiting for service /spawn_entity [spawn_entity.py-6] [INFO] [1721352166.074252112] [spawn_entity]: Spawn Entity started [spawn_entity.py-6] [INFO] [1721352166.074442278] [spawn_entity]: Loading entity XML from file /home/lab1/ros2_ws/install/rl_turtlebot_launch/share/rl_turtlebot_launch/urdf/turtlebot3_waffle.urdf [spawn_entity.py-4] [INFO] [1721352166.074493023] [spawn_entity]: Spawn Entity started [spawn_entity.py-4] [INFO] [1721352166.074674658] [spawn_entity]: Loading entity XML from file /home/lab1/ros2_ws/install/rl_turtlebot_launch/share/rl_turtlebot_launch/urdf/turtlebot3_waffle.urdf [spawn_entity.py-6] [INFO] [1721352166.074846235] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-6] [INFO] [1721352166.074978259] [spawn_entity]: Waiting for service /spawn_entity [spawn_entity.py-4] [INFO] [1721352166.075055066] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-4] [INFO] [1721352166.075188369] [spawn_entity]: Waiting for service /spawn_entity [robot_state_publisher-3] [INFO] [1721352166.078197592] [robot_state_publisher]: got segment base_footprint [robot_state_publisher-3] [INFO] [1721352166.078255204] [robot_state_publisher]: got segment base_link [robot_state_publisher-3] [INFO] [1721352166.078259586] [robot_state_publisher]: got segment base_scan [robot_state_publisher-3] [INFO] [1721352166.078261874] [robot_state_publisher]: got segment camera_depth_frame [robot_state_publisher-3] [INFO] [1721352166.078264109] [robot_state_publisher]: got segment camera_depth_optical_frame [robot_state_publisher-3] [INFO] [1721352166.078266519] [robot_state_publisher]: got segment camera_link [robot_state_publisher-3] [INFO] [1721352166.078268708] [robot_state_publisher]: got segment camera_rgb_frame [robot_state_publisher-3] [INFO] [1721352166.078270838] [robot_state_publisher]: got segment camera_rgb_optical_frame [robot_state_publisher-3] [INFO] [1721352166.078273050] [robot_state_publisher]: got segment caster_back_left_link [robot_state_publisher-3] [INFO] [1721352166.078275165] [robot_state_publisher]: got segment caster_back_right_link [robot_state_publisher-3] [INFO] [1721352166.078277151] [robot_state_publisher]: got segment imu_link [robot_state_publisher-3] [INFO] [1721352166.078279245] [robot_state_publisher]: got segment wheel_left_link [robot_state_publisher-3] [INFO] [1721352166.078281434] [robot_state_publisher]: got segment wheel_right_link [spawn_entity.py-5] [INFO] [1721352166.569728255] [spawn_entity]: Calling service /spawn_entity [spawn_entity.py-6] [INFO] [1721352166.577600512] [spawn_entity]: Calling service /spawn_entity [spawn_entity.py-4] [INFO] [1721352166.578143401] [spawn_entity]: Calling service /spawn_entity [spawn_entity.py-5] [INFO] [1721352166.615479641] [spawn_entity]: Spawn status: Entity pushed to spawn queue, but spawn service timed outwaiting for entity to appear in simulation under the name [turtlebot3_waffle_2] [spawn_entity.py-5] [ERROR] [1721352166.615657547] [spawn_entity]: Spawn service failed. Exiting. [spawn_entity.py-6] [INFO] [1721352166.694504006] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [turtlebot3_waffle_3] [ERROR] [spawn_entity.py-5]: process has died [pid 263389, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -entity turtlebot3_waffle_2 -file /home/lab1/ros2_ws/install/rl_turtlebot_launch/share/rl_turtlebot_launch/urdf/turtlebot3_waffle.urdf -x 0.0 -y 0.0 -z 0.01 --ros-args']. [INFO] [spawn_entity.py-6]: process has finished cleanly [pid 263391] [spawn_entity.py-4] [INFO] [1721352166.920741484] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [turtlebot3_waffle_1] [INFO] [spawn_entity.py-4]: process has finished cleanly [pid 263387]
我在的rqt_graph界面没有显示预先规定的命名空间,所以我觉得我的launch文件可能存在一些问题:
def generate_launch_description(): launch_file_dir = os.path.join(get_package_share_directory('rl_turtlebot_launch'), 'launch') pkg_gazebo_ros = get_package_share_directory('gazebo_ros') use_sim_time = LaunchConfiguration('use_sim_time', default='true') world = os.path.join( get_package_share_directory('rl_turtlebot_launch'), 'worlds', 'lab.world' ) gzserver_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(pkg_gazebo_ros, 'launch', 'gzserver.launch.py') ), launch_arguments={'world': world}.items() ) gzclient_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py') ) ) robot_state_publisher_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(launch_file_dir, 'robot_state_publisher.launch.py') ), launch_arguments={'use_sim_time': use_sim_time}.items() ) spawn_turtlebot1_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(launch_file_dir, 'spawn_turtlebot3.launch.py') ), launch_arguments={ 'x_pose': '-2.0', 'y_pose': '-0.5', 'robot_name': 'turtlebot3_waffle_1' }.items() ) spawn_turtlebot2_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(launch_file_dir, 'spawn_turtlebot3.launch.py') ), launch_arguments={ 'x_pose': '0.0', 'y_pose': '0.0', 'robot_name': 'turtlebot3_waffle_2' }.items() ) spawn_turtlebot3_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(launch_file_dir, 'spawn_turtlebot3.launch.py') ), launch_arguments={ 'x_pose': '2.0', 'y_pose': '0.5', 'robot_name': 'turtlebot3_waffle_3' }.items() ) ld = LaunchDescription() # Add the commands to the launch description ld.add_action(gzserver_cmd) ld.add_action(gzclient_cmd) ld.add_action(robot_state_publisher_cmd) ld.add_action(spawn_turtlebot1_cmd) ld.add_action(spawn_turtlebot2_cmd) ld.add_action(spawn_turtlebot3_cmd) return ld```
-
@FantaTerry 您好,感谢您的提问
我和您的构件思路不同,但是我发现您的robot_state_publisher只启动了一次。我的两个机械臂均有各自的robot_state_publisher用于发布机器人状态,也使用命名空间进行区分,我不确定启动一次是否可以无冲突调用,所以我进行了区分,以下是我的部分launch代码:
left_robot_state_publisher_node = Node( package='robot_state_publisher', executable='robot_state_publisher', namespace='/left_ur_ft', output='both', parameters=[{"use_sim_time": True}, left_robot_description], ) right_robot_state_publisher_node = Node( package='robot_state_publisher', executable='robot_state_publisher', namespace='/right_ur_ft', output='both', parameters=[{"use_sim_time": True}, right_robot_description], )
希望能够帮到您