ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Custom panel plugin not being found when running rviz2

asked 2020-01-08 01:58:26 -0500

tuser gravatar image

updated 2020-01-10 00:26:23 -0500

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>
edit retag flag offensive close merge delete

Comments

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?

nbbrooks gravatar image nbbrooks  ( 2020-01-10 17:40:07 -0500 )edit

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.

tuser gravatar image tuser  ( 2020-01-13 00:47:41 -0500 )edit

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.

nbbrooks gravatar image nbbrooks  ( 2020-01-13 12:47:09 -0500 )edit

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.

tuser gravatar image tuser  ( 2020-01-15 06:34:14 -0500 )edit

3 Answers

Sort by » oldest newest most voted
3

answered 2020-01-24 11:23:00 -0500

updated 2020-01-24 11:52:27 -0500

I believe I have solved this issue. I believe your core problem is this line in your CMakeLists.txt:

pluginlib_export_plugin_description_file(my_panel_plugin plugin_description.xml)

It should be

pluginlib_export_plugin_description_file(rviz_common plugin_description.xml)

Otherwise it will not be detected by pluginlib loader. This talks about that briefly - I made a PR to fix the error in the rviz2 documentation you linked. When loading rviz plugins, it looks for files named "rviz_common__pluginlib__plugin" and does some discovery mechanics from there - the first part of that string is the first argument in pluginlib_export_plugin_description_file.

The second potential issue may be that you are not resourcing your workspace with your custom plugin after building. If you don't resource, the ament path will not include the built plugins, which prevents the above discovery mechanism from working.

Somewhat unrelated sidenote: as I was trying to reliably replicate issues/solutions, I was producing various subsets of my workspace in new workspaces. It took me a while to figure out it was still including non-sourced workspaces in my Ament path because of the way colcon chains workspaces together in each workspace's install/setup.bash file. Make sure to check $COLCON_PREFIX_PATH only lists your expected user workspaces (it should not include /opt) - if something is wrong, look at the $COLCON_CURRENT_PREFIX definitions in each sourced workspace's setup.bash. This drives the Ament path.

edit flag offensive delete link more

Comments

Thanks for looking into this, saw that you managed to get the documentation updated as well. I will try it and get back, hopefully this solves the issue for me.

Edit: Panel shows up in the menu! Thanks!

tuser gravatar image tuser  ( 2020-01-29 05:07:04 -0500 )edit
0

answered 2020-01-10 00:32:33 -0500

tuser gravatar image

It seems that custom plugins of panel type are not supported in rviz2 currently according to issue reported here:

https://github.com/ros2/rviz/issues/469

"... the plugin factory only loads the default builtin options without any functionality to load plugins of the panel type."

edit flag offensive delete link more
0

answered 2021-10-27 21:54:37 -0500

AndyZe gravatar image

updated 2021-10-28 09:16:10 -0500

Noting some other minor issues I see. This is for generic pluginlib plugins, not for RViz, so it might be a little different for RViz. My guide here is the pluginlib tutorial.

  • package.xml: <library path="lib/libmy_panel_plugin">

Should simply be "my_panel_plugin"

  • package.xml: Needs a <depend> on pluginlib
edit flag offensive delete link more

Question Tools

5 followers

Stats

Asked: 2020-01-08 01:58:26 -0500

Seen: 2,107 times

Last updated: Oct 28 '21