[ROS2 foxy] Interactive marker server inside a Rviz plugin
Hello,
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:
WaypointTool::WaypointTool()
: 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()
{
exec_.add_node(nh_);
while(rclcpp::ok()){
exec_.spin_some();
}
}
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 ?
Asked by Alrevan on 2021-02-18 10:08:02 UTC
Answers
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.
Asked by jacobperron on 2021-02-18 13:43:19 UTC
Comments
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.
Asked by Alrevan on 2021-02-19 03:07:08 UTC
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
Asked by jlack on 2022-06-16 10:59:23 UTC
@jlack Your issue seems slightly different to the question asked here. Perhaps the solution you're looking for is: https://answers.ros.org/question/403587/interactive-markers-not-showing-in-rviz/?answer=403588#post-id-403588
Asked by ijnek on 2022-07-10 07:51:12 UTC
Comments
Just checking: are you calling
applyChanges()
on the interactive marker server after processing requests?Asked by jacobperron on 2021-02-18 13:34:51 UTC
Yes I do make the call, I will try to delay the init of the server as suggested
Asked by Alrevan on 2021-02-19 02:20:27 UTC