当你利用launch文件打开gazebo时,遇到模型出不来

这时:

        你一定要观察代码的报错情况。

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用 `roslaunch` 启动机器人模型前,需要先安装 Gazebo 和机器人模型相关的包,例如: ``` sudo apt-get install ros-<distro>-gazebo-ros-pkgs ros-<distro>-gazebo-ros-control sudo apt-get install ros-<distro>-turtlebot3-* ``` 其中 `<distro>` 是 ROS 版本号,例如 `melodic`。 接下来,创建一个 launch 文件,例如 `turtlebot3_gazebo.launch`,内容如下: ```xml <launch> <!-- 启动 Gazebo --> <include file="$(find gazebo_ros)/launch/empty_world.launch"> <arg name="world_name" value="$(find turtlebot3_gazebo)/worlds/turtlebot3_world.world"/> <arg name="paused" value="false"/> <arg name="use_sim_time" value="true"/> <arg name="gui" value="true"/> <arg name="headless" value="false"/> </include> <!-- 启动机器人模型 --> <arg name="model" default="burger"/> <arg name="x" default="0"/> <arg name="y" default="0"/> <arg name="z" default="0"/> <arg name="yaw" default="0"/> <include file="$(find turtlebot3_gazebo)/launch/turtlebot3.launch.xml"> <arg name="model" value="$(arg model)"/> <arg name="x_pos" value="$(arg x)"/> <arg name="y_pos" value="$(arg y)"/> <arg name="z_pos" value="$(arg z)"/> <arg name="yaw" value="$(arg yaw)"/> </include> </launch> ``` 这个 launch 文件首先启动 Gazebo,然后再启动机器人模型。其中 `world_name` 指定了 Gazebo 的场景,`model` 指定了要启动的机器人模型类型(例如 `burger` 或 `waffle`),`x`、`y`、`z` 和 `yaw` 则指定了机器人模型在场景中的初始位置和姿态。 最后,在终端中运行以下命令启动机器人模型: ``` roslaunch turtlebot3_gazebo turtlebot3_gazebo.launch ``` 注意,需要使用正确的包名和 launch 文件名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值