小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
ROS2机器人开发书籍中6.4.4不发布话题的问题
-
问题描述:
我在学习第六章时成功创建了机器人模型,执行到6.4.4时一切正常,rviz中模型如下,但编辑gazebo_control_plugin.xacro,并修改fishbot.urdf.xacro增加6-38的代码后,进行重新构建 启动仿真后并没有6-39中的话题。
具体细节和上下文:
代码均为拷贝您提供的ros2bookcode
gazebo_control_plugin.xacro
<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:macro name="gazebo_control_plugin"> <gazebo> <plugin name='diff_drive' filename='libgazebo_ros_diff_drive.so'> <ros> <namespace>/</namespace> <remapping>cmd_vel:=cmd_vel</remapping> <remapping>odom:=odom</remapping> </ros> <update_rate>30</update_rate> <!-- wheels --> <left_joint>left_wheel_joint</left_joint> <right_joint>right_wheel_joint</right_joint> <!-- kinematics --> <wheel_separation>0.2</wheel_separation> <wheel_diameter>0.064</wheel_diameter> <!-- limits --> <max_wheel_torque>20</max_wheel_torque> <max_wheel_acceleration>1.0</max_wheel_acceleration> <!-- output --> <publish_odom>true</publish_odom> <publish_odom_tf>true</publish_odom_tf> <publish_wheel_tf>true</publish_wheel_tf> <odometry_frame>odom</odometry_frame> <robot_base_frame>base_footprint</robot_base_frame> </plugin> </gazebo> </xacro:macro> </robot>
fishbot.urdf.xacro
<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="fishbot"> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/base.urdf.xacro" /> <!-- 传感器组件 --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/imu.urdf.xacro" /> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/laser.urdf.xacro" /> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/camera.urdf.xacro" /> <!-- 执行器组件 --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/wheel.urdf.xacro" /> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/caster.urdf.xacro" /> <xacro:base_xacro length="0.12" radius="0.1" /> <!-- 传感器 --> <xacro:imu_xacro xyz="0 0 0.02" /> <xacro:laser_xacro xyz="0 0 0.10" /> <xacro:camera_xacro xyz="0.10 0 0.075" /> <!-- 执行器主动轮+从动轮 --> <xacro:wheel_xacro wheel_name="left" xyz="0 0.10 -0.06" /> <xacro:wheel_xacro wheel_name="right" xyz="0 -0.10 -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" /> <!-- Gazebo 插件 --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_control_plugin.xacro" /> <!-- <xacro:gazebo_control_plugin /> --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/fishbot.ros2_control.xacro" /> <xacro:fishbot_ros2_control /> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_sensor_plugin.xacro" /> <xacro:gazebo_sensor_plugin /> </robot>
重新构建与启动仿真
an@911:~/ros2bookcode/chapt6/chapt6_ws$ colcon build Starting >>> fishbot_description Finished <<< fishbot_description [0.09s] Summary: 1 package finished [0.23s] an@911:~/ros2bookcode/chapt6/chapt6_ws$ source install/setup.bash an@911:~/ros2bookcode/chapt6/chapt6_ws$ ros2 launch fishbot_description display_robot.launch.py model:=src/fishbot_description/urdf/fishbot/fishbot.urdf.xacro [INFO] [launch]: All log files can be found below /home/an/.ros/log/2024-09-12-19-13-09-487047-911-15696 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [joint_state_publisher-1]: process started with pid [15698] [INFO] [robot_state_publisher-2]: process started with pid [15700] [INFO] [rviz2-3]: process started with pid [15702] [robot_state_publisher-2] [INFO] [1726139589.623140879] [robot_state_publisher]: got segment back_caster_link [robot_state_publisher-2] [INFO] [1726139589.623268195] [robot_state_publisher]: got segment base_footprint [robot_state_publisher-2] [INFO] [1726139589.623274896] [robot_state_publisher]: got segment base_link [robot_state_publisher-2] [INFO] [1726139589.623278944] [robot_state_publisher]: got segment camera_link [robot_state_publisher-2] [INFO] [1726139589.623283379] [robot_state_publisher]: got segment camera_optical_link [robot_state_publisher-2] [INFO] [1726139589.623287257] [robot_state_publisher]: got segment front_caster_link [robot_state_publisher-2] [INFO] [1726139589.623291064] [robot_state_publisher]: got segment imu_link [robot_state_publisher-2] [INFO] [1726139589.623295333] [robot_state_publisher]: got segment laser_cylinder_link [robot_state_publisher-2] [INFO] [1726139589.623299037] [robot_state_publisher]: got segment laser_link [robot_state_publisher-2] [INFO] [1726139589.623302634] [robot_state_publisher]: got segment left_wheel_link [robot_state_publisher-2] [INFO] [1726139589.623306451] [robot_state_publisher]: got segment right_wheel_link [rviz2-3] [INFO] [1726139589.788711352] [rviz2]: Stereo is NOT SUPPORTED [rviz2-3] [INFO] [1726139589.788774003] [rviz2]: OpenGl version: 4.5 (GLSL 4.5) [joint_state_publisher-1] [INFO] [1726139589.822071202] [joint_state_publisher]: Waiting for robot_description to be published on the robot_description topic... [rviz2-3] [INFO] [1726139589.830594485] [rviz2]: Stereo is NOT SUPPORTED
显示的话题列表
an@911:~$ ros2 topic list /clicked_point /goal_pose /initialpose /joint_states /parameter_events /robot_description /rosout /tf /tf_static
显示的仿真模型
尝试过的解决方法:
搜索很多次没找到解决方法,不知道是不是缺少了哪步,还请点明错误
-
从您提供的描述和代码来看,您在尝试使用ROS 2和Gazebo来模拟一个机器人,并期望在仿真中看到特定的话题(如
/odom
),但实际上并没有看到这个话题。这里有几个可能的原因和解决方案:1. 检查Gazebo插件的加载
首先,确保
gazebo_control_plugin.xacro
中的插件确实被加载到了URDF模型中。从您提供的fishbot.urdf.xacro
文件来看,您已经包含了gazebo_control_plugin.xacro
,但没有显式调用<xacro:gazebo_control_plugin />
宏。虽然您可能通过其他方式(如fishbot_ros2_control.xacro
)隐式地包含了它,但最好还是确认一下。解决方案:
- 确保在URDF文件中正确调用了
<xacro:gazebo_control_plugin />
宏。 - 检查
fishbot_ros2_control.xacro
文件,看是否有任何可能影响插件加载的代码。
2. ROS 2 控制配置
由于您提到了
ros2_control
,确保您的控制配置是正确的。ros2_control
需要正确的硬件描述(通常通过YAML文件提供)和控制器配置(同样在YAML文件中)。解决方案:
- 检查是否有对应的控制器配置文件(如YAML文件),并确保它们被正确加载。
- 确保控制器节点正在运行,并且没有报告任何错误。
3. 重新构建和清理
有时,旧的构建文件可能会干扰新的构建。尝试清理您的构建目录并重新构建。
解决方案:
- 在工作空间目录中运行
colcon build --packages-select fishbot_description --symlink-install
来仅构建fishbot_description
包。 - 清理构建目录:
rm -rf build install log
,然后重新构建。
4. 检查Gazebo和ROS 2的日志
查看Gazebo和ROS 2的日志文件可能会提供更多关于为什么话题没有发布的线索。
解决方案:
- 查看
~/.ros/log/
目录下的ROS 2日志文件。 - 查看Gazebo的终端输出或日志文件,看是否有任何错误或警告。
5. 验证URDF和XACRO文件
使用
check_urdf
工具验证URDF文件是否没有错误。解决方案:
- 运行
ros2 run robot_state_publisher robot_state_publisher fishbot_description/urdf/fishbot/fishbot.urdf.xacro
,并使用check_urdf
命令来验证URDF。
6. 确保Gazebo和ROS 2的兼容性
确保您使用的Gazebo和ROS 2版本是兼容的。
解决方案:
- 查阅ROS 2和Gazebo的官方文档,确认您使用的版本是否相互兼容。
按照这些步骤检查和调整您的设置,您应该能够更接近问题的根源,并找到解决方案。如果问题仍然存在,您可能需要更详细地检查您的ROS 2控制配置或寻求来自ROS 2社区的帮助。
以上为生成回答,仅供参考~
- 确保在URDF文件中正确调用了
-
@1286588184 没看到有启动gazebo欸
-
-
是启动这个launch文件吗
an@911:~/ros2bookcode/chapt6$ ros2 launch fishbot_description gazebo_sim.launch.py [INFO] [launch]: All log files can be found below /home/an/.ros/log/2024-09-13-16-06-39-026307-911-4420 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [robot_state_publisher-1]: process started with pid [4422] [INFO] [gzserver-2]: process started with pid [4424] [INFO] [gzclient-3]: process started with pid [4426] [INFO] [spawn_entity.py-4]: process started with pid [4428] [robot_state_publisher-1] [INFO] [1726214799.434220248] [robot_state_publisher]: got segment back_caster_link [robot_state_publisher-1] [INFO] [1726214799.434303381] [robot_state_publisher]: got segment base_footprint [robot_state_publisher-1] [INFO] [1726214799.434308766] [robot_state_publisher]: got segment base_link [robot_state_publisher-1] [INFO] [1726214799.434311465] [robot_state_publisher]: got segment camera_link [robot_state_publisher-1] [INFO] [1726214799.434314019] [robot_state_publisher]: got segment camera_optical_link [robot_state_publisher-1] [INFO] [1726214799.434316513] [robot_state_publisher]: got segment front_caster_link [robot_state_publisher-1] [INFO] [1726214799.434318834] [robot_state_publisher]: got segment imu_link [robot_state_publisher-1] [INFO] [1726214799.434321177] [robot_state_publisher]: got segment laser_cylinder_link [robot_state_publisher-1] [INFO] [1726214799.434323514] [robot_state_publisher]: got segment laser_link [robot_state_publisher-1] [INFO] [1726214799.434325751] [robot_state_publisher]: got segment left_wheel_link [robot_state_publisher-1] [INFO] [1726214799.434328088] [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] [1726214799.722044380] [spawn_entity]: Spawn Entity started [spawn_entity.py-4] [INFO] [1726214799.722312098] [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] [1726214799.723847055] [spawn_entity]: Waiting for entity xml on /robot_description [spawn_entity.py-4] [INFO] [1726214799.735158585] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-4] [INFO] [1726214799.735467999] [spawn_entity]: Waiting for service /spawn_entity [spawn_entity.py-4] [INFO] [1726214800.492925943] [spawn_entity]: Calling service /spawn_entity [gzclient-3] [Msg] Waiting for master. [gzclient-3] [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [gzclient-3] [Msg] Publicized address: 10.139.109.189 [gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/an/.gazebo/models/.git" [gzserver-2] [Msg] Waiting for master. [gzserver-2] [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [gzserver-2] [Msg] Publicized address: 10.139.109.189 [gzserver-2] [Msg] Loading world file [/home/an/ros2bookcode/chapt6/install/fishbot_description/share/fishbot_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 [gzserver-2] [INFO] [1726214801.132406165] [depth_camera]: Publishing camera info to [/camera_sensor/camera_info] [gzserver-2] [INFO] [1726214801.132921282] [depth_camera]: Publishing depth camera info to [/camera_sensor/depth/camera_info] [gzserver-2] [INFO] [1726214801.133263243] [depth_camera]: Publishing pointcloud to [/camera_sensor/points] [spawn_entity.py-4] [INFO] [1726214801.196537173] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [fishbot] [gzserver-2] [Err] [Plugin.hh:212] Failed to load plugin libgazebo_ros2_control.so: libgazebo_ros2_control.so: cannot open shared object file: No such file or directory [INFO] [spawn_entity.py-4]: process has finished cleanly [pid 4428] [INFO] [ros2-5]: process started with pid [4632] [ros2-5] usage: ros2 [-h] [--use-python-default-buffering] [ros2-5] Call `ros2 <command> -h` for more detailed usage. ... [ros2-5] ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'control' (choose from 'action', 'bag', 'component', 'daemon', 'doctor', 'extension_points', 'extensions', 'interface', 'launch', 'lifecycle', 'multicast', 'node', 'param', 'pkg', 'run', 'security', 'service', 'topic', 'wtf') [ERROR] [ros2-5]: process has died [pid 4632, exit code 2, cmd 'ros2 control load_controller --set-state active fishbot_joint_state_broadcaster']. [INFO] [ros2-6]: process started with pid [4634] [ros2-6] usage: ros2 [-h] [--use-python-default-buffering] [ros2-6] Call `ros2 <command> -h` for more detailed usage. ... [ros2-6] ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'control' (choose from 'action', 'bag', 'component', 'daemon', 'doctor', 'extension_points', 'extensions', 'interface', 'launch', 'lifecycle', 'multicast', 'node', 'param', 'pkg', 'run', 'security', 'service', 'topic', 'wtf') [ERROR] [ros2-6]: process has died [pid 4634, exit code 2, cmd 'ros2 control load_controller --set-state active fishbot_diff_drive_controller']. [gzserver-2] [Wrn] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/pose/local/info, deleting message. This warning is printed only once.
现在是这样的
an@911:~$ ros2 topic list /camera_sensor/camera_info /camera_sensor/depth/camera_info /camera_sensor/depth/image_raw /camera_sensor/image_raw /camera_sensor/points /clicked_point /clock /goal_pose /imu /initialpose /joint_states /parameter_events /performance_metrics /robot_description /rosout /scan /tf /tf_static
-
@1286588184 你是跳着看的书吗,前面的装依赖之类的是不是没看和操作
-
我又试了一下,把这里的注释取消掉就正常出现cmd和odem话题了
<!-- Gazebo 插件 --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_control_plugin.xacro" /> <!-- <xacro:gazebo_control_plugin /> -->
an@911:~$ ros2 topic list /camera_sensor/camera_info /camera_sensor/depth/camera_info /camera_sensor/depth/image_raw /camera_sensor/image_raw /camera_sensor/points /clock /cmd_vel /imu /joint_states /odom /parameter_events /performance_metrics /robot_description /rosout /scan /tf /tf_static
不太明白这里为什么被注释了
这个代码我是直接下载的,一开始就是带注释的 -
@1286588184 在 ROS2机器人开发书籍中6.4.4不发布话题的问题 中说:
[Err] [Plugin.hh:212] Failed to load plugin libgazebo_ros2_control.so: libgazebo_ros2_control.so: cannot open shared object file: No such file or directory
这里的报错很明显了,没有安装依赖
-
@1286588184 建议跟着书操作,了解下代码为什么这么写和注释
-
@小鱼 我发现了这个,但书里没找到关于这个依赖的安装信息,只在6.4.2中提到安装gazebo依赖
n@911:~$ sudo apt install ros-humble-gazebo-ros-pkgs 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 ros-humble-gazebo-ros-pkgs 已经是最新版 (3.7.0-1jammy.20240820.174040)。 下列软件包是自动安装的并且现在不需要了: libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python-pkg-resources python-setuptools python2 python2-minimal python2.7 python2.7-minimal 使用'sudo apt autoremove'来卸载它(它们)。 升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 103 个软件包未被升级。
我安装了这个,上面报错显示的那个包我在文件夹里找到了,但就是不起作用,有什么办法吗,或者说书里具体哪里有讲这个
我是从第六章开始学的,之前一直跟着视频课的动手学ros2,正好学到机器人gazebo仿真出问题了,然后就从这本书的第六章开始学的
-
@1286588184 不是这个,书中应该还提到了ros2_control依赖
-
@1286588184 代码对应的是这章结束的代码,不是刚好6.4的,你运行的代码出现了第六章最后面才出现的内容
-
@小鱼 好的 感谢小鱼老师 我找到了 这章的代码我打算重新去理解编写 一步一步按书上来