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

[ROS2 foxy] Interactive marker server inside a Rviz plugin

asked 2021-02-18 09:08:02 -0600

Alrevan gravatar image


I have a combination a tool and panel in Rviz that should allow me to manage/create a waypoint list. When the tool is loaded it should also load the panel and the interactive marker server that will manage the waypoint.

The issue is the interactive marker server constructor will take a rclcpp::Node::SharedPtr in its constructor which is not immediately available in a Rviz2::plugin.

Rightn now i have tried two different things:

I tried to get the rviz node instance:

WaypointTool::WaypointTool() : rviz_common::Tool(){
   auto nodeAbstraction = context_->getRosNodeAbstraction().lock();
   rclcpp::Node::SharedPtr node = nodeAbstraction->get_raw_node();
   server_ = new interactive_markers::InteractiveMarkerServer("waypoint", node);
   // Stuff

However this gives me a segfault on this line:

auto nodeAbstraction = context_->getRosNodeAbstraction().lock();

I guess the node weak_ptr is not initialized in this context.

I tried another way where I directly create a node instance in my tool class and give it to the server:

    : rviz_common::Tool(), nh_(std::make_shared<rclcpp::Node>("w_tool"), server_("waypoint", nh_) {
    // Stuff

However if I use this directly rviz interactive marker display can't connect to the server and gives me an error like this:

[INFO] [1613640458.153922653] [rviz]: Connected on namespace: waypoint
[INFO] [1613640458.169085509] [rviz]: Sending request for interactive markers
[WARN] [1613640459.188331428] [rviz]: Did not receive response with interactive markers, resending request...

I assume it is because the node is not spinning so nothing happens when the server is called by the client. To solve this I added a thread inside my class where I make the node spin:

void WaypointTool::onInitialize() {
   // Stuff
   thread_ = std::make_shared<std::thread>(std::bind(&WaypointTool::spin, this));

 void WaypointTool::spin()

When doing this, the console will outputs these lines continuously:

[INFO] [1613653584.000676745] [rviz]: Sending request for interactive markers
[INFO] [1613653583.936624364] [w_tool]: Responding to request to get interactive markers
[INFO] [1613653583.968256112] [rviz]: Service response received for initialization

However no interactive markers are ever displayed even if they seem to be created correctly as the topic /waypoint/output correctly outputs something.

Has anyone already managed to make interactive server work with rviz2 plugins ?

edit retag flag offensive close merge delete


Just checking: are you calling applyChanges() on the interactive marker server after processing requests?

jacobperron gravatar image jacobperron  ( 2021-02-18 12:34:51 -0600 )edit

Yes I do make the call, I will try to delay the init of the server as suggested

Alrevan gravatar image Alrevan  ( 2021-02-19 01:20:27 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-02-18 12:43:19 -0600

jacobperron gravatar image

If you want to use the ROS node provided by RVIz, I think you should delay the creation of the interactive marker server until the onInitialize() method of your tool is called. This seems to be what some of the default tools are doing, so presumably the ROS node is valid at this point.

edit flag offensive delete link more


This worked, I can now use the rviz node for my server. However I can't see my markers and the server seems stuck in a kind of loop. I will investigate more on this, thanks.

Alrevan gravatar image Alrevan  ( 2021-02-19 02:07:08 -0600 )edit

Was there ever a resolution here? I am in exactly the same spot you were here I think. I'm getting spammed with Sending request for interactive markers and Service response received for initialization

jlack gravatar image jlack  ( 2022-06-16 10:59:23 -0600 )edit

@jlack Your issue seems slightly different to the question asked here. Perhaps the solution you're looking for is:

ijnek gravatar image ijnek  ( 2022-07-10 07:51:12 -0600 )edit

Question Tools



Asked: 2021-02-18 09:08:02 -0600

Seen: 826 times

Last updated: Feb 18 '21