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

Pushbutton in GUI in ROS

asked 2018-01-23 04:01:02 -0500

phil333 gravatar image

updated 2018-01-24 02:28:06 -0500

130s gravatar image

I need to trigger a specific function in my ROS node by the user. There a simple pushbutton function that can be setup within the rqt dynamic reconfigure? Currently I am just using a workaround of just triggering the function whenever an int value is changing, but that is not really a great interface.

edit retag flag offensive close merge delete

Comments

Using dynamic_reconfigure for this sounds like a bit of an abuse of the infrastructure.

Creating UIs like this is typically done in RQT, which is the same framework that rqt_dynamic_reconfigure is built on top of. See wiki/rqt. Has both Python and C++ bindings.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-23 10:05:52 -0500 )edit

so far I only used dynamic_reconfigure, but this is something i should probably investigate. thx

phil333 gravatar image phil333  ( 2018-01-23 10:20:24 -0500 )edit

It's a bit hacky but if you're using Rviz then you can use the 2D nav goal message that is triggered using the Rviz GUI, you can ignore the content of the message and use the message itself as a trigger for an event.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-01-23 11:28:43 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2018-01-24 02:33:55 -0500

130s gravatar image

updated 2018-01-24 02:46:33 -0500

As someones pointed out already I'm afraid asking about dynamic reconfigure for your purpose sounds like an XY problem.

That said, another option is in jsk_rqt_plugins there's a rqt_yn_btn rqt plugin that calls a specific ROS Service.

edit flag offensive delete link more
1

answered 2018-01-23 09:44:10 -0500

jayess gravatar image

How about a boolean? That should be a checkbox in rqt_reconfigure that you can check and uncheck.

edit flag offensive delete link more

Comments

didnt even think of this, still ugly, but a good fix :)

phil333 gravatar image phil333  ( 2018-01-23 10:20:54 -0500 )edit

Yeah, it's not pretty but it works.

jayess gravatar image jayess  ( 2018-01-23 13:19:42 -0500 )edit
1

This is what I use quite often. It is also possible to have your code that runs a dynamic reconfigure server toggle the boolean for you. This lets you fire off single triggers from rqt_reconfigure or other dynamic reconfigure clients.

Thomas D gravatar image Thomas D  ( 2018-01-24 00:21:13 -0500 )edit
1

May I please ask everyone here to stop recommending using dynamic_reconfigure for this? It's a massive abuse of that particular piece of infrastructure (violating semantics and what not). RQT plugins aren't really that difficult, and much more suited for this.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 02:03:25 -0500 )edit

You could even go for a rosbridge_suite approach with rosjs or even rosnodejs. Or use Tkinter as @Airuno2L suggests in his answer.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 02:04:11 -0500 )edit
0

answered 2018-01-23 07:37:28 -0500

Airuno2L gravatar image

As far as I know the built-in rqt_reconfigure (the gui for dynamic reconfigure) only really has support for sliders (and maybe pull down menus and check boxes but I'm not sure).

But, you don't have to limit yourself to using rqt or even dynamic reconfigure. You can really use ROS with any GUI library you like (C++ or Python ones will be easiest of course).

For example, if you use python, you can use TkInter (the easiest Python GUI library in my opinion/experience, also it ships with Python by default most of the time) and make the callback for the button press publish a message to a topic.

Here is a quick example of a Tkinter button:

from Tkinter import *

master = Tk()

def callback():
    print "click!"

b = Button(master, text="OK", command=callback)  
b.pack()

mainloop()

You would just make the callback function publish a ROS message instead of printing "click!". More info about Tkinter buttons can be found here.

edit flag offensive delete link more

Comments

I just tried to run that and had to do

from tkinter import *

instead of

from Tkinter import *

The T had to be lower case on my system, I'm not sure if your system will be the same.

Airuno2L gravatar image Airuno2L  ( 2018-01-23 07:41:19 -0500 )edit

would have been nice to have everything inside rqt. Do you have any C++ recommendation instead of TkInter, my current implementation is written C.

phil333 gravatar image phil333  ( 2018-01-23 08:43:06 -0500 )edit

Based on that, although I haven't used it I would probably do what gvdhoorn said and look at rqt.

Airuno2L gravatar image Airuno2L  ( 2018-01-23 13:13:27 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-01-23 04:01:02 -0500

Seen: 2,931 times

Last updated: Jan 24 '18