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

Unable to assign slot to rviz property with custom namespace

asked 2021-06-15 10:04:29 -0500

Weasfas gravatar image

updated 2022-03-25 17:36:05 -0500

lucasw gravatar image

Hi all,

I am implementing a custom rviz tool for a certain task, the tool is already working properly and I came up with no errors during the plugin generation. However, when I try to assign a Q_SLOT to a rviz::StringProperty all is compiled successfully until I use the tool in rviz, at that point rviz prints an error telling that the PluginlibFactory was unable to load the plugin.

But here is the caveat, if the plugin is implemented in rviz namespace the tool seems to work while if I add a custom namespace to the tools implementation it does not work; and I am pretty sure that is because of the namespace since I tried with a default tool implementation and the error only shows when the namespace is not rviz.

For instance, lets take a look at this code extracted from rviz implementation of goal tool.h:

#ifndef RVIZ_GOAL_TOOL_H
#define RVIZ_GOAL_TOOL_H

#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
#include <QObject>

#include <ros/ros.h>

#include "rviz/default_plugin/tools/pose_tool.h"
#endif

namespace rviz
{
class Arrow;
class DisplayContext;
class StringProperty;

class GoalTool : public PoseTool
{
  Q_OBJECT
public:
  GoalTool();
  ~GoalTool() override
  {
  }
  void onInitialize() override;

protected:
  void onPoseSet(double x, double y, double theta) override;

private Q_SLOTS:
  void updateTopic();

private:
  ros::NodeHandle nh_;
  ros::Publisher pub_;

  StringProperty* topic_property_;
};

} // namespace rviz

#endif

In line 45 of goal_tool.cpp the string property is assigned:

topic_property_ =
      new StringProperty("Topic", "goal", "The topic on which to publish navigation goals.",
                         getPropertyContainer(), SLOT(updateTopic()), this);

if this is compiled with rviz namespace the tool works wonderfully, but if we change the namespace:

#ifndef RVIZ_GOAL_TOOL_H
#define RVIZ_GOAL_TOOL_H

#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
#include <QObject>

#include <ros/ros.h>

#include "rviz/default_plugin/tools/pose_tool.h"
#endif

namespace rviz
{
class Arrow;
class DisplayContext;
class StringProperty;
}

using namespace rviz;
namespace custom_ns
{
class GoalTool : public PoseTool
{
  Q_OBJECT
public:
  GoalTool();
  ~GoalTool() override
  {
  }
  void onInitialize() override;

protected:
  void onPoseSet(double x, double y, double theta) override;

private Q_SLOTS:
  void updateTopic();

private:
  ros::NodeHandle nh_;
  ros::Publisher pub_;

  StringProperty* topic_property_;
};

} // namespace custom_ns

#endif

With the same assign line, Rviz just prompts the error and the tool is not usable. The plugin export line for the first is:

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(rviz::GoalTool, rviz::Tool)

and for the second one with custom namespace:

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(custom_ns::GoalTool, rviz::Tool)

And. finally, the xml for the first one is:

<library path="librviz_default_plugin">
   <class name="rviz/SetGoal" type="rviz::GoalTool" base_class_type="rviz::Tool">
    <description>
      Publish a goal pose for the robot.  After one use, reverts to default tool.
    </description>
  </class>
</library>

while the second is:

<library path="libcustom_ns_default_plugin">
   <class name="custom_ns/SetGoal" type="custom_ns::GoalTool" base_class_type="rviz::Tool">
    <description>
      Publish a goal pose for the robot.  After one use, reverts to default tool.
    </description>
  </class>
</library>

So, I am doing something wrong, is this expected to work like that and I need to insert my custom namespace ... (more)

edit retag flag offensive close merge delete

Comments

1

at that point rviz prints an error telling that the PluginlibFactory was unable to load the plugin.

where it the error message?

gvdhoorn gravatar image gvdhoorn  ( 2021-06-15 12:09:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-16 05:59:32 -0500

Weasfas gravatar image

I am going to answer myself after a bit of research of what was happening,

Answering @gvdhoorn commentes question the error was the following:

PluginlibFactory: The plugin for class 'custom_ns/GoalTool"' failed to load.  Error: Failed to load library /home/noetic/catkin_ws/devel/lib//libcustom_ns_default_plugin.so.

And I discovered it was caused by a mistake in the CmakeLists.txt file in which I did not used properly the Qt5 directive in order to advertise the compiler that the plugin Tool code contains Qt code. For anyone that come up with this error you should check that in your Cmake file there is the qt5_wrap_cpp with your header/cpp files.

With that line everything compiles and works properly.

Cheers.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-06-15 10:04:29 -0500

Seen: 173 times

Last updated: Jun 16 '21