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()
def add_arm_target_to_action(self): '''Add a new ArmTarget primitive to the current action.''' if self.n_actions() > 0: arm_state = self._robot.get_arm_state() gripper_state = self._robot.get_gripper_state() rospy.loginfo("gripper_state: {}".format(gripper_state)) current_action = self._actions[self._current_action_id] primitive_number = current_action.n_primitives() arm_target = ArmTarget(self._robot, self._tf_listener, self._im_server, arm_state, gripper_state, primitive_number) current_action.add_primitive(arm_target) else: rospy.logwarn("Can't add primitive: No actions created yet.") self._update_session_state()
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
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 self._actions[self._current_action_id].add_primitive(primitive_copy) self._actions[self._current_action_id].update_viz() self._update_session_state()