8 """Class for controlling iCub simulator via its RPC world port."""
12 self.
_port_name_port_name =
"/WorldController-" + str(id(self)) +
"/commands"
14 self.
_rpc_client_rpc_client.addOutput(
"/icubSim/world")
23 def _execute(self, cmd):
24 """Execute an RPC command, returning obtained answer bottle."""
29 def _is_success(self, ans):
30 """Check if RPC call answer Bottle indicates successfull execution."""
31 return ans.size() == 1
and ans.get(0).asVocab() == 27503
33 def _prepare_del_all_command(self):
34 """Prepare the "world del all" command bottle."""
35 result = yarp.Bottle()
37 map(result.addString, [
"world",
"del",
"all" ])
40 def _prepare_create_command(self, obj, size, location, colour):
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)
67 def _prepare_move_command(self, obj, obj_id, location):
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)
78 def _prepare_rot_command(self, obj, obj_id, rotation):
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)
89 def _prepare_get_command(self, obj, obj_id):
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."""
112 return len(self.
_objects_objects) - 1
117 """Move an object specified by the internal id to another location."""
118 obj_desc = self.
_objects_objects[obj_id]
122 """Rotate an object specified by the internal id giving its absolute rotation."""
123 obj_desc = self.
_objects_objects[obj_id]
127 """Obtain the object location from the simulator. Returns None on failure."""
128 obj_desc = self.
_objects_objects[obj_id]
130 if result.size() == 3:
131 return [ result.get(i).asDouble()
for i
in xrange(3) ]
136 """Delete all objects from the simultor"""
152 except AttributeError:
def create_object(self, obj, size, location, colour)
def _prepare_del_all_command(self)
def get_object_location(self, obj_id)
def rotate_object(self, obj_id, rotation)
def _prepare_move_command(self, obj, obj_id, location)
def _is_success(self, ans)
def _prepare_get_command(self, obj, obj_id)
def move_object(self, obj_id, location)
def _prepare_create_command(self, obj, size, location, colour)
def _prepare_rot_command(self, obj, obj_id, rotation)
void append(const size_t index, shared_ptr< Epsilon_neighbours_t > en)
yarp::sig::Vector & map(yarp::sig::Vector &v, double(op)(double))
Performs a unary operator inplace on each element of a vector.
bool write(const std::string filename, const FullRegulation ®)