@fcnb 请问解决了吗,遇到一样的问题一直没解决
虚拟机使用VM,系统乌班图22.04
d05a7d8c-33b3-4f47-b9c4-22b0e579be28-image.png
ub@ub-virtual-machine:~/chapt6/chapt6_ws$ ros2 launch fishbot_description gazebo_sim.launch.py
[INFO] [launch]: All log files can be found below /home/ub/.ros/log/2025-07-16-20-10-55-594522-ub-virtual-machine-4590
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [4595]
[INFO] [gzserver-2]: process started with pid [4597]
[INFO] [gzclient-3]: process started with pid [4599]
[INFO] [spawn_entity.py-4]: process started with pid [4601]
[robot_state_publisher-1] [INFO] [1752667856.267970093] [robot_state_publisher]: got segment back_caster_link
[robot_state_publisher-1] [INFO] [1752667856.268156632] [robot_state_publisher]: got segment base_footprint
[robot_state_publisher-1] [INFO] [1752667856.268172869] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1752667856.268181356] [robot_state_publisher]: got segment camera_link
[robot_state_publisher-1] [INFO] [1752667856.268188438] [robot_state_publisher]: got segment camera_optical_link
[robot_state_publisher-1] [INFO] [1752667856.268195597] [robot_state_publisher]: got segment front_caster_link
[robot_state_publisher-1] [INFO] [1752667856.268202887] [robot_state_publisher]: got segment imu_link
[robot_state_publisher-1] [INFO] [1752667856.268209962] [robot_state_publisher]: got segment laser_cylinder_link
[robot_state_publisher-1] [INFO] [1752667856.268216871] [robot_state_publisher]: got segment laser_link
[robot_state_publisher-1] [INFO] [1752667856.268223440] [robot_state_publisher]: got segment left_wheel_link
[robot_state_publisher-1] [INFO] [1752667856.268230619] [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] [1752667856.804856341] [spawn_entity]: Spawn Entity started
[spawn_entity.py-4] [INFO] [1752667856.805229257] [spawn_entity]: Loading entity published on topic /robot_description
[spawn_entity.py-4] [INFO] [1752667856.807024211] [spawn_entity]: Waiting for entity xml on /robot_description
[gzserver-2] [Wrn] [gazebo_ros_init.cpp:178]
[gzserver-2] # # ####### ####### ### ##### #######
[gzserver-2] ## # # # # # # # #
[gzserver-2] # # # # # # # # #
[gzserver-2] # # # # # # # # #####
[gzserver-2] # # # # # # # # #
[gzserver-2] # ## # # # # # # #
[gzserver-2] # # ####### # ### ##### #######
[gzserver-2]
[gzserver-2] This version of Gazebo, now called Gazebo classic, reaches end-of-life
[gzserver-2] in January 2025. Users are highly encouraged to migrate to the new Gazebo
[gzserver-2] using our migration guides (https://gazebosim.org/docs/latest/gazebo_classic_migration?utm_source=gazebo_ros_pkgs&utm_medium=cli)
[gzserver-2]
[gzserver-2]
[spawn_entity.py-4] [INFO] [1752667856.911160252] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30
[spawn_entity.py-4] [INFO] [1752667856.911831738] [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.28.130
[gzserver-2] [Err] [RTShaderSystem.cc:480] Unable to find shader lib. Shader generating will fail. Your GAZEBO_RESOURCE_PATH is probably improperly set. Have you sourced <prefix>/share/gazebo/setup.bash?
[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.28.130
[gzclient-3] [Err] [RTShaderSystem.cc:480] Unable to find shader lib. Shader generating will fail. Your GAZEBO_RESOURCE_PATH is probably improperly set. Have you sourced <prefix>/share/gazebo/setup.bash?
[gzclient-3] [Wrn] [GuiIface.cc:120] Could not find the Qt platform plugin "wayland" in ""
[spawn_entity.py-4] [INFO] [1752667857.956423711] [spawn_entity]: Calling service /spawn_entity
[gzserver-2] [Msg] Loading world file [/home/ub/chapt6/chapt6_ws/install/fishbot_description/share/fishbot_description/world/custom_room.world]
[gzserver-2] [Err] [RenderEngine.cc:197] Failed to initialize scene
[gzserver-2] gzserver: /usr/include/boost/smart_ptr/shared_ptr.hpp:728: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = gazebo::rendering::Scene; typename boost::detail::sp_member_access<T>::type = gazebo::rendering::Scene*]: Assertion `px != 0' failed.
[ERROR] [gzserver-2]: process has died [pid 4597, exit code -6, cmd 'gzserver /home/ub/chapt6/chapt6_ws/install/fishbot_description/share/fishbot_description/world/custom_room.world --verbose -slibgazebo_ros_init.so -slibgazebo_ros_factory.so -slibgazebo_ros_force_system.so'].
[gzserver-2]
[gzclient-3] [Err] [Scene.cc:227] Service call[/shadow_caster_material_name] timed out
[gzclient-3] [Err] [Scene.cc:249] Service call[/shadow_caster_render_back_faces] timed out
[gzclient-3] [Err] [RenderEngine.cc:197] Failed to initialize scene
[gzclient-3] [Err] [GLWidget.cc:177] GLWidget could not create a scene. This will likely result in a blank screen.
[gzclient-3] gzclient: /usr/include/boost/smart_ptr/shared_ptr.hpp:728: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = gazebo::rendering::Camera; typename boost::detail::sp_member_access<T>::type = gazebo::rendering::Camera*]: 断言 "px != 0" 失败。
[ERROR] [gzclient-3]: process has died [pid 4599, exit code -6, cmd 'gzclient --gui-client-plugin=libgazebo_ros_eol_gui.so --verbose'].
[gzclient-3]
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[robot_state_publisher-1] [INFO] [1752667879.936981925] [rclcpp]: signal_handler(signum=2)
[spawn_entity.py-4] Traceback (most recent call last):
[spawn_entity.py-4] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 372, in <module>
[spawn_entity.py-4] main()
[spawn_entity.py-4] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 367, in main
[spawn_entity.py-4] exit_code = spawn_entity_node.run()
[spawn_entity.py-4] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 228, in run
[spawn_entity.py-4] success = self._spawn_entity(entity_xml, initial_pose, spawn_service_timeout)
[spawn_entity.py-4] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 290, in _spawn_entity
[spawn_entity.py-4] rclpy.spin_once(self)
[spawn_entity.py-4] File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/init.py", line 206, in spin_once
[spawn_entity.py-4] executor.spin_once(timeout_sec=timeout_sec)
[spawn_entity.py-4] File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 751, in spin_once
[spawn_entity.py-4] self._spin_once_impl(timeout_sec)
[spawn_entity.py-4] File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 740, in _spin_once_impl
[spawn_entity.py-4] handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
[spawn_entity.py-4] File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 723, in wait_for_ready_callbacks
[spawn_entity.py-4] return next(self._cb_iter)
[spawn_entity.py-4] File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 620, in _wait_for_ready_callbacks
[spawn_entity.py-4] wait_set.wait(timeout_nsec)
[spawn_entity.py-4] KeyboardInterrupt
[ERROR] [spawn_entity.py-4]: process has died [pid 4601, exit code -2, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -topic /robot_description -entity fishbot --ros-args'].
[INFO] [robot_state_publisher-1]: process has finished cleanly [pid 4595]
shaannj@shaannj-virtual-machine:~$ sudo apt install ros-humble-tf-transformations
[sudo] shaannj 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列【新】软件包将被安装:
ros-humble-tf-transformations
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 276 个软件包未被升级。
需要下载 19.6 kB 的归档。
解压缩后会消耗 110 kB 的额外空间。
错误:1 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu jammy/main amd64 ros-humble-tf-transformations amd64 1.1.0-1jammy.20250325.170033
404 Not Found [IP: 2402:f000:1:400::2 80]
E: 无法下载 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/pool/main/r/ros-humble-tf-transformations/ros-humble-tf-transformations_1.1.0-1jammy.20250325.170033_amd64.deb 404 Not Found [IP: 2402:f000:1:400::2 80]
E: 有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?
如题,楼主的ubuntu安装在win11的wsl2上,
numpy是安装在win系统中的,
但是根据AI,一般来说ros2调用numpy,会直接链接到ubuntu之外的numpy即win上的那个。
然后楼主根据AI的建议,重新设置了这个链接。
楼主问AI结果如下:
708ffdef-2232-49d7-a35f-c289188fd931-image.png
重新设置的代码如下。
555e9364-eba2-492b-b4f1-f627cc0fbbd8-image.png
起因:楼主正在学小鱼教程里手搓python节点的练习,colcon和source都正常,也已经安装了numpy,但是ros2 run 的时候报错。报错内容如下。
ros2 run village_li li4_node
Traceback (most recent call last):
File "/root/town_ws/install/village_li/lib/village_li/li4_node", line 33, in <module>
sys.exit(load_entry_point('village_li==0.0.0', 'console_scripts', 'li4_node')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/town_ws/install/village_li/lib/python3.12/site-packages/village_li/li4.py", line 7, in main
li4_node = Node('li4') # 创建节点
^^^^^^^^^^^
File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/node.py", line 240, in init
self._parameter_service = ParameterService(self)
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/parameter_service.py", line 35, in init
node.create_service(
File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/node.py", line 1725, in create_service
check_is_valid_srv_type(srv_type)
File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/type_support.py", line 51, in check_is_valid_srv_type
check_for_type_support(srv_type)
File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_or_srv_type.class.import_type_support()
File "/opt/ros/jazzy/lib/python3.12/site-packages/rcl_interfaces/srv/_describe_parameters.py", line 527, in import_type_support
_describe_parameters.Metaclass_DescribeParameters_Event.import_type_support()
File "/opt/ros/jazzy/lib/python3.12/site-packages/rcl_interfaces/srv/_describe_parameters.py", line 341, in import_type_support
from service_msgs.msg import ServiceEventInfo
File "/opt/ros/jazzy/lib/python3.12/site-packages/service_msgs/msg/init.py", line 1, in <module>
from service_msgs.msg._service_event_info import ServiceEventInfo # noqa: F401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ros/jazzy/lib/python3.12/site-packages/service_msgs/msg/_service_event_info.py", line 18, in <module>
import numpy # noqa: E402, I100
^^^^^^^^^^^^
ModuleNotFoundError: No module named 'numpy'
[ros2run]: Process exited with failure 1
希望各位大神帮帮忙呀!小仙什么都会做的(跪
项目地址:https://github.com/robomaster-oss/rmoss_gazebo.git
系统环境:
Ubuntu22.04
Ros2Humble
笔记本双系统,非ARM架构
缺少ros_gz_bridge这个包,尝试通过apt安装:sudo apt install ros-humble-ros-gz-bridge
报错
查看官网的文档,使用官方的推荐ROS2Humble下载方法:sudo apt-get install ros-${ROS_DISTRO}-ros-gz还是出现同样的报错
spaaaaace@spaaaaace-DRA-XX:~/Code/HBUT2025_rm_vision/lc_navigation/lc_navigation_2025/simulation_ws$ sudo apt-get install ros-${ROS_DISTRO}-ros-gz 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 没有可用的软件包 ros-humble-ros-gz,但是它被其它的软件包引用了。 这可能意味着这个缺失的软件包可能已被废弃, 或者只能在其他发布源中找到 E: 软件包 ros-humble-ros-gz 没有可安装候选尝试过换源,无果,求助
配置好雷达的wifi_ssid、wifi_pswd、server_ip,net_mode为默认的tcp
将跳帽修改到串口模式,跳帽接法如下图所示
8246065e-2fc2-4743-a448-47e4948113d9-图片.png
二、启动服务重新拉取docker镜像并启动服务
xhost + && sudo docker run -it --rm -p 8889:8889 -p 8889:8889/udp --privileged -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix --device /dev/snd -e DISPLAY=unix$DISPLAY registry.cn-hangzhou.aliyuncs.com/fishros/fishbot_laser启动完成后,可以看到如下界面
ef868a6c-a4fa-4053-ab72-79538b7c20fd-图片.png
三、驱动雷达保证雷达板在通电状态,
选择1驱动雷达,回车,
选择3有线串口,回车,
接着选择1 /dev/ttyUSB0。我们尝试驱动雷达
25d915a2-b360-4cab-9c6f-88a7d68c5561-图片.png
等待雷达连接,未连接成功请先检查跳线帽是否更换到串口模式
驱动成功后,我们可以打开一个新的终端,输入ros2 topic list,查看是否有scan话题。
ros2 topic list3fdbe9e5-f359-4ba2-8f79-48cecdb14cb6-图片.png
此时在终端中打开rviz2,
7b15222c-c0e4-4784-8b50-4760957a6e15-图片.png
修改fixed frame为laser_frame,左下角点击add---by topic,添加LaserScan,
cfc168a2-1435-4d0e-8e3c-de655e0c6a84-图片.png
接着修改Qos为Best Effort,接着就能看到雷达的点云数据了
移动雷达,观察点云的变化
2b11e0a1-dafc-4c29-b667-23621795211a-图片.png
四、手动建图测试使用Crtl+C,打断驱动的运行,回车,
选择4返回上级
选择2建图测试
选择3有线串口
选择1/dev/ttyUSB0
c6ff60e9-e0ff-43aa-8095-8119ed160de2-图片.png
等待片刻,你应该可以直接看到一张地图出现
ae323491-a053-42a4-89de-c5f51db9cb2b-图片.png
你可以将FishBot放到地上,或者用手拿着fishbot,慢慢走一圈,观察地图的变化,也可以直接用键盘控制节点(需要根据上节教程个启动Agent)控制fishbot走一圈,看看能否得到完整的地图。
d0503e59-b7f1-4b8e-8cdb-aa08b452b9b8-图片.png
我们需要使用一个叫做nav2_map_server的工具。
安装nav2_map_server
保存地图
ros2 run nav2_map_server map_saver_cli --help可以看到有下面的用法
Usage: map_saver_cli [arguments] [--ros-args ROS remapping args] Arguments: -h/--help -t <map_topic> -f <mapname> --occ <threshold_occupied> --free <threshold_free> --fmt <image_format> --mode trinary(default)/scale/raw NOTE: --ros-args should be passed at the end of command line我们的地图话题为map,文件名字我们用fishbot_map,所以有下面这个这样写的命令行。
ros2 run nav2_map_server map_saver_cli -t map -f fishbot_map
接着我们就可以得到下面的两个文件
这两个文件就是对当前地图保存下来的文件,其中.pgm是地图的数据文件,.yaml后缀的是地图的描述文件。
跳帽在flash模式下,扫描配置,修改net_mode为udp,针对建图卡顿网络问题优化,udp对网络差的环境有更好的兼容性
82d83fa2-6063-4ba9-b445-aac19b873472-图片.png
配置完成后,将跳线帽调整到WIFI模式
cdfb78a8-adeb-45d1-9949-c11d9d45b756-图片.png
三、启动服务重新拉取docker镜像并运行:
xhost + && sudo docker run -it --rm -p 8889:8889 -p 8889:8889/udp -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix --device /dev/snd -e DISPLAY=unix$DISPLAY registry.cn-hangzhou.aliyuncs.com/fishros/fishbot_laser启动完成后,可以看到如下页面
cc346c82-58de-441c-b770-9936d52d3b10-图片.png
四、驱动测试保证雷达板在通电状态
选择1驱动雷达,回车
选择2无线udp,回车,我们尝试驱动雷达
0bb1f40f-b525-455e-aa19-62b992e68ebb-图片.png
等待激光雷达udp连接
如果未连接成功,请检查是否符合下述现象和问题:
驱动成功后,我们可以打开一个新的终端,输入ros2 topic list,查看是否有/scan话题。 ros2 topic list
此时在终端中打开rviz2,修改fixed frame为laser_frame,左下角点击add---by topic,添加LaserScan,
c6ea58a3-0aab-4a9e-8a0f-bb00e894bea8-图片.png
接着修改Qos为Best Effort,接着就能看到雷达的点云数据了
移动雷达,观察点云的变化
f0e48929-c362-43bc-9909-5df28d01c4d2-图片.png
五、手动建图测试使用Crtl+C,打断驱动的运行,回车,
选择4返回上级
选择2建图测试
选择2无线udp
ae1b462f-0fe0-441e-91f1-86ba5a29567f-图片.png
等待片刻,你应该可以直接看到一张地图出现
a5cdca2e-f532-4a26-a6be-19c964720650-图片.png
你可以将FishBot放到地上,或者用手拿着fishbot,慢慢走一圈,观察地图的变化,也可以直接用键盘控制节点(需要根据上节教程个启动Agent)控制fishbot走一圈,看看能否得到完整的地图。
22bde3c5-5fee-4397-b669-1be9897ce4d3-图片.png
六、保存地图我们需要使用一个叫做nav2_map_server的工具。
安装nav2_map_server
保存地图
ros2 run nav2_map_server map_saver_cli --help可以看到有下面的用法
Usage: map_saver_cli [arguments] [--ros-args ROS remapping args] Arguments: -h/--help -t <map_topic> -f <mapname> --occ <threshold_occupied> --free <threshold_free> --fmt <image_format> --mode trinary(default)/scale/raw NOTE: --ros-args should be passed at the end of command line我们的地图话题为map,文件名字我们用fishbot_map,所以有下面这个这样写的命令行。
ros2 run nav2_map_server map_saver_cli -t map -f fishbot_map
接着我们就可以得到下面的两个文件
这两个文件就是对当前地图保存下来的文件,其中.pgm是地图的数据文件,.yaml后缀的是地图的描述文件。
配置助手配置雷达时net_mode默认为tcp
当配置完成后,需要将跳线帽调整到WIFI模式,这样雷达板将会把来自雷达的数据通过wifi转发给tcp服务。
0f1cc291-deda-42eb-a52c-46c6e30836d7-图片.png
调整完后,跳线帽接法如上图所示。
二、启动服务打开电脑,输入下面的指令,我们使用docker来下载雷达相关的驱动。
xhost + && sudo docker run -it --rm -p 8889:8889 -p 8889:8889/udp -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix --device /dev/snd -e DISPLAY=unix$DISPLAY registry.cn-hangzhou.aliyuncs.com/fishros/fishbot_laser下载完成后,你可以看到下面的界面
0c4c4005-51ee-422b-8f56-2711b4433c4b-图片.png
保持雷达板在通电状态,输入1,回车,选择1无线tcp,我们尝试驱动雷达
b808fcb5-5643-486f-95a5-3a2b57ecec37-图片.png
看到上述界面,表示驱动成功。
如果没有看到上述界面,请检查是否符合下述现象和问题:
驱动成功后,我们可以打开一个新的终端,输入ros2 topic list,查看是否有scan话题。 ros2 topic list
5426580f-7835-43ed-86cc-71c6362c61b6-图片.png
在rviz中可视化点云数据:
此时打开rviz2,左下角点击add---by topic,添加LaserScan,并修改fixed frame为laser_frame
96f93e0e-75cb-481e-8ee6-7ad521fa8b87-图片.png
修改Qos为Best Effort,接着就能看到雷达的点云数据了
移动雷达,观察点云的变化
f69d084e-b2d7-45f4-9fd5-83e2835a60bf-图片.png
使用Crtl+C,打断驱动的运行,回车,
选择4返回上级
选择2建图测试
选择1无线tcp
52ade1bc-f6d6-4bc7-ba28-2602093c240c-图片.png
等待片刻,你应该可以直接看到一张地图出现
f3cf1f46-c483-4c2e-8890-569c22f0ee3b-图片.png
你可以将FishBot放到地上,或者用手拿着fishbot,慢慢走一圈,观察地图的变化,也可以直接用键盘控制节点(需要根据上节教程个启动Agent)控制fishbot走一圈,看看能否得到完整的地图。
ef03f587-7142-4062-b0c0-ddb76fddc692-图片.png
我们需要使用一个叫做nav2_map_server的工具。
安装nav2_map_server
保存地图
ros2 run nav2_map_server map_saver_cli --help可以看到有下面的用法
Usage: map_saver_cli [arguments] [--ros-args ROS remapping args] Arguments: -h/--help -t <map_topic> -f <mapname> --occ <threshold_occupied> --free <threshold_free> --fmt <image_format> --mode trinary(default)/scale/raw NOTE: --ros-args should be passed at the end of command line我们的地图话题为map,文件名字我们用fishbot_map,所以有下面这个这样写的命令行。
ros2 run nav2_map_server map_saver_cli -t map -f fishbot_map
接着我们就可以得到下面的两个文件
这两个文件就是对当前地图保存下来的文件,其中.pgm是地图的数据文件,.yaml后缀的是地图的描述文件。
e509d2e7-d36f-4582-98f3-e057062825a2-图片.png
为什么下面一直在等待?
源码
import rclpy
from rclpy.node import Node
from chapt4_interfaces.srv import FaceDetector
import face_recognition
import cv2
from ament_index_python.packages import get_package_share_directory #获取功能包share目录绝对路径
import os
from cv_bridge import CvBridge
import time
class FaceDetectNode(Node):
def init(self):
super().init('face_detect_node')
self.service_ = self.create_service(FaceDetector,'face_detect',self.detect_face_callback)
self.bridge = CvBridge()
self.number_of_times_to_upsample = 1
self.model = 'hog'
self.default_image_path = os.path.join(get_package_share_directory('demo_python_service') ,'resource/default.jpeg')
self.get_logger().info("人脸检测服务已经启动!")
def main():
rclpy.init()
node = FaceDetectNode()
rclpy.spin(node)
rclpy.shutdown()
ls@ls-OMEN-Gaming-Laptop-16-ae0xxx:~/chapter6/chapter6_ws$ ros2 launch fishbot_description display_robot.launch.py
[INFO] [launch]: All log files can be found below /home/ls/.ros/log/2025-07-14-22-50-13-406014-ls-OMEN-Gaming-Laptop-16-ae0xxx-7918
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [7920]
[INFO] [joint_state_publisher-2]: process started with pid [7922]
[INFO] [rviz2-3]: process started with pid [7924]
[robot_state_publisher-1] [INFO] [1752504613.535700714] [robot_state_publisher]: got segment back_caster_link
[robot_state_publisher-1] [INFO] [1752504613.535768118] [robot_state_publisher]: got segment base_footprint
[robot_state_publisher-1] [INFO] [1752504613.535774413] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1752504613.535777807] [robot_state_publisher]: got segment camera_link
[robot_state_publisher-1] [INFO] [1752504613.535781003] [robot_state_publisher]: got segment front_caster_link
[robot_state_publisher-1] [INFO] [1752504613.535784553] [robot_state_publisher]: got segment imu_link
[robot_state_publisher-1] [INFO] [1752504613.535787920] [robot_state_publisher]: got segment laser_cylinder_link
[robot_state_publisher-1] [INFO] [1752504613.535791156] [robot_state_publisher]: got segment laser_link
[robot_state_publisher-1] [INFO] [1752504613.535794234] [robot_state_publisher]: got segment left_wheel_link
[robot_state_publisher-1] [INFO] [1752504613.535797336] [robot_state_publisher]: got segment right_wheel_link
[rviz2-3] /opt/ros/humble/lib/rviz2/rviz2: symbol lookup error: /snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0: undefined symbol: __libc_pthread_init, version GLIBC_PRIVATE
[ERROR] [rviz2-3]: process has died [pid 7924, exit code 127, cmd '/opt/ros/humble/lib/rviz2/rviz2 -d /home/ls/chapter6/chapter6_ws/install/fishbot_description/share/fishbot_description/config/rviz/display_model.rviz --ros-args'].
[joint_state_publisher-2] [INFO] [1752504613.756091603] [joint_state_publisher]: Waiting for robot_description to be published on the robot_description topic...
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[robot_state_publisher-1] [INFO] [1752504624.928440216] [rclcpp]: signal_handler(signum=2)
[INFO] [robot_state_publisher-1]: process has finished cleanly [pid 7920]
[INFO] [joint_state_publisher-2]: process has finished cleanly [pid 7922]
本人C++和python都会一点,不知道需不需要掌握两种语言的写法,就是ROS2的课程
ad3381ef-2366-4abc-9798-645de4ee123f-image.png
256985dd-084c-4c91-ada2-5aa90d9aa1b2-image.png
589e1f14-d6b7-43e2-97f2-d41befc2b719-image.png
这里有什么需要配置的吗
ls@ls-OMEN-Gaming-Laptop-16-ae0xxx:~/chapter6/chapter6_ws$ ros2 launch fishbot_description gazebo_sim.launch.py
[INFO] [launch]: All log files can be found below /home/ls/.ros/log/2025-07-14-19-31-02-736177-ls-OMEN-Gaming-Laptop-16-ae0xxx-43738
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [43741]
[INFO] [gzserver-2]: process started with pid [43743]
[INFO] [gzclient-3]: process started with pid [43745]
[INFO] [spawn_entity.py-4]: process started with pid [43747]
[robot_state_publisher-1] [INFO] [1752492663.155872124] [robot_state_publisher]: got segment back_caster_link
[robot_state_publisher-1] [INFO] [1752492663.155987358] [robot_state_publisher]: got segment back_wheel_link
[robot_state_publisher-1] [INFO] [1752492663.156001201] [robot_state_publisher]: got segment base_footprint
[robot_state_publisher-1] [INFO] [1752492663.156010853] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1752492663.156019436] [robot_state_publisher]: got segment camera_link
[robot_state_publisher-1] [INFO] [1752492663.156027798] [robot_state_publisher]: got segment front_caster_link
[robot_state_publisher-1] [INFO] [1752492663.156036241] [robot_state_publisher]: got segment imu_link
[robot_state_publisher-1] [INFO] [1752492663.156044576] [robot_state_publisher]: got segment laser_cylinder_link
[robot_state_publisher-1] [INFO] [1752492663.156052841] [robot_state_publisher]: got segment laser_link
[robot_state_publisher-1] [INFO] [1752492663.156060997] [robot_state_publisher]: got segment left_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]
[spawn_entity.py-4] Traceback (most recent call last):
[spawn_entity.py-4] File "/opt/ros/humble/lib/gazebo_ros/spawn_entity.py", line 31, in <module>
[spawn_entity.py-4] from lxml import etree as ElementTree
[spawn_entity.py-4] ModuleNotFoundError: No module named 'lxml'
[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]
[ERROR] [spawn_entity.py-4]: process has died [pid 43747, exit code 1, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -topic /robot_description -entity fishbot --ros-args'].
[gzserver-2] [Wrn] [gazebo_ros_init.cpp:178]
[gzserver-2] # # ####### ####### ### ##### #######
[gzserver-2] ## # # # # # # # #
[gzserver-2] # # # # # # # # #
[gzserver-2] # # # # # # # # #####
[gzserver-2] # # # # # # # # #
[gzserver-2] # ## # # # # # # #
[gzserver-2] # # ####### # ### ##### #######
[gzserver-2]
[gzserver-2] This version of Gazebo, now called Gazebo classic, reaches end-of-life
[gzserver-2] in January 2025. Users are highly encouraged to migrate to the new Gazebo
[gzserver-2] using our migration guides (https://gazebosim.org/docs/latest/gazebo_classic_migration?utm_source=gazebo_ros_pkgs&utm_medium=cli)
[gzserver-2]
[gzserver-2]
[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.197.145.93
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/Optical_flow"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/Sunflower"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/TensorRT"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/Test"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/YOLO"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/cartographer"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/define"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/final_reference"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/lidarteachws"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/omniverse"
[gzclient-3] [Err] [InsertModelWidget.cc:403] Missing model.config for model "/home/ls/Desktop/robotcontrol"
[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] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/user_camera/pose, deleting message. This warning is printed only once.
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[robot_state_publisher-1] [INFO] [1752492883.290270574] [rclcpp]: signal_handler(signum=2)
[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.197.145.93
[gzserver-2] [Msg] Loading world file [/home/ls/chapter6/chapter6_ws/install/fishbot_description/share/fishbot_description/world/custom_room.world]
[INFO] [robot_state_publisher-1]: process has finished cleanly [pid 43741]
[INFO] [gzserver-2]: process has finished cleanly [pid 43743]
[gzserver-2]
[gzserver-2]
[INFO] [gzclient-3]: process has finished cleanly [pid 43745]
[gzclient-3]
[gzclient-3]
通过网盘分享的文件:FishBot_VMware
链接: https://pan.baidu.com/s/1tVDm_pWtZ0m1XENqSAKLUg?pwd=fish 提取码: fish
--来自百度网盘超级会员v2的分享
1、下载网盘里的文件
a7bb14e0-6876-44a9-8f4c-85dbf659b4ad-image.png
2、打开VMware-workstation-full-17.5.2-23775571.exe,一直点击下一步,安装VMware。在最后一步完成时输入密钥,密钥为VM全版本许可证密钥里的VMware-workstation 17的密钥。
安装完成之后桌面上会有如下图标
14992647-5f13-4378-9109-77fc5f6bdfbe-image.png
3、解压网盘里的镜像文件压缩包
095bca56-ce46-486a-9391-011741d79a3e-image.png
4、双击点开VMware,在文件里面打开解压得到的Ubuntu22_FishBot
0b899981-1ccb-407c-a92d-408630e63035-image.png
e3abc024-40da-49e5-808a-eff512aeda56-image.png
5、打开之后会弹出导入虚拟机的弹窗,给虚拟机起一个名字,安排合适的路径
5fa6ea21-667e-4f4d-b2ff-39312bace706-image.png
设置完之后点击导入
6、导入之后,在编辑虚拟机设置里面可以修改内存大小,直接点击“开启此虚拟机”进入fishros的虚拟机,密码ros
59a3a74d-ec21-460c-a176-21b54bb289d6-image.png
主机无法接收到机器人的发送,通过tcpdump抓包,在主机向机器人发送数据时,两端都能够抓取到数据包,而机器人向主机发送时,仅在机器人端能够抓取到数据包。
想要完成在主机接受机身摄像头发布的图像数据,但是主机无法发现机器人发布的主题
安装mirco-ROS-Agent,colcon build时,出现如下错误
7fcd7191-e5ec-49f7-ad18-e878624fcd45-image.png
我的系统是ubuntu20.04,用的ros是galactic,我在同步之前录制了一个bag包,包含6个相机和一个激光雷达的信息系,下面是bag包的相关信息:
c606@ubuntu:~/fyx/data_bag$ ros2 bag info rosbag2_2025_07_10-03_25_26 Files: rosbag2_2025_07_10-03_25_26_0.db3 Bag size: 2.4 GiB Storage id: sqlite3 Duration: 17.252s Start: Jul 10 2025 03:25:28.197 (1752143128.197) End: Jul 10 2025 03:25:45.450 (1752143145.450) Messages: 999 Topic information: Topic: /rslidar_points | Type: sensor_msgs/msg/PointCloud2 | Count: 173 | Serialization Format: cdr Topic: /camera1/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 135 | Serialization Format: cdr Topic: /camera3/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 137 | Serialization Format: cdr Topic: /camera2/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 123 | Serialization Format: cdr Topic: /camera4/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 144 | Serialization Format: cdr Topic: /camera5/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 146 | Serialization Format: cdr Topic: /camera6/pylon_ros2_camera_node/image_raw | Type: sensor_msgs/msg/Image | Count: 141 | Serialization Format: cdr接着我写了一个功能包,作用是接受相机和雷达的话题,将话题内容同步后再以话题的形式发送出去,在写好节点代码后,我先通过命令ros2 run sys_time sys_time_node开启节点,再通过ros2 bag record -o synced_bag /clock $(ros2 topic list | grep "synced")命令开启录制,最后通过ros2 bag play rosbag2_2025_07_10-03_25_26 --loop --clock --read-ahead-queue-size 10000命令播放原始bag包。
在播放bag包后我发现同步节点的回调函数没有被调用,结束录制命令后我通过rqt_bag synced_bag命令查看时间戳,发现没有时间戳,这证明同步未进行或者同步失败了。
下面是我同步节点的运行日志:
c606@ubuntu:~/fyx/e2e_ws$ ros2 run sys_time sys_time_node
[INFO] [1752477350.845923197] [multi_sensor_sync]: 🚀 多传感器同步节点已启动 (ApproximateTime策略)
[WARN] [1752477359.044116748] []: Messages of type 6 arrived out of order (will print only once)
[WARN] [1752477376.810937820] []: Messages of type 3 arrived out of order (will print only once)
[WARN] [1752477376.825926258] []: Messages of type 0 arrived out of order (will print only once)
[WARN] [1752477376.831166002] []: Messages of type 2 arrived out of order (will print only once)
[WARN] [1752477376.840478915] []: Messages of type 5 arrived out of order (will print only once)
[WARN] [1752477376.891147241] []: Messages of type 1 arrived out of order (will print only once)
[WARN] [1752477377.102514764] []: Messages of type 4 arrived out of order (will print only once)
下面是我的同步节点代码:
#include <rclcpp/rclcpp.hpp> #include <sensor_msgs/msg/image.hpp> #include <sensor_msgs/msg/point_cloud2.hpp> #include <message_filters/subscriber.h> #include <message_filters/synchronizer.h> #include <message_filters/sync_policies/approximate_time.h> using ImageMsg = sensor_msgs::msg::Image; using PointCloud2Msg = sensor_msgs::msg::PointCloud2; class MultiSensorSync : public rclcpp::Node { public: MultiSensorSync() : Node("multi_sensor_sync") { // 增强QoS配置 auto qos = rclcpp::SensorDataQoS() .keep_last(20) // 增大缓存队列 .reliable() // 可靠传输模式 .durability_volatile(); // 允许历史数据 initPublishers(qos); initSubscribersAndSync(qos); RCLCPP_INFO(this->get_logger(), "🚀 多传感器同步节点已启动 (ApproximateTime策略)"); } private: void initPublishers(const rclcpp::QoS& qos) { for (int i = 0; i < 6; ++i) { cam_pubs_.push_back( this->create_publisher<ImageMsg>("/camera" + std::to_string(i+1) + "/synced/image_raw", qos) ); } lidar_pub_ = this->create_publisher<PointCloud2Msg>("/rslidar_points/synced", qos); } void initSubscribersAndSync(const rclcpp::QoS& qos) { // 创建相机订阅器 for (int i = 0; i < 6; ++i) { cam_subs_.push_back( std::make_shared<message_filters::Subscriber<ImageMsg>>( this, "/camera" + std::to_string(i+1) + "/pylon_ros2_camera_node/image_raw", qos.get_rmw_qos_profile() ) ); } // 创建雷达订阅器 lidar_sub_ = std::make_shared<message_filters::Subscriber<PointCloud2Msg>>( this, "/rslidar_points", qos.get_rmw_qos_profile() ); // 配置ApproximateTime策略 using SyncPolicy = message_filters::sync_policies::ApproximateTime< ImageMsg, ImageMsg, ImageMsg, ImageMsg, ImageMsg, ImageMsg, PointCloud2Msg>; // 创建同步器(增大时间窗口) sync_ = std::make_shared<message_filters::Synchronizer<SyncPolicy>>( SyncPolicy(50), // 队列大小增至50 *cam_subs_[0], *cam_subs_[1], *cam_subs_[2], *cam_subs_[3], *cam_subs_[4], *cam_subs_[5], *lidar_sub_ ); // 注册回调并绑定生命周期 sync_->registerCallback( std::bind(&MultiSensorSync::syncCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7 ) ); } void syncCallback( const ImageMsg::ConstSharedPtr& cam1, const ImageMsg::ConstSharedPtr& cam2, const ImageMsg::ConstSharedPtr& cam3, const ImageMsg::ConstSharedPtr& cam4, const ImageMsg::ConstSharedPtr& cam5, const ImageMsg::ConstSharedPtr& cam6, const PointCloud2Msg::ConstSharedPtr& lidar) { // 使用第一个相机的时间戳作为基准 //const auto& base_stamp = cam1->header.stamp; const auto& base_stamp = lidar->header.stamp; // 发布所有相机数据(统一时间戳) publishWithStamp(cam_pubs_[0], cam1, base_stamp); publishWithStamp(cam_pubs_[1], cam2, base_stamp); publishWithStamp(cam_pubs_[2], cam3, base_stamp); publishWithStamp(cam_pubs_[3], cam4, base_stamp); publishWithStamp(cam_pubs_[4], cam5, base_stamp); publishWithStamp(cam_pubs_[5], cam6, base_stamp); // 发布雷达数据(统一时间戳) auto new_lidar = std::make_shared<PointCloud2Msg>(*lidar); new_lidar->header.stamp = base_stamp; lidar_pub_->publish(*new_lidar); // 修复时间戳访问方式 RCLCPP_INFO(this->get_logger(), "🔥 同步发布 @ %d.%09d", base_stamp.sec, base_stamp.nanosec); } void publishWithStamp(rclcpp::Publisher<ImageMsg>::SharedPtr pub, const ImageMsg::ConstSharedPtr& msg, const builtin_interfaces::msg::Time& stamp) { auto new_msg = std::make_shared<ImageMsg>(*msg); new_msg->header.stamp = stamp; pub->publish(*new_msg); } // 成员变量 std::vector<rclcpp::Publisher<ImageMsg>::SharedPtr> cam_pubs_; std::vector<std::shared_ptr<message_filters::Subscriber<ImageMsg>>> cam_subs_; rclcpp::Publisher<PointCloud2Msg>::SharedPtr lidar_pub_; std::shared_ptr<message_filters::Subscriber<PointCloud2Msg>> lidar_sub_; using SyncPolicy = message_filters::sync_policies::ApproximateTime< ImageMsg, ImageMsg, ImageMsg, ImageMsg, ImageMsg, ImageMsg, PointCloud2Msg>; std::shared_ptr<message_filters::Synchronizer<SyncPolicy>> sync_; }; int main(int argc, char** argv) { rclcpp::init(argc, argv); rclcpp::executors::MultiThreadedExecutor executor; auto node = std::make_shared<MultiSensorSync>(); executor.add_node(node); executor.spin(); rclcpp::shutdown(); return 0; }最后还有一点,我录制的原始bag中相机和雷达的频率在10hz左右,下面是原始bag中的时间戳截图:
Screenshot from 2025-07-14 00-46-07.png
20463530-d3c1-4bc8-b699-776cafed8f9d-image.png
rviz显示如下8f421ede-a828-4232-a3b4-0ae7983716fe-image.png
rqt显示如下3dcb6256-528d-483f-8a24-980a0329e5b0-image.png
查看 map 无数据输出 odom无相关话题62e41c4b-f894-4f64-b0a6-5683e2b3e1bc-image.png
f468274a-ce94-4134-b849-ba15812a7b10-image.png
scan有输出8aedd05c-c5b2-43da-91db-7c65337983a7-image.png
851cdefd-0755-4a22-beeb-0a5c4212a9fe-image.png
42917dc4-86c4-4dce-9796-ecfb8cbe83f5-d0680705-af49-4751-90f3-d136d009ab53.png,出现了如下bug,怎么解决呢
版块
-
1.3k
主题4.9k
帖子 -
449
主题2.9k
帖子 -
67
主题260
帖子 -
1.1k
主题4.3k
帖子 -
1.0k
主题3.7k
帖子 -
5
主题11
帖子 -
358
主题1.6k
帖子