执行6.5.2章节中关于ros2_control的代码时,发现输出端并没有显示从yaml文件读取参数,成功激活硬件的信息
-
我的系统是Ubuntu 22.04.5 LTS,ROS版本是humb,gazebo版本是Gazebo multi-robot simulator, version 11.10.2。
我现在遇到的问题是根据教材的代码构建并运行后,输出端没有显示任何关于ros2_control的信息,但是可以正常启动gazeb,并出现仿真画面。很奇怪是不是哪里有问题?
输出信息如下:[INFO] [launch]: All log files can be found below /home/fu/.ros/log/2024-12-27-11-52-51-747578-fu-23280 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [robot_state_publisher-1]: process started with pid [23284] [INFO] [gzserver-2]: process started with pid [23286] [INFO] [gzclient-3]: process started with pid [23288] [INFO] [spawn_entity.py-4]: process started with pid [23290] [robot_state_publisher-1] [INFO] [1735271572.162625006] [robot_state_publisher]: got segment back_caster_link [robot_state_publisher-1] [INFO] [1735271572.162683506] [robot_state_publisher]: got segment base_footprint [robot_state_publisher-1] [INFO] [1735271572.162686852] [robot_state_publisher]: got segment base_link [robot_state_publisher-1] [INFO] [1735271572.162689567] [robot_state_publisher]: got segment camera_link [robot_state_publisher-1] [INFO] [1735271572.162692122] [robot_state_publisher]: got segment camera_optical_link [robot_state_publisher-1] [INFO] [1735271572.162694707] [robot_state_publisher]: got segment front_caster_link [robot_state_publisher-1] [INFO] [1735271572.162697332] [robot_state_publisher]: got segment imu_link [robot_state_publisher-1] [INFO] [1735271572.162699846] [robot_state_publisher]: got segment laser_cylinder_link [robot_state_publisher-1] [INFO] [1735271572.162701880] [robot_state_publisher]: got segment laser_link [robot_state_publisher-1] [INFO] [1735271572.162703663] [robot_state_publisher]: got segment left_wheel_link [robot_state_publisher-1] [INFO] [1735271572.162705888] [robot_state_publisher]: got segment right_wheel_link [gzclient-3] Gazebo multi-robot simulator, version 11.10.2 [gzclient-3] Copyright (C) 2012 Open Source Robotics Foundation. [gzclient-3] Released under the Apache 2 License. [gzclient-3] http://gazebosim.org [gzclient-3] [gzserver-2] Gazebo multi-robot simulator, version 11.10.2 [gzserver-2] Copyright (C) 2012 Open Source Robotics Foundation. [gzserver-2] Released under the Apache 2 License. [gzserver-2] http://gazebosim.org [gzserver-2] [spawn_entity.py-4] [INFO] [1735271572.305556634] [spawn_entity]: Spawn Entity started [spawn_entity.py-4] [INFO] [1735271572.305681037] [spawn_entity]: Loading entity published on topic /robot_description [spawn_entity.py-4] /opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/qos.py:307: UserWarning: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL is deprecated. Use DurabilityPolicy.TRANSIENT_LOCAL instead. [spawn_entity.py-4] warnings.warn( [spawn_entity.py-4] [INFO] [1735271572.306448056] [spawn_entity]: Waiting for entity xml on /robot_description [spawn_entity.py-4] [INFO] [1735271572.317031674] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-4] [INFO] [1735271572.317141760] [spawn_entity]: Waiting for service /spawn_entity [gzserver-2] [Msg] Waiting for master. [gzserver-2] [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [gzserver-2] [Msg] Publicized address: 192.168.33.107 [gzserver-2] [Msg] Loading world file [/home/fu/CodeRepo/ros2_learning/dpg/ros2_/install/roobot_description/share/roobot_description/world/custom_room.world] [gzserver-2] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [spawn_entity.py-4] [INFO] [1735271572.819228429] [spawn_entity]: Calling service /spawn_entity [spawn_entity.py-4] [INFO] [1735271572.828264473] [spawn_entity]: Spawn status: Entity [fishbot] already exists. [spawn_entity.py-4] [ERROR] [1735271572.828491149] [spawn_entity]: Spawn service failed. Exiting. [ERROR] [spawn_entity.py-4]: process has died [pid 23290, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -topic /robot_description -entity fishbot --ros-args']. [gzserver-2] [INFO] [1735271573.651086500] [depth_camera]: Publishing camera info to [/camera_sensor/camera_info] [gzserver-2] [INFO] [1735271573.651313737] [depth_camera]: Publishing depth camera info to [/camera_sensor/depth/camera_info] [gzserver-2] [INFO] [1735271573.651438521] [depth_camera]: Publishing pointcloud to [/camera_sensor/points] [gzserver-2] [INFO] [1735271573.666764576] [diff_drive]: Wheel pair 1 separation set to [0.200000m] [gzserver-2] [INFO] [1735271573.666795775] [diff_drive]: Wheel pair 1 diameter set to [0.064000m] [gzserver-2] [INFO] [1735271573.667267269] [diff_drive]: Subscribed to [/cmd_vel] [gzserver-2] [INFO] [1735271573.668068553] [diff_drive]: Advertise odometry on [/odom] [gzserver-2] [INFO] [1735271573.668939407] [diff_drive]: Publishing odom transforms between [odom] and [base_footprint] [gzserver-2] [INFO] [1735271573.668950718] [diff_drive]: Publishing wheel transforms between [base_footprint], [left_wheel_joint] and [right_wheel_joint] [gzclient-3] [Msg] Waiting for master. [gzclient-3] [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [gzclient-3] [Msg] Publicized address: 192.168.33.107 [gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [INFO] [gzclient-3]: process has finished cleanly [pid 23288] [gzclient-3] [gzclient-3] ^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT) [robot_state_publisher-1] [INFO] [1735271703.216909016] [rclcpp]: signal_handler(signum=2) [gzserver-2] [Wrn] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/pose/local/info, deleting message. This warning is printed only once. [INFO] [robot_state_publisher-1]: process has finished cleanly [pid 23284] [INFO] [gzserver-2]: process has finished cleanly [pid 23286] [gzserver-2] [gzserver-2]
我看到里面提示fishbot已经存在,就尝试使用
ros2 service call /delete_entity gazebo_msgs/DeleteEntity "{name: fishbot}"
这个指令进行删除,但是好像没有用。 -
根据你提供的输出信息,有几个关键点需要注意,特别是关于
ros2_control
和 Gazebo 的集成部分。以下是一些可能的解决步骤和检查点:-
检查 YAML 文件是否被正确读取:
- 确保你的
ros2_control
配置文件(通常是.yaml
文件)被正确指定在启动文件中。这通常是通过设置参数服务器或者通过命令行参数来完成的。 - 你可以在 ROS 2 的参数服务器中查询相关参数来确认是否已正确加载。使用命令
ros2 param list
或ros2 param get /<node_name> <param_name>
来检查。
- 确保你的
-
确认
ros2_control
节点是否启动:- 在你的输出中,没有看到任何与
ros2_control
相关的节点启动信息。确保你的启动文件中包含了启动ros2_control
所需的所有节点,如controller_manager
、robot_state_publisher
(如果它负责发布/robot_description
),以及任何特定的控制器节点。 - 使用
ros2 node list
来查看当前运行的节点,确认ros2_control
的相关节点是否在运行。
- 在你的输出中,没有看到任何与
-
处理 Gazebo 中的实体重复问题:
- 输出中提到
"Spawn status: Entity [fishbot] already exists."
,这意味着尝试在 Gazebo 中添加一个已经存在的实体。这可能是因为之前的 Gazebo 实例没有正确关闭,或者你的启动脚本试图多次添加同一个实体。 - 使用
ros2 service call /gazebo/reset gazebo_msgs/srv/Reset "{}"
来重置 Gazebo 世界,这通常会删除所有实体。 - 确保在尝试重新添加实体之前,Gazebo 已经完全重置或重启。
- 输出中提到
-
检查
robot_description
话题:robot_state_publisher
通常需要从/robot_description
话题读取 URDF 或 XACRO 描述。确认这个话题是否被正确发布,并且包含了你期望的机器人描述。- 你可以使用
rostopic echo /robot_description
来查看发布的内容。
-
调试和日志:
- 增加日志的详细程度可以帮助识别问题。在启动文件中,你可以设置节点的日志级别为 DEBUG,以便获取更多信息。
- 检查
.ros/log
目录下的日志文件,可能会有更详细的错误信息或警告。
-
确保环境配置正确:
- 确保你的 ROS 2 工作空间已经正确构建,并且所有必要的包都已安装。
- 检查你的
setup.bash
或setup.zsh
是否已经正确 source。
通过上述步骤,你应该能够更接近问题的根源,并找到解决方案。如果问题仍然存在,可能需要更详细地检查你的配置文件和启动脚本。
以上为生成回答,仅供参考~
-
-
代码如下
----fishbot.ros2_control.xacro---<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros2.org/wiki/xacro"> <xacro:macro name="fishbot_ros2_control"> <ros2_control name="FishBotGazeboSystem" type="system"> <hardware> <plugin>gazebo_ros2_control/GazeboSystem</plugin> </hardware> <joint name="left_wheel_joint"> <command_interface name="velocity"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <command_interface name="effort"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <state_interface name="position"/> <state_interface name="velocity"/> <state_interface name="effort"/> </joint> <joint name="right_wheel_joint" > <command_interface name="velocity"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <command_interface name="effort"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <state_interface name="position"/> <state_interface name="velocity"/> <state_interface name="effort"/> </joint> <gazebo> <plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control"> <parameters>$(find roobot_description)/config/fishbot_ros2_controller.yaml</parameters> </plugin> </gazebo> </ros2_control> </xacro:macro> </robot>
#fishbot.urdf.xacro <?xml version="1.0" encoding="UTF-8"?> <robot name="fishbot" xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:include filename="$(find roobot_description)/urdf/fishbot/base.urdf.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/sensor/imu.urdf.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/sensor/laser.urdf.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/sensor/camera.urdf.xacro" /> <xacro:include filename="$(find roobot_description)/urdf/fishbot/actuator/caster.urdf.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/actuator/wheel.urdf.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/plugins/gazebo_control_plugins.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/plugins/gazebo_sensor_plugin.xacro"/> <xacro:include filename="$(find roobot_description)/urdf/fishbot/fishbot.ros2_control.xacro"/> <xacro:gazebo_sensor_plugin/> <!-- <xacro:gazebo_control_plugin/> --> <xacro:fishbot_ros2_control/> <xacro:base_xacro length="0.12" radius="0.1" /> <xacro:imu_xacro xyz="0 0 0.02"/> <xacro:laser_xacro xyz="0 0 0.1"/> <xacro:camera_xacro xyz="0.1 0.0 0.075"/> <xacro:wheel_xacro wheel_name="left" xyz="0.0 0.1 -0.06"/> <xacro:wheel_xacro wheel_name="right" xyz="0.0 -0.1 -0.06"/> <xacro:caster_xacro caster_name="front" xyz="0.08 0.0 -0.076"/> <xacro:caster_xacro caster_name="back" xyz="-0.08 0.0 -0.076"/> </robot>
-
执行ros2 param list的输出如下
ros2 param list /depth_camera: camera_sensor.depth.image_raw.enable_pub_plugins camera_sensor.image_raw.enable_pub_plugins qos_overrides./clock.subscription.depth qos_overrides./clock.subscription.durability qos_overrides./clock.subscription.history qos_overrides./clock.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability update_rate use_sim_time /diff_drive: qos_overrides./clock.subscription.depth qos_overrides./clock.subscription.durability qos_overrides./clock.subscription.history qos_overrides./clock.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability qos_overrides./tf.publisher.depth qos_overrides./tf.publisher.durability qos_overrides./tf.publisher.history qos_overrides./tf.publisher.reliability use_sim_time /gazebo: enable_performance_metrics publish_rate qos_overrides./clock.subscription.depth qos_overrides./clock.subscription.durability qos_overrides./clock.subscription.history qos_overrides./clock.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability use_sim_time /imu_plugin: qos_overrides./clock.subscription.depth qos_overrides./clock.subscription.durability qos_overrides./clock.subscription.history qos_overrides./clock.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability use_sim_time /laserscan: qos_overrides./clock.subscription.depth qos_overrides./clock.subscription.durability qos_overrides./clock.subscription.history qos_overrides./clock.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability use_sim_time /robot_state_publisher: frame_prefix ignore_timestamp publish_frequency qos_overrides./joint_states.subscription.depth qos_overrides./joint_states.subscription.history qos_overrides./joint_states.subscription.reliability qos_overrides./parameter_events.publisher.depth qos_overrides./parameter_events.publisher.durability qos_overrides./parameter_events.publisher.history qos_overrides./parameter_events.publisher.reliability qos_overrides./tf.publisher.depth qos_overrides./tf.publisher.durability qos_overrides./tf.publisher.history qos_overrides./tf.publisher.reliability qos_overrides./tf_static.publisher.depth qos_overrides./tf_static.publisher.history qos_overrides./tf_static.publisher.reliability robot_description use_sim_time
检查node的列表如下
$ ros2 node list /depth_camera /diff_drive /gazebo /imu_plugin /laserscan /robot_state_publisher
-
@noname 在 执行6.5.2章节中关于ros2_control的代码时,发现输出端并没有显示从yaml文件读取参数,成功激活硬件的信息 中说:
[spawn_entity.py-4] [INFO] [1735271572.828264473] [spawn_entity]: Spawn status: Entity [fishbot] already exists.
要看懂提示才行,你的world世界不干净,里面有机器人了,重新搞一个没有机器人的world
-
@小鱼 好的,谢谢。我当时尝试了直接在原图删除然后保存,但是没作用,没想到重新创建一个。