ROS2-humble下使用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], )
希望能够帮到您
-
@1393399898 您好,我最近也在做多机器人,请问您是怎么解决的
-
@1393399898 我也是遇到,第二个机器人的gazebo_ros2_control仍然使用第一个机器人的命名空间,我试过很多办法都没法解决
-
@guoshanqi 非常抱歉这么久才回复您
我使用的方式是在github下载ros2的包重新编译安装,不使用二进制安装,例如:control,controller,control_msgs,control_toolbox,gazebo_ros2_control等一系列包,除此之外,还有ur机械臂的包和realsense相机的包。这些包在几乎每周都在更新版本,而二进制安装的版本还是非常过时。
我将这些包直接编译安装在系统下(/opt/ros/humble),没有试过放在项目中,不确定放在项目中是否会成功。因此,这就改变了系统原有的依赖,可能会造成其他项目无法正常执行,因此在这之前请慎重考虑,使用二进制重新安装即可回退。我目前没有其他更好的解决方式
希望能够帮助到您
-
@1393399898 你好有具体解决教程吗我也是这个问题控制器明明已经区分空间但节点还是会重复
-
@wind2918 在项目代码方面没有什么改动,我是重新编译了ros2下的系统功能包,在之前已经介绍过这种方式的利弊,您可也翻阅一下。
造成这个问题的主要原因是:二进制安装(apt install)的ros2系统功能包(主要为controller_manager等)重复使用,这一点目前还无法通过修改自己的项目代码解决。但是在github中这部分已经进行了更新,二进制安装中还没有被更新,所以我们需要下载源码然后编译。我为了方便使用,将编译后的文件添加到了系统文件夹下(https://blog.csdn.net/m0_60346726/article/details/132858862)。
希望能够帮助到您
-
@1393399898 可以再发一下这个教程吗,这个显示打不开了,万分感谢
-
@wind2918 这个不是完整教程,这个只是将编译文件添加到系统文件夹下。完整操作你需要参考我之前发的回答,评估自己需要重新编译的功能包。以及安装时的注意事项
-
@1393399898 非常感谢你的帮助我现在已经解决了,这个问题困扰我很久