8    """Class for controlling iCub simulator via its RPC world port.""" 
   12        self.
_port_name = 
"/WorldController-" + str(id(self)) + 
"/commands" 
 
   24        """Execute an RPC command, returning obtained answer bottle.""" 
 
   30        """Check if RPC call answer Bottle indicates successfull execution.""" 
   31        return ans.size() == 1 
and ans.get(0).asVocab() == 27503 
 
 
   34        """Prepare the "world del all" command bottle.""" 
   35        result = yarp.Bottle()
 
   37        map(result.addString, [ 
"world", 
"del", 
"all" ])
 
 
   41        """Prepare an RPC command for creating an object in the simulator environment. 
   43        See Simulator Readme section 'Object Creation' 
   46            obj - object type string. 'sph', 'box', 'cyl' 'ssph', 'sbox' or 'scyl'. 
   47            size - list of values specifying the size of an object. Parameters depend on object type: 
   50                (s)cyl: [ radius, length ] 
   51            location - coordinates of the object location, [ x, y, z ] 
   52            colour - object colour in RGB (normalised), [ r, g, b ] 
   54            yarp.Bottle with the command, ready to be sent to the rpc port of the simulator 
   57        result = yarp.Bottle()
 
   60        map(result.addString, [
"world", 
"mk", obj])
 
   61        map(result.addDouble, size)
 
   62        map(result.addDouble, location)
 
   63        map(result.addDouble, colour)
 
 
   68        """Prepare the "world set <obj> <xyz>" command bottle.""" 
   69        result = yarp.Bottle()
 
   72        map(result.addString, [
"world", 
"set", obj])
 
   74        map(result.addDouble, location)
 
 
   79        """Prepare the "world rot <obj> <rotxyz>" command bottle.""" 
   80        result = yarp.Bottle()
 
   83        map(result.addString, [
"world", 
"rot", obj])
 
   85        map(result.addDouble, rotation)
 
 
   90        """Prepare the "world get <obj> <id>" command bottle.""" 
   91        result = yarp.Bottle()
 
   94        map(result.addString, [
"world", 
"get", obj])
 
 
  100        """Create an object of a specified type, size, location and colour, returning internal object ID or -1 on error.""" 
  108            self.
_objects.append((obj, obj_sim_id))
 
 
  117        """Move an object specified by the internal id to another location.""" 
 
  122        """Rotate an object specified by the internal id giving its absolute rotation.""" 
 
  127        """Obtain the object location from the simulator. Returns None on failure.""" 
  130        if result.size() == 3:
 
  131            return [ result.get(i).asDouble() 
for i 
in xrange(3) ] 
 
 
  136        """Delete all objects from the simultor""" 
  137        result = self._is_success(self._execute(self._prepare_del_all_command())) 
  141            self._sim_ids_counters.clear() 
 
  148            if self._rpc_client <> None: 
  150            self._rpc_client.close() 
  152        except AttributeError: 
 
 
move_object(self, obj_id, location)
 
get_object_location(self, obj_id)
 
_prepare_del_all_command(self)
 
_prepare_move_command(self, obj, obj_id, location)
 
_prepare_rot_command(self, obj, obj_id, rotation)
 
create_object(self, obj, size, location, colour)
 
_prepare_get_command(self, obj, obj_id)
 
rotate_object(self, obj_id, rotation)
 
_prepare_create_command(self, obj, size, location, colour)