Exemple #1
0
        def callback(data):
          # Get field names ('/left_arm/sholder_pitch') from defined number (1)
          fields_num = self.field_subscription[message.type]
          fields_name = (
            self.field_table[field] 
            for field in fields_num
          )

          # Convert individual fields values
          for field_num in fields_num:
            if self.field_conv_table.has_key(field_num):
              value = get_attr(data, self.field_table[field_num])
              value = self.field_conv_table[field_num](value)
              set_attr(data, self.field_table[field_num], value)

          # Extract appropriate fields from the ROS message 
          if desc.has_key('ROS_field_map'):
            # There is a map between ROS messsage and embedded message.
            # Convert from ROS value to embedded value:
            d = attrs_to_dict(data, desc['fields'], desc['ROS_field_map'])
          else:
            d = attrs_to_dict(data, desc['fields'])

          d['array'] = []
          for field in fields_name:
            d[desc['fields'][-1]].append(get_attr(data, field))
          d['length'] = len(d[desc['fields'][-1]])
          if desc.has_key('ROS_emb_conv'):
            for key in desc['ROS_emb_conv'].keys():
              d[key] = desc['ROS_emb_conv'][key](d[key])
          self.send(message.type, **d)
Exemple #2
0
 def convert_ROS_to_embedded(self, desc, data):
   """
   Converts ROS topic/message to embedded message.
   
   Keyword arguments:
     desc -- Description of embedded message.
     data -- ROS message.
   """
   if desc.has_key('ROS_field_map'):
     # There is a map between ROS messsage and embedded message:
     d = attrs_to_dict(data, desc['fields'], desc['ROS_field_map'])
   else:
     d = attrs_to_dict(data, desc['fields'])
   if desc.has_key('ROS_emb_conv'):
     for key in desc['ROS_emb_conv'].keys():
       d[key] = desc['ROS_emb_conv'][key](d[key])
   return d