def _create_resource(self, uri): # Create a resource to request resource = scheduler_msgs.Resource() resource.id = unique_id.toMsg(unique_id.fromRandom()) resource.rapp = self.resource_type resource.uri = uri compressed_image_topic_remapped = self._get_remapped_topic(rocon_uri.parse(resource.uri).name.string) resource.remappings = [rocon_std_msgs.Remapping(self._default_compressed_image_topic, compressed_image_topic_remapped)] return resource
def request_turtle(self, x_vel=0.1, z_vel=0.1, scale=1.0): ''' Request a turtle. ''' resource = scheduler_msgs.Resource() resource.id = unique_id.toMsg(unique_id.fromRandom()) resource.rapp = 'turtle_concert/turtle_stroll' resource.uri = 'rocon:/' resource_request_id = self.requester.new_request([resource], priority=self.service_priority) resource.parameters = [rocon_std_msgs.KeyValue('turtle_x_vel', str(x_vel)), rocon_std_msgs.KeyValue('turtle_z_vel', str(z_vel)), rocon_std_msgs.KeyValue('square_scale', str(scale))] self.pending_requests.append(resource_request_id) self.requester.send_requests()
def _node_to_resource(node, linkgraph): ''' Convert linkgraph information for a particular node to a scheduler_msgs.Resource type. @param node : a node from the linkgraph @type concert_msgs.LinkNode @param linkgraph : the entire linkgraph (used to lookup the node's edges) @type concert_msgs.LinkGraph @return resource @rtype scheduler_msgs.Resource ''' resource = scheduler_msgs.Resource() resource.rapp = rocon_uri.parse(node.resource).rapp resource.uri = node.resource resource.remappings = [rocon_std_msgs.Remapping(e.remap_from, e.remap_to) for e in linkgraph.edges if e.start == node.id or e.finish == node.id] resource.parameters = [rocon_std_msgs.KeyValue(key,str(val)) for key, val in node.parameters.items()] return resource
def ros_capture_teleop_callback(self, request_id, msg): ''' Processes the service pair server 'capture_teleop'. This will run in a thread of its own for each request. It has a significantly long lock though - this needs to get fixed. ''' response = rocon_service_msgs.CaptureTeleopResponse() response.result = False # Todo : request the scheduler for this resource, # use self.allocation_timeout to fail gracefully self.lock.acquire() if not msg.release: # i.e. we're capturing: if msg.rocon_uri not in [r.uri for r in self.teleopable_robots]: rospy.logwarn( "TeleopPimp : couldn't capture teleopable robot [not available][%s]" % msg.rocon_uri) response.result = False self.allocate_teleop_service_pair_server.reply( request_id, response) else: # send a request resource = scheduler_msgs.Resource() resource.id = unique_id.toMsg(unique_id.fromRandom()) resource.rapp = 'turtle_concert/teleop' resource.uri = msg.rocon_uri resource_request_id = self.requester.new_request([resource]) self.pending_requests.append(resource_request_id) self.requester.send_requests() timeout_time = time.time() + 5.0 while not rospy.is_shutdown() and time.time() < timeout_time: if resource_request_id not in self.pending_requests: self.allocated_requests[ msg.rocon_uri] = resource_request_id response.result = True break rospy.rostime.wallsleep(0.1) if response.result == False: rospy.logwarn( "TeleopPimp : couldn't capture teleopable robot [timed out][%s]" % msg.rocon_uri) self.requester.rset[resource_request_id].cancel() else: rospy.loginfo( "TeleopPimp : captured teleopable robot [%s][%s]" % (msg.rocon_uri, self.allocated_requests[msg.rocon_uri])) self.allocate_teleop_service_pair_server.reply( request_id, response) else: # we're releasing if msg.rocon_uri in self.allocated_requests.keys(): rospy.loginfo( "TeleopPimp : released teleopable robot [%s][%s]" % (msg.rocon_uri, self.allocated_requests[msg.rocon_uri].hex)) self.requester.rset[self.allocated_requests[ msg.rocon_uri]].cancel() self.requester.send_requests() response.result = True self.allocate_teleop_service_pair_server.reply( request_id, response) self.lock.release()
name='dude_bar', gateway_name='gateway_two', platform_info='linux.*.ros.pc.*', apps=apps) concert_client_msgs['dudette'] = concert_msgs.ConcertClient( name='dudette', gateway_name='gateway_three', platform_info='linux.*.ros.pc.dudette', apps=apps) concert_clients = {} for name, msg in concert_client_msgs.iteritems(): concert_clients[name] = concert_schedulers.common.ConcertClient(msg) resources = {} resources['dude'] = scheduler_msgs.Resource(name="rocon_apps/listener", platform_info="linux.*.ros.pc.*") resources['dudette'] = scheduler_msgs.Resource( name="rocon_apps/talker", platform_info="linux.*.ros.pc.dudette") ############################################################################## # Setups ############################################################################## def setup_chatter_configuration(): #global app_listener, app_talker, apps, concert_clients chatter_resources = [] chatter_resources.append(resources['dude']) chatter_resources.append(resources['dude']) chatter_resources.append(resources['dudette']) return chatter_resources, concert_clients