コード例 #1
0
 def relayed_invitation(self, req):
     '''
       Provides a relayed invitation from a client (e.g. android remocon).
       This relay fills in the gateway name to pass on to the app manager,
       which makes life much simpler for the clients.
     '''
     if self.auto_invite and req.cancel:
         # Don't cancel, just ignore it and send back a true response (not broken).
         return rocon_app_manager_srvs.SimpleInviteResponse(True)
     try:
         rospy.loginfo(
             "Pairing Master : inviting the private master's application manager."
         )
         remote_response = self.remote_invite_service(
             rocon_app_manager_srvs.InviteRequest(
                 remote_target_name=self.local_gateway_name,
                 application_namespace='',
                 cancel=req.cancel))
     except rospy.service.ServiceException:  # service call failed
         console.logerror(
             "Pairing Master: remote invitation failed to connect.")
     except rospy.exceptions.ROSInterruptException:  # shutdown exception
         sys.exit(0)
     return rocon_app_manager_srvs.SimpleInviteResponse(
         remote_response.result)
コード例 #2
0
 def spin(self):
     '''
       If the private master's robot app manager is currently being remote controlled by us (start_app and stop_app
       is available), then it checks to make sure the android client is there. If not, it uninvites the private
       robot app manager so that it is free to be remote controlled by other sources.
       
       To check that it is there, it looks to see if either the android remocon or android remocon app is
       publishing to the /pairing/android_app_name topic.
     '''
     master = rosgraph.Master(rospy.get_name())
     flagged_for_release_count = 0
     while not rospy.is_shutdown():
         if not self.watchdog_flag:
             rospy.rostime.wallsleep(1.0)
         else:
             if flagged_for_release_count == 0:
                 rospy.rostime.wallsleep(1.0)
             else:
                 rospy.rostime.wallsleep(0.25)
             try:
                 # If not found, exceptions get thrown.
                 result = master.lookupService('/' +
                                               self.remote_gateway_name +
                                               '/start_app')
                 # Found, so check that an android client is connected.
                 if not self.is_pairing_device_present(master):
                     # Don't automatically disengage as sometimes the start_app handle will appear before the android
                     # client's handle. Put it under observation
                     flagged_for_release_count += 1
                     # This gives it 3-4s to release control, don't set it too low, because switching between a running app and
                     # back to the app list can often take 2-3 seconds before the watchdog topic is re-established.
                     if flagged_for_release_count == 20:
                         # Android client disappeared, probably crashed, so release control (uninvite)
                         rospy.loginfo(
                             "Pairing Master : android client disappeared, releasing remote control."
                         )
                         remote_response = self.remote_invite_service(
                             rocon_app_manager_srvs.InviteRequest(
                                 remote_target_name=self.local_gateway_name,
                                 application_namespace='',
                                 cancel=True))
                         flagged_for_release_count = 0
                 else:
                     flagged_for_release_count = 0
             except rospy.service.ServiceException:
                 pass  # Was in the middle of uninviting when ros shutdown
             except rosgraph.masterapi.Error:
                 pass
             except rosgraph.masterapi.Failure:
                 pass
コード例 #3
0
    def invite(self, concert_gateway_name, client_local_name, ok_flag):
        '''
          Bit messy with ok_flag here as we are mid-transition to using 'cancel' flag in the
          invite services.

          @param concert_gateway_name : have to let the client know the concert gateway name
                                        so they can flip us topics...
          @type str
        '''
        req = rapp_manager_srvs.InviteRequest(concert_gateway_name,
                                              client_local_name, not ok_flag)
        resp = self._invite_service(req)

        if resp.result == True:
            self._setup_service_proxies()
        else:
            raise Exception(str("Invitation Failed : " + self.name))
コード例 #4
0
ファイル: pairing_master.py プロジェクト: Playfish/cafe_demo
    rospy.loginfo("Pairing Master : remote gateway name [%s]" %
                  remote_gateway_name)
    # this is how the android app chooser can find the namespace for the start_app etc. handles
    rospy.set_param('/robot/name', remote_gateway_name)
    unused_platform, unused_system, robot, unused_name = platform_info(
        remote_gateway_name)
    rospy.set_param('/robot/type', robot)
    invite_service_name = '/' + remote_gateway_name + '/invite'
    invite_service = rospy.ServiceProxy(invite_service_name,
                                        rocon_app_manager_srvs.Invite)
    try:
        rospy.loginfo("Pairing Master : waiting for invite service [%s]" %
                      invite_service_name)
        rospy.wait_for_service(invite_service_name)
        if auto_invite:
            rospy.loginfo(
                "Pairing Master : automatically taking control (inviting) the application manager."
            )
            invite_service(
                rocon_app_manager_srvs.InviteRequest(
                    remote_target_name=local_gateway_name,
                    application_namespace='',
                    cancel=False))
    except rospy.service.ServiceException:  # service call failed
        console.logerror("Pairing Master: invite service call failed.")
        sys.exit(1)
    except rospy.exceptions.ROSInterruptException:  # shutdown exception
        sys.exit(0)

    rospy.spin()
コード例 #5
0
    def invite(self, concert_gateway_name, client_local_name, cancel):
        '''
          One perhaps unexpected behaviour here is that we let the client know it's local
          concert alias so that it can use that for it's application namespace. We do this
          rather than let the concert client use its unique name + uuid combination to set
          the namespace simply for convenience. It's far more practical and easier to introspect
          the concert client name aliases than having to jump around a new uuid each time.

          @param concert_gateway_name : have to let the client know the concert gateway name
                                        so they can flip us topics...
          @type str

          @param client_local_name : this configures the default namespace used by the client
          @type str

          @param cancel : whether to cancel an existing invite or initiate a new invitation
          @type boolean

          @return result of the invitation
          @rtype boolean
        '''
        # quiet abort checks
        if cancel and not self.is_invited:
            return True  # kind of an automatic success
        if not cancel and self.is_blocking:
            return False
        req = rapp_manager_srvs.InviteRequest(concert_gateway_name,
                                              client_local_name, cancel)
        resp = rapp_manager_srvs.InviteResponse()
        try:
            self._invite_service.wait_for_service(0.3)
            resp = self._invite_service(req)
        except rospy.ROSException:
            resp.result = False
            resp.error_code = rapp_manager_msgs.ErrorCodes.CLIENT_CONNECTION_DISRUPTED
            resp.message = "service not available"
        except rospy.ROSInterruptException:
            resp.result = False
            resp.error_code = rapp_manager_msgs.ErrorCodes.CLIENT_CONNECTION_DISRUPTED
            resp.message = "interrupted by shutdown"
        except rospy.service.ServiceException:
            resp.result = False
            resp.error_code = rapp_manager_msgs.ErrorCodes.CLIENT_CONNECTION_DISRUPTED
            resp.message = "message sent, but not received"
        if resp.result == True:
            self.is_invited = not cancel
            self.is_invited_elsewhere = False
            self.is_blocking = False
            if self.is_invited:
                rospy.loginfo("Conductor : invited [%s][%s]" %
                              (self.name, self.gateway_name))
                self._setup_service_proxies()
            else:
                rospy.loginfo("Conductor : uninvited [%s]" % self.name)
        elif not cancel:
            if (resp.error_code == rapp_manager_msgs.ErrorCodes.
                    INVITING_CONTROLLER_NOT_WHITELISTED
                    or resp.error_code == rapp_manager_msgs.ErrorCodes.
                    INVITING_CONTROLLER_BLACKLISTED or resp.error_code
                    == rapp_manager_msgs.ErrorCodes.LOCAL_INVITATIONS_ONLY):
                rospy.loginfo("Conductor : invitation to %s was blocked [%s]" %
                              (self.name, resp.message))
                self.is_blocking = True
            elif resp.error_code == rapp_manager_msgs.ErrorCodes.ALREADY_REMOTE_CONTROLLED:
                if not self.is_invited_elsewhere:
                    self.is_invited_elsewhere = True
                    # only provide debug logging when this actually flips to True (don't spam)
                    rospy.loginfo(
                        "Conductor : invitation to %s was refused [%s]" %
                        (self.name, resp.message))
            else:
                rospy.logwarn("Conductor : invitation to %s failed [%s]" %
                              (self.name, resp.message))
        else:
            rospy.logwarn("Conductor : failed to uninvite %s [%s]" %
                          (self.name, resp.message))
        return resp.result