def to_msg(self): ''' Converts this app definition to ros msg format. :returns: ros message format of Rapp :rtype: rocon_app_manager_msgs.Rapp ''' a = rapp_manager_msgs.Rapp() a.name = self.data['name'] a.display_name = self.data['display_name'] a.description = self.data['description'] a.compatibility = self.data['compatibility'] a.status = self.data['status'] a.icon = rocon_python_utils.ros.icon_to_msg(self.data['icon']) a.implementations = [] key = 'public_interface' if key in self.data: a.public_interface = [rocon_std_msgs.KeyValue(key, str(val)) for key, val in self.data[key].items()] key = 'public_parameters' if key in self.data: a.public_parameters = [rocon_std_msgs.KeyValue(str(key), str(val)) for key, val in self.data[key].items()] return a
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 _load_profile(self): ''' load profile from filepath ''' msg = concert_msgs.SoftwareProfile() with open(self._filepath) as f: loaded_profile = yaml.load(f) if not 'launch' in loaded_profile: raise InvalidSoftwareprofileException("'launch' field does not exist!!!") msg.resource_name = loaded_profile['resource_name'] = self.resource_name msg.name = loaded_profile['name'] = loaded_profile['name'].lower().replace(" ", "_") msg.description = loaded_profile['description'] if 'description' in loaded_profile else "" msg.author = loaded_profile['author'] if 'author' in loaded_profile else "" msg.max_count = loaded_profile['max_count'] if 'max_count' in loaded_profile else -1 msg.launch = loaded_profile['launch'] msg.parameters = [] if 'parameters' in loaded_profile: for kv in loaded_profile['parameters']: msg.parameters.append(rocon_std_msgs.KeyValue(str(kv['name']), str(kv['value']))) # generate message self.msg = msg self.name = msg.name
def validate_parameters(self, given): ''' validates the given parameter is usable for this software. :param given rocon_std_msgs/KeyValue[]: parameter to validate :returns: whether it is successful or not, the updated parameters, msg :rtypes: bool, [rocon_std_msgs.KeyValue], str ''' default = self.msg.parameters default_dict = { i.key:i.value for i in default} given_dict = {i.key:i.value for i in given} # Check if given parameters are invalid d_keys = default_dict.keys() is_invalid = False invalid_params = [] for k in given_dict.keys(): if not k in d_keys: invalid_params.append(k) is_invalid = True if is_invalid: msg = "Invalid parameter is given. %s"%str(invalid_params) return False, [], msg # Assign params = {} for key, value in default_dict.items(): params[key] = given_dict[key] if key in given_dict else value params_keyvalue = [rocon_std_msgs.KeyValue(key, value) for key, value in params.items()] return True, params_keyvalue, "Success"
def dict_to_KeyValue(d): ''' Converts a dictionary to key value ros msg type. ''' l = [] for k, v in d.iteritems(): l.append(rocon_std_msgs.KeyValue(k, str(v))) return l
def dict_to_key_value_msg(d): ''' Converts a dictionary to key value ros msg type. :param d: dictionary :type d: dict :returns: KeyValue ros message :rtype: [rocon_std_msgs.KeyValue] ''' l = [] for k, v in d.iteritems(): l.append(rocon_std_msgs.KeyValue(k, str(v))) return l
def _prepare_start_rapp(self): parameters = [] for name, box in self._parameters_items: if isinstance(box, QCheckBox): value = "true" if box.isChecked() else "false" else: value = box.toPlainText().strip() parameters.append(rocon_std_msgs.KeyValue(name, value)) remappings = [(k, v.toPlainText().strip()) for k, v in self._remappings_items if k != v.toPlainText().strip()] impl = self.rapp_impls.currentText() return impl, remappings, parameters
def _convert_to_device_msgs(self, device_raw_data): msgs = [] for dev_id in device_raw_data: device = device_raw_data[dev_id] if device['has_subdevice_count'] is 1: for sdev_id in device['subDevices']: sub_device = device['subDevices'][sdev_id] dev = rocon_device_msgs.Device() dev.label = sub_device['shortName'] dev.type = self._type_converter(dev.label) dev.uuid = str(dev_id) + '_' + str(sub_device['data']) dev.data.append( rocon_std_msgs.KeyValue('guid', str(dev_id))) dev.data.append(rocon_std_msgs.KeyValue('data', '')) msgs.append(dev) else: dev = rocon_device_msgs.Device() dev.label = device['shortName'].replace(' ', '_').lower() dev.type = device['device_type'] dev.uuid = str(dev_id) dev.data.append(rocon_std_msgs.KeyValue('data', '')) dev.data.append(rocon_std_msgs.KeyValue('guid', str(dev_id))) msgs.append(dev) return msgs
def set_srv_parameters(self, srv_name, param_data): result = False message = "" try: srv_profile_msg = concert_msgs.ServiceProfile() srv_profile_msg.name = srv_name parameter_detail = [] for key in param_data.keys(): parameter = rocon_std_msgs.KeyValue(key, param_data[key]) parameter_detail.append(parameter) srv_profile_msg.parameters_detail = parameter_detail (result, message) = self.update_service_config(srv_profile_msg) except Exception, e: rospy.loginfo(e) message = str(e) result = False
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 convert_post_to_devices_msg(self, post): device = post['topic'] device_data = post['data'] dev_label, dev_type, dev_uuid = device.split("/") dev = rocon_device_msgs.Device() dev.label = str(dev_label) dev.type = str(dev_type) dev.uuid = str(dev_uuid) dev.data = [ rocon_std_msgs.KeyValue(str(key), str(value)) for key, value in device_data.items() ] msg = rocon_device_msgs.Devices() msg.devices = [] msg.devices.append(dev) return msg
def rapp_msg_to_dict(msg): rapp = {} rapp["status"] = msg.status rapp["name"] = msg.name rapp["display_name"] = msg.display_name rapp["description"] = msg.description rapp["compatibility"] = msg.compatibility rapp["preferred"] = msg.preferred rapp["icon"] = msg.icon rapp["implementations"] = msg.implementations rapp["public_interface"] = msg.public_interface rapp["public_parameters"] = [] for parameter in msg.public_parameters: if parameter.value.lower() == "false": value = False elif parameter.value.lower() == "true": value = True else: value = parameter.value rapp["public_parameters"].append(rocon_std_msgs.KeyValue(parameter.key, value)) return rapp
def _service_profile_to_msg(self, loaded_profile): """ Change service proflies data to ros message :returns: generated service profile message :rtype: [concert_msgs.ServiceProfile] """ msg = concert_msgs.ServiceProfile() msg.uuid = unique_id.toMsg(unique_id.fromRandom()) # todo change more nice method if 'resource_name' in loaded_profile: msg.resource_name = loaded_profile['resource_name'] if 'name' in loaded_profile: msg.name = loaded_profile['name'] if 'description' in loaded_profile: msg.description = loaded_profile['description'] if 'author' in loaded_profile: msg.author = loaded_profile['author'] if 'priority' in loaded_profile: msg.priority = loaded_profile['priority'] if 'launcher_type' in loaded_profile: msg.launcher_type = loaded_profile['launcher_type'] if 'icon' in loaded_profile: msg.icon = rocon_python_utils.ros.icon_resource_to_msg(loaded_profile['icon']) if 'launcher' in loaded_profile: msg.launcher = loaded_profile['launcher'] if 'interactions' in loaded_profile: msg.interactions = loaded_profile['interactions'] if 'parameters' in loaded_profile: msg.parameters = loaded_profile['parameters'] if 'parameters_detail' in loaded_profile: for param_key in loaded_profile['parameters_detail'].keys(): msg.parameters_detail.append(rocon_std_msgs.KeyValue(param_key, str(loaded_profile['parameters_detail'][param_key]))) # t = type(loaded_profile['parameters_detail'][param_key]) # if t is list or t is dict: # msg.parameters_detail.append(rocon_std_msgs.KeyValue(param_key, eval(loaded_profile['parameters_detail'][param_key]))) # else: # msg.parameters_detail.append(rocon_std_msgs.KeyValue(param_key, str(loaded_profile['parameters_detail'][param_key]))) return msg
def create_web_video_parameters(address, port): params = [] params.append(rocon_std_msgs.KeyValue('address', str(address))) params.append(rocon_std_msgs.KeyValue('port', str(port))) return params