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

Can I have a rviz::Tool inside an rviz::Panel?

asked 2017-01-11 10:04:12 -0500

mgruhler gravatar image

We have developed several tools for interacting with rviz. However, those tools are, in the end, providing "one" functionality (think of: add object, move object, delete object).

Thus, to streamline this and make the rviz interface cleaner, I'd like to have all those tools not as buttons on the toolbar, but on a panel.

Is this doable with rviz::Tool? Or does this require to load them to the toolbar?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-01-12 09:49:47 -0500

kramer gravatar image

updated 2017-01-14 10:41:21 -0500

It's been a while since I did this (or even looked at the code), but I created a tool that I load/unload programmatically for a corresponding custom Display. Something to be aware of is that the tool currently in use is system-wide, so loading/unloading needs to be handled appropriately.

In a Panel, you can access the ToolManager from the protected VisualizationManager member:

ToolManager* toolManager = vis_manager_->tool_manager_;

See the ToolManager API for further functionality. Note that this is for Indigo; things may be different for other ROS versions.

Edit: given the ToolManager* (I'll call it tMan for brevity) and tool class name (tClassName), loading is:

tMan->addTool(tClassName);

Assume you have a reference to a Tool* tool; to make it the active tool:

tMan->setCurrentTool(tool);

That will take care of switching tools for you; unloading a tool is akin to removing it from the tool panel (which you likely don't need to do).

Note that actually bookkeeping the tools is a pain. As far as I know, you need to use the class name; something like:

Tool* curTool = tMan->getCurrentTool();
if (curTool && curTool->getClassId() == tClassName) {
    ...
}

But just doing tMan->setCurrentTool(tool) will deactivate the old and activate the new. Hope that helps some.

edit flag offensive delete link more

Comments

Thanks for answering, I'll try it out soon

With the toolManager I can then load this tool, in effect calling the activate() function of this tool? This would be exactly what I was looking for.

What about a tool (say, SendGoal) which is active at this moment. Do I need to manually unload this?

mgruhler gravatar image mgruhler  ( 2017-01-13 02:33:55 -0500 )edit

'Cuz it's (somewhat) complicated text to put in a comment, I'm editing my answer with some extra code.

kramer gravatar image kramer  ( 2017-01-14 10:05:13 -0500 )edit

@kramer thank you so much for the in depth answer. This helped me a lot and a quick proof-of-concept seems to work. I'll update if I stumble upon any issues worth noting. So far, I'll consider this answered.

mgruhler gravatar image mgruhler  ( 2017-01-16 01:36:49 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-01-11 10:04:12 -0500

Seen: 435 times

Last updated: Jan 14 '17