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

subscriber in rqt plugin python

asked 2017-02-09 13:17:53 -0500

fonstein gravatar image

updated 2017-02-11 07:59:47 -0500

lucasw gravatar image

I'm writing a rqt plugin in python, but can't get the subscriber to work. I want the string from "controller/mode" to show in "lineControlMode". For some reason this doesn't happen. Hope some of you can help me.

import os
import rospkg
import rospy

from qt_gui.plugin import Plugin
from python_qt_binding import loadUi
from python_qt_binding.QtWidgets import QWidget, QGraphicsView
from std_msgs.msg import String

class MyPlugin(Plugin):

def __init__(self, context):
    super(MyPlugin, self).__init__(context)

    # Give QObjects reasonable names
    rp = rospkg.RosPack()

    # Process standalone plugin command-line arguments
    from argparse import ArgumentParser
    parser = ArgumentParser()
    # Add argument(s) to the parser.
    parser.add_argument("-q", "--quiet", action="store_true",
                  help="Put plugin in silent mode")
    args, unknowns = parser.parse_known_args(context.argv())
    if not args.quiet:
        print 'arguments: ', args
        print 'unknowns: ', unknowns

    # Create QWidget
    self._widget = QWidget()
    ui_file = os.path.join(rp.get_path('rqt_vortex_control_mode'), 'resource', 'MyPlugin.ui')

    # Extend the widget with all attributes and children from UI file
    loadUi(ui_file, self._widget)

    # Give QObjects reasonable names

    # Add widget to the user interface

    #MY CODE

    self.sub = rospy.Subscriber("/uranus_dp/controller/mode", String, self.callback)

def shutdown_plugin(self):

def callback(self, mode):

Here is the link to my repository just in case:

edit retag flag offensive close merge delete


The plugin appears to work, but when you publish to /uranus_dp/controller/mode the lineControlMode widget doesn't show anything?

lucasw gravatar image lucasw  ( 2017-02-11 08:02:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-02-11 08:11:37 -0500

lucasw gravatar image

updated 2017-02-11 08:12:45 -0500

Does the "init" test message successfully show up?

If so then try this at the bottom of the init:

temp = String("test string")

If that works re-enable the subscriber and put a rospy.loginfo(mode) in the callback and publish test messages to the topic, and see if the callback is getting triggered.

edit flag offensive delete link more


Thanks, that helped a lot. Got it to work now!

fonstein gravatar image fonstein  ( 2017-02-15 12:47:27 -0500 )edit

What was the issue? Did setText not like taking a String?

lucasw gravatar image lucasw  ( 2017-02-15 15:29:12 -0500 )edit

I had to cast the data to String. There was also some bugs on the Subscriber, but with your tips on debugging I got it to work.

fonstein gravatar image fonstein  ( 2017-02-15 16:16:04 -0500 )edit

Question Tools

1 follower


Asked: 2017-02-09 13:17:53 -0500

Seen: 905 times

Last updated: Feb 11 '17