def handle_set(self, request): """ Handles the set field of a request. The set field is constructed as follows:: { 'set': { 'obj_name_1': {'var_path_1': value, 'var_path_2': value, # ... }, 'obj_name_2': {'var_path_1': value, 'var_path_2': value, # ... }, # ... } } For each triple obj_name_1, var_path_1, value the handler will set the corresponding value to self.robot.obj_name_1.var_path_1: i.e. if we want to set the goal_position and goal_speed of the motor named l_knee_y to resp. 0 and 100 we would use:: { 'set': { 'l_knee_y': {'goal_position': 0, 'present_speed': 100}, } } .. note:: The var_path could be complete path, e.g. "skeleton.left_foot.position.x". """ for obj_name, value_pairs in request.iteritems(): obj = getattr(self.robot, obj_name) for var_path, value in value_pairs.iteritems(): attrsetter(var_path)(obj, value)
def action(self, new_action): self._action_output = new_action self._action = lambda x: attrsetter(self._action_output)(self.robot, x)