Пример #1
0
    def build_from_json(self, json):
        '''Fills out action using information using json from db

        Args:
            dict : json/dict retrieved from couchdb
        '''
        self._action_id = json['id']
        self._name = json['name']
        self._primitive_counter = json['primitive_counter']
        for primitive in json['seq']:
            if primitive.has_key('arm_target'):
                target = primitive['arm_target']
                primitive = ArmTarget(self._robot, self._tf_listener,
                                      self._im_server)
                primitive.build_from_json(target)

            elif primitive.has_key('arm_trajectory'):
                target = primitive['arm_trajectory']
                primitive = ArmTrajectory(self._robot, self._tf_listener,
                                          self._im_server)
                primitive.build_from_json(target)

            self.add_primitive(primitive, False, False)

        self.reset_viz()
Пример #2
0
 def start_recording_arm_trajectory(self):
     '''Creates ArmTrajectory primitive that will be updated
     by update_arm_trajectory
     '''
     current_action = self._actions[self._current_action_id]
     primitive_number = current_action.n_primitives()
     self._current_arm_trajectory = ArmTrajectory(self._robot,
                                                  self._tf_listener,
                                                  self._im_server,
                                                  primitive_number)
Пример #3
0
    def copy_primitive(self, primitive_number):
        '''Make a copy of a primitive

        Args:
            primitive (int)
        '''
        # new_id = self.n_actions()

        map_fun = '''function(doc) {
                     emit(doc.id, doc);
                  }'''

        results = self._db.query(map_fun)

        # Load data from db into Action objects.
        new_num = self.n_primitives()
        for result in results:
            if int(result.value['id']) == self._current_action_id:
                for idx, primitive in enumerate(result.value['seq']):
                    if idx == primitive_number:
                        if primitive.has_key('arm_target'):
                            target = primitive['arm_target']
                            primitive_copy = ArmTarget(self._robot,
                                                       self._tf_listener,
                                                       self._im_server)
                            primitive_copy.build_from_json(target)
                            primitive_copy.set_primitive_number(new_num)
                            break

                        elif primitive.has_key('arm_trajectory'):
                            target = primitive['arm_trajectory']
                            primitive_copy = ArmTrajectory(
                                self._robot, self._tf_listener,
                                self._im_server)
                            primitive_copy.build_from_json(target)
                            primitive_copy.set_primitive_number(new_num)
                            break
                        elif primitive.has_key('grasp'):
                            target = primitive['grasp']
                            primitive_copy = Grasp(
                                self._robot, self._tf_listener,
                                self._im_server,
                                self._grasp_suggestion_service,
                                self._grasp_feedback_topic,
                                self._external_ee_link)
                            primitive_copy.build_from_json(target)
                            primitive_copy.set_primitive_number(new_num)
                            break

        self._actions[self._current_action_id].add_primitive(primitive_copy)

        self._actions[self._current_action_id].update_viz()

        self._update_session_state()
Пример #4
0
    def build_from_json(self, json):
        '''Fills out action using information using json from db

        Args:
            dict : json/dict retrieved from couchdb
        '''
        enabled = True
        self._action_id = json['id']
        self._name = json['name']
        self._primitive_counter = json['primitive_counter']
        for primitive in json['seq']:
            if primitive.has_key('arm_target'):
                target = primitive['arm_target']
                primitive = ArmTarget(self._robot, self._tf_listener,
                              self._im_server)
                primitive.build_from_json(target)

            elif primitive.has_key('arm_trajectory'):
                target = primitive['arm_trajectory']
                primitive = ArmTrajectory(self._robot, self._tf_listener,
                                  self._im_server)
                primitive.build_from_json(target)
            elif primitive.has_key('grasp'):
                if self._grasp_suggestion_service == "":
                    enabled = False
                target = primitive['grasp']
                primitive = Grasp(self._robot, self._tf_listener,
                            self._im_server, 
                            self._grasp_im_server,
                            self._grasp_suggestion_service,
                            self._grasp_feedback_topic,
                            self._external_ee_link)
                primitive.build_from_json(target)

            self.add_primitive(primitive, False, False)

        self.reset_viz()
        return enabled