这时:
你一定要观察代码的报错情况。
base) cp@cp-Legion-R7000P-ARH7:~/fishbot_ws/fishbot_description$ ros2 launch fishbot_description gazebo.launch.py
[INFO] [launch]: All log files can be found below /home/cp/.ros/log/2024-07-10-14-50-46-678403-cp-Legion-R7000P-ARH7-22729
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [gazebo-1]: process started with pid [22730]
[INFO] [spawn_entity.py-2]: process started with pid [22732]
[spawn_entity.py-2] Traceback (most recent call last):
[spawn_entity.py-2] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 31, in <module>
[spawn_entity.py-2] from lxml import etree as ElementTree
[spawn_entity.py-2] ModuleNotFoundError: No module named 'lxml'
[ERROR] [spawn_entity.py-2]: process has died [pid 22732, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -entity fishbot -file /home/cp/fishbot_ws/fishbot_description/install/fishbot_description/share/fishbot_description/urdf/fishbot_gazebo.urdf --ros-args'].
[gazebo-1] Gazebo multi-robot simulator, version 11.10.2
[gazebo-1] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-1] Released under the Apache 2 License.
[gazebo-1] http://gazebosim.org
[gazebo-1]
[gazebo-1] Gazebo multi-robot simulator, version 11.10.2
[gazebo-1] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-1] Released under the Apache 2 License.
[gazebo-1] http://gazebosim.org
[gazebo-1]
[gazebo-1] [INFO] [1720594247.399727506] [gazebo_ros_node]: ROS was initialized without arguments.
[gazebo-1] [Msg] Waiting for master.
[gazebo-1] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-1] [Msg] Publicized address: 192.168.2.15
[gazebo-1] [Msg] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[gazebo-1] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[gazebo-1] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[gazebo-1] [Msg] Waiting for master.
[gazebo-1] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-1] [Msg] Publicized address: 192.168.2.15
[gazebo-1] [Msg] Loading world file [/usr/share/gazebo/../../share/gazebo-11/worlds/empty.world]
[INFO] [gazebo-1]: process has finished cleanly [pid 22730]
[gazebo-1]
[gazebo-1]
这个的报错是:
spawn_entity.py-2] ModuleNotFoundError: No module named 'lxml'
[ERROR] [spawn_entity.py-2]: process has died [pid 22732, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -entity fishbot -file
错误信息是 ModuleNotFoundError: No module named 'lxml'
,说明你的系统缺少 lxml
这个Python库。
解决办法:
pip install lxml
如果是
(base) cp@cp-Legion-R7000P-ARH7:~/fishbot_ws/fishbot_description$ ros2 launch fishbot_description gazebo.launch.py
[INFO] [launch]: All log files can be found below /home/cp/.ros/log/2024-07-10-15-27-36-291074-cp-Legion-R7000P-ARH7-24464
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [gazebo-1]: process started with pid [24465]
[INFO] [spawn_entity.py-2]: process started with pid [24467]
[gazebo-1] Gazebo multi-robot simulator, version 11.10.2
[gazebo-1] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-1] Released under the Apache 2 License.
[gazebo-1] http://gazebosim.org
[gazebo-1]
[spawn_entity.py-2] [INFO] [1720596456.664649068] [spawn_entity]: Spawn Entity started
[spawn_entity.py-2] [INFO] [1720596456.664917558] [spawn_entity]: Loading entity XML from file /home/cp/fishbot_ws/fishbot_description/install/fishbot_description/share/fishbot_description/urdf/fishbot_gazebo.urdf
[spawn_entity.py-2] Traceback (most recent call last):
[spawn_entity.py-2] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 370, in <module>
[spawn_entity.py-2] main()
[spawn_entity.py-2] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 365, in main
[spawn_entity.py-2] exit_code = spawn_entity_node.run()
[spawn_entity.py-2] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 143, in run
[spawn_entity.py-2] self.get_logger().error('Error: specified file %s does not exist', self.args.file)
[spawn_entity.py-2] TypeError: RcutilsLogger.error() takes 2 positional arguments but 3 were given
[gazebo-1] Gazebo multi-robot simulator, version 11.10.2
[gazebo-1] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-1] Released under the Apache 2 License.
[gazebo-1] http://gazebosim.org
[gazebo-1]
[ERROR] [spawn_entity.py-2]: process has died [pid 24467, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -entity fishbot -file /home/cp/fishbot_ws/fishbot_description/install/fishbot_description/share/fishbot_description/urdf/fishbot_gazebo.urdf --ros-args'].
[gazebo-1] [INFO] [1720596457.293746157] [gazebo_ros_node]: ROS was initialized without arguments.
[gazebo-1] [Msg] Waiting for master.
[gazebo-1] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-1] [Msg] Publicized address: 192.168.2.15
[gazebo-1] [Msg] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[gazebo-1] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[gazebo-1] [Wrn] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/user_camera/pose, deleting message. This warning is printed only once.
[gazebo-1] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[gazebo-1] [Msg] Waiting for master.
[gazebo-1] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-1] [Msg] Publicized address: 192.168.2.15
[gazebo-1] [Msg] Loading world file [/usr/share/gazebo/../../share/gazebo-11/worlds/empty.world]
[ERROR] [gazebo-1]: process has died [pid 24465, exit code 255, cmd 'gazebo --verbose -s libgazebo_ros_factory.so'].
[gazebo-1]
[gazebo-1]
错误情况:
[spawn_entity.py-2] self.get_logger().error('Error: specified file %s does not exist', self.args.file)
[spawn_entity.py-2] TypeError: RcutilsLogger.error() takes 2 positional arguments but 3 were given
文件中出现了 TypeError: RcutilsLogger.error() takes 2 positional arguments but 3 were given
这个错误。这表明你的代码在调用 RcutilsLogger.error()
方法时传递了不正确的参数数量。
解决办法:
一,确认文件路径正确:
确保文件 /home/cp/fishbot_ws/fishbot_description/install/fishbot_description/share/fishbot_description/urdf/fishbot_gazebo.urdf
实际存在。
我的情况是最后一个文件fishbot_gazebo.urdf
不正确,不是gazebo而是base,重命名之后可以运行。
二,检查并修改 spawn_entity.py
文件:
sudo nano /opt/ros/humble/lib/gazebo_ros/spawn_entity.py
找到:
self.get_logger().error('Error: specified file %s does not exist', self.args.file)
改为
self.get_logger().error(f'Error: specified file {self.args.file} does not exist')
再运行:
ros2 launch fishbot_description gazebo.launch.py