Ejemplo n.º 1
0
 def handle_get(self, request):
     """ Handles the get field of a request.
         
         The get field is constructed as follows::
         
             {
                 'get': {
                     'obj_name_1': ('var_path_1', 'var_path_2', ...),
                     'obj_name_2': ('var_path_1', 'var_path_2', ...),
                     # ...
                     }
                 }
         
         For each couple obj_name_1, var_path_1, the handler will get the value corresponding to self.robot.obj_name_1.var_path_1: i.e. if we want to get the present_position and present_speed of the motor named l_knee_y we would use::
         
             {
                 'get': {
                     'l_knee_y': ('present_position', 'present_speed'),
                     }
                 }
         
         .. note:: The var_path could be complete path, e.g. "skeleton.left_foot.position.x".
         
         """
     answer = defaultdict(dict)
     
     for obj_name, paths in request.iteritems():
         obj = getattr(self.robot, obj_name) if obj_name else self.robot
         
         for var_path in paths:
             answer[obj_name][var_path] = attrgetter(var_path)(obj)
 
     return answer
Ejemplo n.º 2
0
    def handle_get(self, request):
        """ Handles the get field of a request.

            The get field is constructed as follows::

                {
                    'get': {
                        'obj_name_1': ('var_path_1', 'var_path_2', ...),
                        'obj_name_2': ('var_path_1', 'var_path_2', ...),
                        # ...
                        }
                    }

            For each couple obj_name_1, var_path_1, the handler will get the value corresponding to self.robot.obj_name_1.var_path_1: i.e. if we want to get the present_position and present_speed of the motor named l_knee_y we would use::

                {
                    'get': {
                        'l_knee_y': ('present_position', 'present_speed'),
                        }
                    }

            .. note:: The var_path could be complete path, e.g. "skeleton.left_foot.position.x".

            """
        answer = defaultdict(dict)

        for obj_name, paths in request.iteritems():
            obj = getattr(self.robot, obj_name) if obj_name else self.robot

            for var_path in paths:
                answer[obj_name][var_path] = attrgetter(var_path)(obj)

        return answer
Ejemplo n.º 3
0
 def handle_call(self, request):
     """ Handles the call field of a request.
         
         The call field is constructed as follows::
         
             'call': {
                 'obj_name_1': {'meth_path_1': (arg1, arg2, ...),
                                 'meth_path_2': (arg1, arg2, ...),
                                 ...
                                 },
         
                 'obj_name_2': {'meth_path_1': (arg1, arg2, ...),
                                 'meth_path_2': (arg1, arg2, ...),
                                 ...
                                 },
                     ...
                     }
         
         For each tuple obj_name_1, meth_path_1 and args  the handler will call the corresponding method of the object with the args: i.e. if we want to call the switch_mode method of a primitive named 'balance' to switch to the third mode we would use::
         
             'call': {
                 'balance': {'switch_mode': (3, )}
                 }
         
         .. note:: To call a method without argument juste use an empty list as args::
         
             'call': {'balance': {'start': ()}}
         
         """
     answer = defaultdict(dict)
     
     for obj_name, meth_pairs in request.iteritems():
         obj = getattr(self.robot, obj_name)
         
         for meth, args in meth_pairs.iteritems():
             f = attrgetter(meth)(obj)
             answer[obj_name][meth] = f(args) if args else f()
     
     return answer
Ejemplo n.º 4
0
    def handle_call(self, request):
        """ Handles the call field of a request.

            The call field is constructed as follows::

                'call': {
                    'obj_name_1': {'meth_path_1': (arg1, arg2, ...),
                                    'meth_path_2': (arg1, arg2, ...),
                                    ...
                                    },

                    'obj_name_2': {'meth_path_1': (arg1, arg2, ...),
                                    'meth_path_2': (arg1, arg2, ...),
                                    ...
                                    },
                        ...
                        }

            For each tuple obj_name_1, meth_path_1 and args  the handler will call the corresponding method of the object with the args: i.e. if we want to call the switch_mode method of a primitive named 'balance' to switch to the third mode we would use::

                'call': {
                    'balance': {'switch_mode': (3, )}
                    }

            .. note:: To call a method without argument juste use an empty list as args::

                'call': {'balance': {'start': ()}}

            """
        answer = defaultdict(dict)

        for obj_name, meth_pairs in request.iteritems():
            obj = getattr(self.robot, obj_name)

            for meth, args in meth_pairs.iteritems():
                f = attrgetter(meth)(obj)
                answer[obj_name][meth] = f(*args) if args else f()

        return answer