Custom panel plugin not being found when running rviz2
I have tried to create a custom ros2 package that will be a panel plugin for rivz2, by following information from "User's Guide to plugin development" as well as "Creating a ROS 2 package" but when running rviz2 it is not finding my custom plugin. I expect to find the custom panel in the rviz GUI under Panels --> Add New Panel but there is nothing there. How can I ensure that the plugin is found by rviz when it is running, any suggestions would be helpful!
The package is successfully built with colcon and when running ros2 pkg list
I have verified that ros2 finds the custom package, my_panel_plugin, but I haven't found any other way of troubleshooting what the issue could be.
I also tried running rviz with debug flag
ros2 run rviz2 rviz2 __log_level:=debug
but my only conclusion from that is that my custom plugin is not being found by the plugin loader in the same way as eg. the rviz_default_plugins.
According to the documentation linked above I need to invoke the PLUGINLIB_EXPORT_CLASS
macro for the plugin loader to find the plugin. I believe I have done this correctly but see the related files for reference, CMakeLists.txt
, package.xml
and plugin_description.xml
.
ROS enviroment variables
ROS_PYTHON_VERSION=3
ROS_VERSION_NAME=dashing
ROS_DISTRO=dashing
ROS_VERSION=2
File structure
├── rviz_plugins
│ └── my_panel_plugin
│ ├── CMakeLists.txt
│ ├── my_panel_plugin.cpp
│ ├── my_panel_plugin.h
│ ├── package.xml
│ └── plugin_description.xml
I've added
#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(sf::rviz_plugins::my_panel_plugin, rviz_common::Panel)
at the end of my_panel_plugin.cpp
.
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(my_panel_plugin)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(pluginlib REQUIRED)
include_directories(include)
# Qt5 boilerplate options from http://doc.qt.io/qt-5/cmake-manual.html
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_library(${PROJECT_NAME} SHARED
my_panel_plugin.cpp
)
# Link ament packages
ament_target_dependencies(${PROJECT_NAME} rclcpp rviz_common)
# Link non ament packages
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
# prevent pluginlib from using boost
target_compile_definitions(my_panel_plugin PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
install(TARGETS my_panel_plugin
DESTINATION lib/${PROJECT_NAME}
)
pluginlib_export_plugin_description_file(my_panel_plugin plugin_description.xml)
# replaces catkin_package(LIBRARIES ${PROJECT_NAME})
ament_export_libraries(${PROJECT_NAME})
ament_package()
package.xml
<package format="2">
<name>my_panel_plugin</name>
<version>0.0.1</version>
<description>This package adds a plugin to rviz2</description>
<maintainer email="you@example.com">Your Name</maintainer>
<license>Proprietary</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>rviz_common</depend>
<depend>libqt5-widgets</depend>
<depend>rviz2</depend>
<export>
<rviz plugin="plugin_description.xml"/>
<build_type>ament_cmake</build_type>
</export>
</package>
plugin_description.xml
<library path="lib/libmy_panel_plugin">
<class name="my_panel_plugin/My_panel_plugin"
type="sf::rviz_plugins::My_panel_plugin"
base_class_type="rviz_common::Panel">
<description>
My_panel_plugin
</description>
</class>
</library>
I'm also trying to develop a custom Panel and could not get it to be added to the list populated by "Add New Panel." Same with a custom Display. I was using the debian ros-eloquent-desktop install.
I switched to a source install https://index.ros.org/doc/ros2/Instal... to look at tackling the issue you pointed out (make sure to resource and that /opt/ros/eloquent isn't still in your AMENT_PREFIX_PATH, and/or just sudo apt remove ros-eloquent-*), and now my package's custom panel and display are showing up in the dialogs as expected.
tuser are you using the debians or a source install?
I'm using debian packages so trying to install from source could be worth trying. Do you have any idea why using a source install solved your issue?
I should probably also upgrade to using eloquent.
Unfortunately I do not have an idea of why they would behave differently. Looking at the apt show version for my debian install and the eloquent branches for rviz2 and pluginlib, little has been committed to these two libraries.
https://github.com/ros2/rviz/commits/...
https://github.com/ros/pluginlib/comm...
So it could be a packaging problem or there is another package with significant changes from the debian release I did not consider.
I will proceed with an alternative solution not using rviz plugins for now. But thanks for the help, if I have time to revisit this I will try your suggestion.