问题描述:
系统:虚拟机16 ubuntu18.04 ros1
根据例程(精通ROS机器人编程或古月的书)编写rviz_teleop_commander插件,静态编译通过,运行rosrun rviz rviz 正常打开,加载rviz_teleop_commander rviz 时 rviz直接崩了,终端显示core dump 。
最后发现是Cmakelist中qt版本的问题
将原本的(以下代码复制来自 ROS探索总结(三十四)——rviz plugin - 古月居)
当然, CMakeLists.txt文件也必须要加入相应的编译规则:
<span style="color:#000000">## This plugin includes Qt widgets, so we must include Qt like so:
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})
## I prefer the Qt signals and slots to avoid defining "emit", "slots",
## etc because they can conflict with boost signals, so define QT_NO_KEYWORDS here.
add_definitions(-DQT_NO_KEYWORDS)
## Here we specify which header files need to be run through "moc",
## Qt's meta-object compiler.
qt4_wrap_cpp(MOC_FILES
src/teleop_pad.h
)</span>
将以上复制关于qt4代码改为以下qt5后 ,运行rviz 并加载插件 正常运行。
find_package(Qt5 REQUIRED Core Widgets)
set(QT_LIBRARIES Qt5::Widgets)
include_directories(${catkin_INCLUDE_DIRS})
add_definitions(-DQT_NO_KEYWORDS)
qt5_wrap_cpp(MOC_FILES
src/teleop_pad.h)
RVIZ plugin插件开发过程中注意问题二:
plugin_description.xml中
<library path="lib/librviz_teleop_commander"> #注意lib后边直接加包名无空格
<class name="rviz_teleop_commander/TeleopPanel" #注意要和.h文件中的namespace保持一致
type="rviz_teleop_commander::TeleopPanel"#注意要和.h文件中的namespace保持一致
base_class_type="rviz::Panel">
<description>
A panel widget allowing simple diff-drive style robot base control.
</description>
</class>
</library>