0
$\begingroup$

Rosanswers logo

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="[email protected]">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>

Originally posted by tuser on ROS Answers with karma: 28 on 2020-01-08

Post score: 1


Original comments

Comment by nbbrooks on 2020-01-10:
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/Installation/Eloquent/Linux-Install-Debians/ 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?

Comment by tuser on 2020-01-13:
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.

Comment by nbbrooks on 2020-01-13:
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/eloquent

https://github.com/ros/pluginlib/commits/eloquent

So it could be a packaging problem or there is another package with significant changes from the debian release I did not consider.

Comment by tuser on 2020-01-15:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by nbbrooks with karma: 56 on 2020-01-24

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by tuser on 2020-01-29:
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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.