Unable to assign slot to rviz property with custom namespace
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 ...
where it the error message?