Exemplo n.º 1
0
 def add_local_service(self, msg):
     rosservprox = rospy.ServiceProxy(
         msg.conn_name, get_ROS_class(msg.conn_type, srv=True))
     l_to_r_srv_cv = self.create_callback_from_local_to_remote_srv(
         msg.conn_name, msg.conn_type, rosservprox)
     remote_service_server = self.client.service_server(
         msg.alias_name, msg.conn_type, l_to_r_srv_cv)
     self._instances['services'].append({
         msg.conn_name: {
             'rosservprox': rosservprox,
             'bridgeservserver': remote_service_server
         }
     })
     return ROSDuctConnectionResponse()
Exemplo n.º 2
0
    def add_remote_service(self, msg):
        remote_service_client = self.client.service_client(
            msg.conn_name, msg.conn_type)
        r_to_l_serv_cb = self.create_callback_from_remote_to_local_srv(
            remote_service_client, msg.conn_name, msg.conn_type)
        rosserv = rospy.Service(msg.alias_name,
                                get_ROS_class(msg.conn_type, srv=True),
                                r_to_l_serv_cb)

        self._instances['services'].append({
            msg.conn_name: {
                'rosserv': rosserv,
                'bridgeservclient': remote_service_client
            }
        })
        return ROSDuctConnectionResponse()
Exemplo n.º 3
0
    def add_local_topic(self, msg):
        bridgepub = self.client.publisher(msg.alias_name,
                                          msg.conn_type,
                                          latch=msg.latch)

        cb_l_to_r = self.create_callback_from_local_to_remote(
            msg.conn_name, msg.conn_type, bridgepub)

        rossub = rospy.Subscriber(msg.conn_name, get_ROS_class(msg.conn_type),
                                  cb_l_to_r)
        self._instances['topics'].append(
            {msg.conn_name: {
                'rossub': rossub,
                'bridgepub': bridgepub
            }})
        return ROSDuctConnectionResponse()
Exemplo n.º 4
0
    def add_remote_topic(self, msg):
        rospub = rospy.Publisher(
            msg.alias_name,
            get_ROS_class(msg.conn_type),
            # SubscribeListener added later
            queue_size=1,
            latch=msg.latch)

        cb_r_to_l = self.create_callback_from_remote_to_local(
            msg.conn_name, msg.conn_type, rospub)
        subl = self.create_subscribe_listener(msg.conn_name, msg.conn_type,
                                              cb_r_to_l)
        rospub.impl.add_subscriber_listener(subl)
        self._instances['topics'].append(
            {msg.conn_name: {
                'rospub': rospub,
                'bridgesub': None
            }})
        return ROSDuctConnectionResponse()
Exemplo n.º 5
0
    def initialize(self):
        """
        Initialize creating all necessary bridged clients and servers.
        """
        connected = False
        while not rospy.is_shutdown() and not connected:
            try:
                self.client = ROSBridgeClient(self.rosbridge_ip,
                                              self.rosbridge_port)
                connected = True
            except socket.error as e:
                rospy.logwarn(
                    'Error when opening websocket, is ROSBridge running?')
                rospy.logwarn(e)
                rospy.sleep(5.0)

        # We keep track of the instanced stuff in this dict
        self._instances = {'topics': [], 'services': []}
        for r_t in self.remote_topics:
            if len(r_t) == 2:
                topic_name, topic_type = r_t
                local_name = topic_name
            elif len(r_t) == 3:
                topic_name, topic_type, local_name = r_t
            rospub = rospy.Publisher(
                local_name,
                get_ROS_class(topic_type),
                # SubscribeListener added later
                queue_size=1)

            cb_r_to_l = self.create_callback_from_remote_to_local(
                topic_name, topic_type, rospub)
            subl = self.create_subscribe_listener(topic_name, topic_type,
                                                  cb_r_to_l)
            rospub.impl.add_subscriber_listener(subl)
            self._instances['topics'].append(
                {topic_name: {
                    'rospub': rospub,
                    'bridgesub': None
                }})

        for l_t in self.local_topics:
            if len(l_t) == 2:
                topic_name, topic_type = l_t
                remote_name = topic_name
            elif len(l_t) == 3:
                topic_name, topic_type, remote_name = l_t

            bridgepub = self.client.publisher(remote_name, topic_type)

            cb_l_to_r = self.create_callback_from_local_to_remote(
                topic_name, topic_type, bridgepub)

            rossub = rospy.Subscriber(topic_name, get_ROS_class(topic_type),
                                      cb_l_to_r)
            self._instances['topics'].append(
                {topic_name: {
                    'rossub': rossub,
                    'bridgepub': bridgepub
                }})

        # Services
        for r_s in self.remote_services:
            if len(r_s) == 2:
                service_name, service_type = r_s
                local_name = service_name
            elif len(r_s) == 3:
                service_name, service_type, local_name = r_s
            remote_service_client = self.client.service_client(
                service_name, service_type)
            r_to_l_serv_cb = self.create_callback_from_remote_to_local_srv(
                remote_service_client, service_name, service_type)
            rosserv = rospy.Service(local_name,
                                    get_ROS_class(service_type, srv=True),
                                    r_to_l_serv_cb)

            self._instances['services'].append({
                service_name: {
                    'rosserv': rosserv,
                    'bridgeservclient': remote_service_client
                }
            })

        for l_s in self.local_services:
            if len(l_s) == 2:
                service_name, service_type = l_s
                remote_name = service_name
            elif len(l_s) == 3:
                service_name, service_type, remote_name = l_s
            rosservprox = rospy.ServiceProxy(
                service_name, get_ROS_class(service_type, srv=True))
            l_to_r_srv_cv = self.create_callback_from_local_to_remote_srv(
                service_name, service_type, rosservprox)
            remote_service_server = self.client.service_server(
                remote_name, service_type, l_to_r_srv_cv)
            self._instances['services'].append({
                service_name: {
                    'rosservprox': rosservprox,
                    'bridgeservserver': remote_service_server
                }
            })

        # Get all params and store them for further updates
        for param in self.parameters:
            if type(param) == list:
                # remote param name is the first one
                param = param[0]
            self.last_params[param] = self.client.get_param(param)