docker中使用ros2humble的rviz2不显示问题
这里写目录标题
- docker中使用ros2humble的rviz2不显示问题
- 删除 Docker 镜像和容器
- 删除 Docker 容器
- Linux服务器下查看系统CPU个数、核心数、(make编译最大的)线程数
- 总结:
- RVIZ2 不能显示数据集
- docker 对于image 重命名的问题
docker中使用ros2humble的rviz2不显示问题
问题描述:
root@9f20405a1baf:/# rviz2
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.Aborted (core dumped)
解答:
通过:export QT_DEBUG_PLUGINS=1
查看问题的具体显示,输出问题的内容形式如下:
root@020b7a1aa6d4:/fastlio2# rviz2
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.Aborted (core dumped)
root@020b7a1aa6d4:/fastlio2# cd ..
root@020b7a1aa6d4:/# export QT_DEBUG_PLUGINS=1
root@020b7a1aa6d4:/# ros2 run rivz2 rivz2
Package 'rivz2' not found
root@020b7a1aa6d4:/# ros2 run rviz2 rivz2
No executable found
root@020b7a1aa6d4:/# ros2 run rviz2 rviz2
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["eglfs"]},"archreq": 0,"className": "QEglFSIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["linuxfb"]},"archreq": 0,"className": "QLinuxFbIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["minimal"]},"archreq": 0,"className": "QMinimalIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["minimalegl"]},"archreq": 0,"className": "QMinimalEglIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["offscreen"]},"archreq": 0,"className": "QOffscreenIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["vnc"]},"archreq": 0,"className": "QVncIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["xcb"]},"archreq": 0,"className": "QXcbIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/ros/humble/lib/rviz2/platforms" ...
loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.[ros2run]: Aborted
root@020b7a1aa6d4:/# echo $DISPLAY root@020b7a1aa6d4:/#
exit
这里参考非常宝藏的社区解决方法
在宿主机中运行:
docker run -it -v /tmp/.X11-unix/:/tmp/.X11-unix/:rw --env=DISPLAY --name ros2_container osrf/ros:humble-desktop-full
解释:
-v /tmp/.X11-unix/:/tmp/.X11-unix/:rw :
-v 选项允许 Docker 将一个卷挂载到容器上,这样容器就能访问宿主机文件系统上的目录
/tmp/.X11-unix/ 是宿主机上由 X 服务器用于显示的一个目录
:/tmp/.X11-unix/ 是容器中挂载卷的位置,与宿主机上的目录相同
:rw 部分允许对卷进行读写访问,这对显示内容是必要的。
--env=DISPLAY
这个参数将宿主机的 DISPLAY 环境变量传递给容器。
DISPLAY 变量以启用可视化
这里我重点排查了一下:貌似是因为之前通过
docker image pull osrf/ros:humble-desktop-full
#拉取的镜像有些东西没有拉取成功 导致RVIZ2始终运行不成功
使得我又重新构建了一个container_ros2 !
docker run -it --name ros2_container osrf/ros:humble-desktop-full
接下来报错问题:
root@cf4125aa605c:/# ros2 run rviz2 rviz2
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["eglfs"]},"archreq": 0,"className": "QEglFSIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["linuxfb"]},"archreq": 0,"className": "QLinuxFbIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["minimal"]},"archreq": 0,"className": "QMinimalIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["minimalegl"]},"archreq": 0,"className": "QMinimalEglIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["offscreen"]},"archreq": 0,"className": "QOffscreenIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["vnc"]},"archreq": 0,"className": "QVncIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so, metadata=
{"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3","MetaData": {"Keys": ["xcb"]},"archreq": 0,"className": "QXcbIntegrationPlugin","debug": false,"version": 331520
}Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/ros/humble/lib/rviz2/platforms" ...
loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
No protocol specified
qt.qpa.xcb: could not connect to display :1
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.[ros2run]: Aborted
解决方法:
大概是没有同意通过docker容器访问宿主机的X服务器:
所以采取的方法为:宝藏解决方法
#执行:
export QT_DEBUG_PLUGINS=1 // 用来输出QT报错的完整信息
再次在docker中运行rviz2的节点
ros2 run rviz2 rviz2 #查看完整报错内容
echo $DISPLAY 判断是不是利用宿主机显示rviz2出现的问题
本地终端输入:
sudo xhost 然后按下回车
输入密码
出现下图:
再在docker中:
ros2 run rviz2 rviz2
成功展示界面:
这里要注意:你rviz2启动的container需要一致!!!
例如:我这里的docker image 存在多种:
但是这里只有ros2_container成功拉取了rviz2,所以 其他的仍然存在rviz2显示问题!!!(那就重新下载一下我的SDK相关包和依赖库)
删除 Docker 镜像和容器
我是个眼里不容沙子的人,没用的docker container需要选择删除
列出所有镜像以获取镜像的 ID
docker images -a
明确删除哪个镜像:
docker rmi <your-image-id>
操作如下:
sudo systemctl start docker
sudo systemctl enable dockerdocker images -a
docker rmi d2c94e258dcb
docker iamges -a
删除 Docker 容器
#停止所有正在运行的容器
docker ps -a //列出 所有容器 停止和未停止
docker ps //列出所有正在运行的容器
删除多个容器
docker rm $(docker ps -a -q)
#用来删除所有停止的容器
一般情况下:可以将线程数设置为CPU核心数的2倍
Linux服务器下查看系统CPU个数、核心数、(make编译最大的)线程数
# 查看CPU
lscpu #查看cpu的所有信息
#######################################################
root@cf4125aa605c:/Livox-SDK2/build# lscpu
Architecture: x86_64CPU op-mode(s): 32-bit, 64-bitAddress sizes: 46 bits physical, 48 bits virtualByte Order: Little Endian
CPU(s): 8On-line CPU(s) list: 0-7
Vendor ID: GenuineIntelModel name: Intel(R) Xeon(R) W-2223 CPU @ 3.60GHzCPU family: 6Model: 85Thread(s) per core: 2Core(s) per socket: 4Socket(s): 1Stepping: 7CPU max MHz: 3900.0000CPU min MHz: 1200.0000BogoMIPS: 7200.00Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida aratpln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization features: Virtualization: VT-x
Caches (sum of all): L1d: 128 KiB (4 instances)L1i: 128 KiB (4 instances)L2: 4 MiB (4 instances)L3: 8.3 MiB (1 instance)
NUMA: NUMA node(s): 1NUMA node0 CPU(s): 0-7
Vulnerabilities: Gather data sampling: Mitigation; MicrocodeItlb multihit: KVM: Mitigation: VMX disabledL1tf: Not affectedMds: Not affectedMeltdown: Not affectedMmio stale data: Mitigation; Clear CPU buffers; SMT vulnerableReg file data sampling: Not affectedRetbleed: Mitigation; Enhanced IBRSSpec rstack overflow: Not affectedSpec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccompSpectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitizationSpectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loopSrbds: Not affectedTsx async abort: Mitigation; TSX disabled
#######################################################
查看物理CPU数量
CPU物理核心就是计算机上实际配置的CPU个数:
cat /proc/cpuinfo |grep "physical id"|sort|uniq|wc -l#通过sort 列出cpu信息
grep 'physical id' /proc/cpuinfo | sort -u
逻辑CPU的个数
计算机没有开启超线程时,逻辑CPU的个数就是计算机的核数
超线程开启后,逻辑CPU的个数是核数的两倍
实际上逻辑CPU的数量就是平时称呼的几核几线程中的线程数量,在linux的cpuinfo中逻辑CPU数就是processor的数量
cat /proc/cpuinfo| grep "processor"| wc -l
grep 'physical id' /proc/cpuinfo
查看核心数量
每个物理CPU含有的核心个数。
cat /proc/cpuinfo| grep "cpu cores"| uniq
grep 'core id' /proc/cpuinfo | sort -u |wc -l
总核数 = 物理CPU个数 X 每颗物理CPU的核数
grep 'core id' /proc/cpuinfo |wc -l
查看线程数
cpu支持的线程数 = cpu数目 * 每个cpu含有的核心数目* 每个核心含有的线程数(64=2162)
CPU是一个影响编译速度的重要因素,所以make -j带上一个参数,可以把项目在进行中的并行编译,现在服务器上的CPU差不多都是多核多线程的,所以完全可以用make -j64,让make最多允许64个编译进程同时执行,这样可以更有效的利用CPU资源。
cat /proc/cpuinfo |grep "processor"|wc -l
grep 'processor' /proc/cpuinfo | sort -u | wc -l
grep 'processor' /proc/cpuinfo | wc -l
博主中线程数 : 64 = 2(physical cpu) * 16(cpu kernel number) * 2(每个核心是双核)
我的是卑微的8 所以 安装库的时候 每一个需要make -j的我都选择make -j8
总结:
pcl:没有选择安装,直接将pcl的include加入到相应的bashrc中-最终选择第二种方式
vim ~/.bashrc
export CPLUS_INCLUDE_PATH="/usr/include/pcl-1.12:$CPLUS_INCLUDE_PATH" #我是pcl-1.12
export LIBRARY_PATH="/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH"
Eigen:直接大片的**sudo apt install libeigen3-dev**
sophus:
git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout 1.22.10
mkdir build && cd build
cmake .. -DSOPHUS_USE_BASIC_LOGGING=ON
make
sudo make install
gtsam
#安装依赖
sudo apt-get install libboost-all-dev
sudo apt-get install cmake
sudo apt-get install libtbb-devgit clone https://github.com/borglab/gtsam.git
cd gtsam
mkdir build && cd build
cmake ..
make check (optional, runs unit tests)
make install
livox_ros_driver2
mkdir -r ws_livox/src
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2
cd ws_livox/src/livox_ros_driver2
source /opt/ros/humble/setup.sh
./build.sh humble
#在后面需要修改livox_ros_driver2_DIR
vim /FastLIO2_ws/src/FASTLIO2_ROS2/fastlio2/CMakeLists.txt
set(livox_ros_driver2_DIR /ws_livox/install/livox_ros_driver2/share/livox_ros_driver2/cmake)
RVIZ2 不能显示数据集
数据连接
首先在安装完成fastlio2需要的依赖库后,
mkdir -p /FastLIO2_ws/src && cd /FastLIO2_ws/src
git clone --recursive https://github.com/liangheming/FASTLIO2_ROS2.git
cd .. #这里colcon 需要在src目录下
colcon build --symlink-install. ./install/setup.bash #激活安装的fastlio2 node
问题:rviz2不能播放db3的rosbag数据
新开启一个终端
docker exec -it rose_container /bin/bash
source /opt/ros/humble/setup.bash
source /FastLIO2_ws/install/setup.bash
ros2 bag play FastLIO_ROS2_Data
问题解决:
需要在colcon build --symlink-install build fastlio2之前
一定要在colcon build --symlink-install 之前source /ws_livox/install/setup.bash!!!
source /ws_livox/install/setup.bash ###!!!!!!cd /FastLIO2_ws/colcon build --symlink-install ## !!!!. ./install/setup.bash ##!!!!
然后在按照上面的方法开启新的终端 ros2 bag play ors_bag_dir 最终能够成功播放数据集。
结果展示!
docker 对于image 重命名的问题
# docker中存在的images
docker images
#利用docker tag image_id name 改变标签
docker tag 6275fe5bc093 humble-discard
#docker images 查看刚刚更改姓名的docker image
#删除改姓名之前的docker
docker rmi osrf/ros:humble-desktop #docker rmi image_unchanged_name:tag
#docker images
docker 重命名参考