def trigger_configuration(self):
        """
        Callback when the configuration button is clicked
        """
        changed = False
        map_topics = sorted(rostopic.find_by_type('nav_msgs/OccupancyGrid'))
        try:
            index = map_topics.index(self.map_topic)
        except ValueError:
            index = 0
        map_topic, ok = QInputDialog.getItem(self, "Select map topic name",
                                             "Topic name", map_topics, index)
        if ok:
            if map_topic != self.map_topic:
                changed = True
            self.map_topic = map_topic

        # Paths
        path_topics = sorted(rostopic.find_by_type('nav_msgs/Path'))
        path_topics = [(topic, topic in self.paths) for topic in path_topics]
        dialog = ListDialog("Select path topic(s)", path_topics, self)
        paths, ok = dialog.exec_()

        if ok:
            if not paths:
                changed = True
            diff = set(paths).symmetric_difference(set(self.paths))
            if diff:
                self.paths = paths
                changed = True

        # Polygons
        polygon_topics = sorted(
            rostopic.find_by_type('geometry_msgs/PolygonStamped'))
        polygon_topics = [(topic, topic in self.polygons)
                          for topic in polygon_topics]
        dialog = ListDialog("Select polygon topic(s)", polygon_topics, self)
        polygons, ok = dialog.exec_()

        if ok:
            if not polygons:
                changed = True
            diff = set(polygons).symmetric_difference(set(self.polygons))
            if diff:
                self.polygons = polygons
                changed = True

        if changed:
            rospy.logdebug(
                "New configuration is different, creating a new nav_view")
            self.new_nav_view()
Exemple #2
0
    def get_servers(self):
        """Get the base names that are broadcasting smach states."""

        # Get the currently broadcasted smach introspection topics
        topics = rostopic.find_by_type('smach_msgs/SmachContainerStatus')

        return [t[:t.rfind(STATUS_TOPIC)] for t in topics]
Exemple #3
0
    def get_servers(self):
        """Get the base names that are broadcasting smach states."""

        # Get the currently broadcasted smach introspection topics
        topics = rostopic.find_by_type(msg_builder.STATUS_MSG_TOPIC_TYPE)

        return [t[:t.rfind(STATUS_TOPIC)] for t in topics]
Exemple #4
0
    def get_servers(self):
        """Get the base names that are broadcasting smach states."""

        # Get the currently broadcasted smach introspection topics
        topics = rostopic.find_by_type("smach_msgs/SmachContainerStatus")

        return [t[: t.rfind(STATUS_TOPIC)] for t in topics]
Exemple #5
0
    def trigger_configuration(self):
        """
        Callback when the configuration button is clicked
        """
        image_topics = sorted(rostopic.find_by_type('sensor_msgs/Image'))
        try:
            topic_index = image_topics.index(self._sub.resolved_name)
        except (AttributeError, ValueError):
            topic_index = 0

        topic_name, ok = QInputDialog.getItem(self._widget, "Select topic name", "Topic name",
                                              image_topics, topic_index)
        if ok:
            self._create_subscriber(topic_name)

        available_rosservices = []
        for s in rosservice.get_service_list():
            try:
                if rosservice.get_service_type(s) in _SUPPORTED_SERVICES:
                    available_rosservices.append(s)
            except:
                pass

        try:
            srv_index = available_rosservices.index(self._srv.resolved_name)
        except (AttributeError, ValueError):
            srv_index = 0

        srv_name, ok = QInputDialog.getItem(self._widget, "Select service name", "Service name", available_rosservices,
                                            srv_index)
        if ok:
            self._create_service_client(srv_name)
Exemple #6
0
    def __init__(self, path, data, meta={}, parent=None):
        QWidget.__init__(self, parent)
        name = path.rstrip("/").rsplit("/", 1)[-1]

        default = meta.get("default", data)
        defines = meta.get("defines")
        topic_type = meta.get("topic_type")

        label = QLabel(name)
        layout = QVBoxLayout()
        layout.addWidget(label)

        if defines == "topic" and topic_type != None:
            combo = QComboBox()
            combo.addItems([""] + rostopic.find_by_type(topic_type))
            combo.setCurrentIndex(combo.findText(data))
            combo.currentIndexChanged.connect(lambda ind: rospy.set_param(path, combo.itemText(ind)))
            layout.addWidget(combo)
        else:
            text = QLineEdit(data)
            text.textChanged.connect(lambda s: rospy.set_param(path, s))
            layout.addWidget(text)

        self.setLayout(layout)
        self.default = default
Exemple #7
0
def _find(msg_type):
    try:
        return response_ok({
            'message_type': msg_type,
            'topics': rt.find_by_type(msg_type)
        })
    except Exception as e:
        return response_error(str(e))
def find_action_with_type(action_type):
    """
    topic_type format: module/type, e.g:'control_msgs/FollowJointTrajectoryAction'
    """
    action_feedback_list = rostopic.find_by_type(action_type + 'Feedback')
    if action_feedback_list:
        return [x.replace('/feedback', '') for x in action_feedback_list]
    else:
        return []
def find_topic_with_type(topic_type):
    """
    topic_type format: module/type, e.g:'tf2_msgs/TFMessage'
    """
    topic_name_list = rostopic.find_by_type(topic_type)
    if topic_name_list:
        return topic_name_list
    else:
        return []
Exemple #10
0
 def trigger_configuration(self):
     """
     Callback when the configuration button is clicked
     """
     topic_name, ok = QInputDialog.getItem(
         self.widget, "Select topic name", "Topic name",
         rostopic.find_by_type('sensor_msgs/Image'))
     if ok:
         self.create_subscriber(topic_name)
 def handle_state_change(self, msg):
     activities = msg.strings
     # returns a list of topics w/ the state specified
     topics = rostopic.find_by_type(self.message_type_s)
     self.set_pubbers(topics)
     for active in activities:
         if active not in self.pubbers:
             rospy.logerr('Could not find the desired topic (%s) to set the state of' % active)
     for topic, pub in self.pubbers.iteritems():
         if topic in activities:
             pub.publish(ApplicationState.VISIBLE)
         else:
             pub.publish(ApplicationState.HIDDEN)
Exemple #12
0
def find_topic(topic_type, timeout=rospy.rostime.Duration(5.0), unique=False):
    '''
    Do a lookup to find topics of the type specified. It can apply the
    additional logic of whether this should return a single unique result,
    or a list.  Under the hood this calls out to the ros master for a list
    of registered topics and it parses that to determine the result. If nothing
    is found, it loops around internally on a 100ms loop until the result is
    found or the specified timeout is reached.

    This will raise exceptions if it times out or returns multiple values.

    Usage:

    .. code-block:: python

        from rocon_python_comms import find_topic

        try:
            pairing_topic_name = find_topic('rocon_interaction_msgs/Pair', timeout=rospy.rostime.Duration(0.5), unique=True)
        except rocon_python_comms.NotFoundException as e:
            rospy.logwarn("support for interactions disabled")

    :param str topic_type: topic type specification, e.g. rocon_std_msgs/MasterInfo
    :param rospy.rostime.Duration timeout: raise an exception if nothing is found before this timeout occurs.
    :param bool unique: flag to select the lookup behaviour (single/multiple results)

    :returns: the fully resolved name of the topic (unique) or list of names (non-unique)
    :rtype: str

    :raises: :exc:`.NotFoundException` if no topic is found within the timeout
    '''
    topic_name = None
    topic_names = []
    timeout_time = time.time() + timeout.to_sec()
    while not rospy.is_shutdown(
    ) and time.time() < timeout_time and not topic_names:
        try:
            topic_names = rostopic.find_by_type(topic_type)
        except rostopic.ROSTopicException:
            raise NotFoundException("ros shutdown")
        if unique:
            if len(topic_names) > 1:
                raise NotFoundException("multiple topics found %s." %
                                        topic_names)
            elif len(topic_names) == 1:
                topic_name = topic_names[0]
        if not topic_names:
            rospy.rostime.wallsleep(0.1)
    if not topic_names:
        raise NotFoundException("timed out")
    return topic_name if topic_name else topic_names
Exemple #13
0
 def handle_state_change(self, msg):
     activities = msg.strings
     # returns a list of topics w/ the state specified
     topics = rostopic.find_by_type(self.message_type_s)
     self.set_pubbers(topics)
     for active in activities:
         if active not in self.pubbers:
             rospy.logerr(
                 'Could not find the desired topic (%s) to set the state of'
                 % active)
     for topic, pub in self.pubbers.iteritems():
         if topic in activities:
             pub.publish(ApplicationState.VISIBLE)
         else:
             pub.publish(ApplicationState.HIDDEN)
Exemple #14
0
    def trigger_configuration(self):
        """
        Callback when the configuration button is clicked
        """
        topic_name, ok = QInputDialog.getItem(self._widget, "Select topic name", "Topic name",
                                              rostopic.find_by_type('sensor_msgs/Image'))
        if ok:
            self._create_subscriber(topic_name)

        available_rosservices = []
        for s in rosservice.get_service_list():
            try:
                if rosservice.get_service_type(s) in _SUPPORTED_SERVICES:
                    available_rosservices.append(s)
            except:
                pass

        srv_name, ok = QInputDialog.getItem(self._widget, "Select service name", "Service name", available_rosservices)
        if ok:
            self._create_service_client(srv_name)
Exemple #15
0
def find_topic(topic_type, timeout=rospy.rostime.Duration(5.0), unique=False):
    '''
      Do a lookup to find topics of the type
      specified. This will raise exceptions if it times out or returns
      multiple values. It can apply the additional logic of whether this should
      return a single unique result, or a list.

      @param topic_type : topic type specification, e.g. rocon_std_msgs/MasterInfo
      @type str

      @param timeout : raise an exception if nothing is found before this timeout occurs.
      @type rospy.rostime.Duration

      @param unique : flag to select the lookup behaviour (single/multiple results)
      @type bool

      @return the fully resolved name of the topic (unique) or list of names (non-unique)
      @type str

      @raise rocon_python_comms.NotFoundException
    '''
    topic_name = None
    topic_names = []
    timeout_time = time.time() + timeout.to_sec()
    while not rospy.is_shutdown(
    ) and time.time() < timeout_time and not topic_names:
        try:
            topic_names = rostopic.find_by_type(topic_type)
        except rostopic.ROSTopicException:
            raise NotFoundException("ros shutdown")
        if unique:
            if len(topic_names) > 1:
                raise NotFoundException("multiple topics found %s." %
                                        topic_names)
            elif len(topic_names) == 1:
                topic_name = topic_names[0]
        if not topic_names:
            rospy.rostime.wallsleep(0.1)
    if topic_name is None:
        raise NotFoundException("timed out")
    return topic_name
    def trigger_configuration(self):
        topic_name, ok = QInputDialog.getItem(
            self._widget, "Select topic name", "Topic name",
            rostopic.find_by_type('sensor_msgs/Image'))
        if ok:
            self._create_subscriber(topic_name)

        available_rosservices = []
        for s in rosservice.get_service_list():
            try:
                if rosservice.get_service_type(
                        s) == "object_recognition_srvs/Recognize":
                    available_rosservices.append(s)
            except:
                pass

        srv_name, ok = QInputDialog.getItem(self._widget,
                                            "Select service name",
                                            "Service name",
                                            available_rosservices)
        if ok:
            self._create_service_client(srv_name)
def resolve_connection_cache(timeout=None):
    """
      @param timeout : timeout on checking for the connection_cache, if None, it just makes a single attempt.
      @type rospy.rostime.Duration

      @raise rocon_python_comms.NotFoundException: if no connection_cache available.
    """
    connection_cache_namespace = None
    topic_names = []
    timeout_time = time.time() + timeout.to_sec(
    ) if timeout is not None else None
    while not rospy.is_shutdown():
        if timeout_time is not None and time.time() > timeout_time:
            break
        # CAREFUL : This will still return a topic name if it was there once and has disappeared since.
        topic_names = rostopic.find_by_type("rocon_std_msgs/ConnectionsList")
        if not topic_names or len(topic_names) > 1:
            connection_cache_namespace = None
        elif topic_names[0] == '/connection_cache/list':
            connection_cache_namespace = "/"
        else:
            connection_cache_namespace = re.sub(r'/connection_cache/list', '',
                                                topic_names[0])
        if connection_cache_namespace is not None or timeout is None:
            break
        else:
            rospy.rostime.wallsleep(0.1)
    if not connection_cache_namespace:
        if not topic_names:
            raise rocon_python_comms.NotFoundException(
                "no connection_cache found attached to this local master - did you start it?"
            )
        else:
            raise rocon_python_comms.NotFoundException(
                "found more than one connection_cache connected to this master, this is an invalid configuration."
            )
    #console.debug("Found a connection_cache at %s"%connection_cache_namespace)
    return connection_cache_namespace
Exemple #18
0
 def find_topic(self, topic_type='sensor_msgs/Image'):
     return rostopic.find_by_type(topic_type)
Exemple #19
0
def get_topics_for_type(type, topics_glob):
    # Filter the list of topics by whether they are public before returning.
    return filter_globs(topics_glob, find_by_type(type))
Exemple #20
0
def getTopicsForType(type):
    return rostopic.find_by_type(type)
Exemple #21
0
def get_topics_for_type(type):
    return find_by_type(type)
Exemple #22
0
 def find_topic(self, topic_type='sensor_msgs/Image'):
     return rostopic.find_by_type(topic_type)
Exemple #23
0
def get_topics_for_type(type, topics_glob):
    # Filter the list of topics by whether they are public before returning.
    return filter(
        lambda x: any(fnmatch.fnmatch(str(x), glob) for glob in topics_glob),
        find_by_type(type))
Exemple #24
0
def getTopicsForType(type):
    return rostopic.find_by_type(type)
Exemple #25
0
def get_topics_for_type(type):
    return find_by_type(type)
Exemple #26
0
 def trigger_configuration(self):
     topic_name, ok = QInputDialog.getItem(
         self._widget, "Select topic name", "Topic name",
         rostopic.find_by_type('sensor_msgs/Image'))
     if ok:
         self._create_subscriber(topic_name)
Exemple #27
0
 def get_servers():
     """Get the base names that are broadcasting HSM structures."""
     topics = rostopic.find_by_type(HsmStructure._type)
     return [t[:t.rfind(STRUCTURE_TOPIC)] for t in topics]