Ask Your Question
2

Looking for an existing ROS + Qt example

asked 2011-06-23 06:51:30 -0600

vpradeep gravatar image

updated 2014-01-28 17:09:55 -0600

ngrennan gravatar image

I'm currently building a remote cockpit/basestation for my robot, and I was considering using ROS and Qt to do it. I have a lot of experience using ROS, but this is definitely one of my first times using Qt. We're fairly committed to Qt, but we're still trying to decide on a backend for our app. ROS is definitely one potential option, assuming it slots in nicely with Qt.

The closest thing I've found to a ROS/Qt quickstart guide was (http://www.ros.org/wiki/eros_python_tools/roscreate_qt_pkg), but I was really looking for was a an existing ROS Qt package or application that I could run.

Does someone have an existing [and fairly crisp] ROS Qt application that they could point me to?

edit retag flag offensive close merge delete

Comments

vpradeep gravatar imagevpradeep ( 2011-06-23 08:39:30 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-06-23 12:20:02 -0600

Daniel Stonier gravatar image

updated 2011-06-23 21:13:02 -0600

Eros also has a package with qt versions of some of the roscpp_tutorials eros_qt_tutorials. Note that although its in e(mbedded)ros, you don't have to be doing embedded to compile these - they compile just as well natively. They integrate ros/qt along with the .ui designer files so that its easy to build your layout.

You can install eros and build/run eros_qt_tutorials directly, or if you just want to check out the package code without all of eros and pull bits from that:

svn co https://code.ros.org/svn/eros/tags/diamondback/tests/eros_qt_tutorials

The only special thing it uses is the eros_prepare_qt4 cmake macro (in CMakeLists.txt) which doesn't do anything special - it just helps patch a few corner case issues for static qt builds until the next cmake release comes out with some fixes.

If doing a shared library build, you can effectively replace that eros_prepare_qt4 with

# Add other components as you need them
find_package(Qt4 COMPONENTS QtCore QtGui)
include(${QT_USE_FILE})
# Need to pick up autogen'd ui files in build dir, so add the following
include_directories(${CMAKE_CURRENT_BINARY_DIR})
edit flag offensive delete link more
3

answered 2011-06-27 07:21:00 -0600

Bill Smart gravatar image

updated 2011-06-27 14:27:36 -0600

I'd suggest using PySide for Qt/ROS integration. You need to install PySide from here first.

Here's a trivial example of publishing and subscribing to get you started:

#!/usr/bin/env python

import roslib; roslib.load_manifest('example')
import rospy

from std_msgs.msg import String

from PySide.QtCore import * 
from PySide.QtGui import * 
import sys

class GUI:
    def __init__(self): 
        # A publisher for messages
        self.pub = rospy.Publisher('example', String)

        # A subscriber for our own messages
        self.sub = rospy.Subscriber('example', String, self.sub_callback)

        self.button = QPushButton('push\nme')
        self.button.clicked.connect(self.pub_callback)
        self.button.show()

    def pub_callback(self):
        self.pub.publish('Thank You!')

    def sub_callback(self, msg):
        print 'Got message:', msg.data


if __name__ == '__main__':
    # Initialize the node
    rospy.init_node('example')

    # Initialize Qt
    app = QApplication(sys.argv)

    gui = GUI()

    app.exec_()

You'll also need the following lines in your manifest.xml

<depend package="rospy" />
<depend package="std_msgs" />
edit flag offensive delete link more

Comments

Control of the main thread isn't an issue with c++ qt. The http://www.ros.org/wiki/eros_python_tools/roscreate_qt_ros_pkg script generates sources which allow gui and ros threads in parallel with clean shutdown from either. I haven't had any bad things happen with callbacks.
Daniel Stonier gravatar imageDaniel Stonier ( 2011-06-27 12:34:39 -0600 )edit
My misunderstanding. I've modified my answer to get rid of the "bad things" statement.
Bill Smart gravatar imageBill Smart ( 2011-06-27 14:29:25 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-23 06:51:30 -0600

Seen: 5,150 times

Last updated: Jun 27 '11