예제 #1
0
    def _set_action(self, action):

        assert action.shape == (self.n_actions,)
        action = action.copy()  # ensure that we don't change the action outside of this scope
        action_obj = action[4:]
        action_obj = action_obj.reshape(self.n_obj_mocaps, -1)
        
        pos_ctrl, gripper_ctrl = action[:3], action[3]
        obj_ctrl = np.concatenate((np.zeros((self.n_obj_mocaps, 3)), 
                                    np.ones((self.n_obj_mocaps, 1)), np.zeros((self.n_obj_mocaps, 3))), axis=1)
        for i_action in range(len(self.obj_action_type)):
            obj_ctrl[:,self.obj_action_type[i_action]] = action_obj[:,i_action]

        pos_ctrl *= 0.05  # limit maximum change in position
        rot_ctrl = [1., 0., 1., 0.]  # fixed rotation of the end effector, expressed as a quaternion
        gripper_ctrl = np.array([gripper_ctrl, gripper_ctrl])
        assert gripper_ctrl.shape == (2,)
        if self.block_gripper:
            gripper_ctrl = np.zeros_like(gripper_ctrl)

        if self.ai_object:
            obj_ctrl *= 0.05
        else:
            obj_ctrl *= 0.00

        obj_ctrl = np.concatenate((obj_ctrl, np.zeros((self.sim.model.nmocap-self.n_obj_mocaps-1, 7))), axis=0)

        action = np.concatenate([pos_ctrl, rot_ctrl, obj_ctrl.ravel(), gripper_ctrl])

        # Apply action to simulation.
        utils.ctrl_set_action(self.sim, action)
        utils.mocap_set_action(self.sim, action)
예제 #2
0
    def _set_action(self, action):

        assert action.shape == (self.n_actions, )
        action = action.copy(
        )  # ensure that we don't change the action outside of this scope
        #pdb.set_trace()

        ctrlrange = self.sim.model.actuator_ctrlrange
        actuation_range = (ctrlrange[:, 1] - ctrlrange[:, 0]) / 2.
        #actuation_center = (ctrlrange[:, 1] + ctrlrange[:, 0]) / 2.
        actuation_center = np.zeros_like(action[:9])
        for i in range(self.sim.data.ctrl.shape[0]):
            actuation_center[i] = self.sim.data.get_joint_qpos(
                self.sim.model.actuator_names[i].replace(':A_', ':'))

        pos_ctrl, gripper_ctrl = action[:7], action[7]
        #pos_ctrl *= 0.05

        gripper_ctrl = np.array([gripper_ctrl, gripper_ctrl])
        assert gripper_ctrl.shape == (2, )
        if self.block_gripper:
            gripper_ctrl = np.zeros_like(gripper_ctrl)

        self.sim.data.ctrl[:
                           7] = actuation_center[:
                                                 7] + pos_ctrl * actuation_range[:
                                                                                 7]
        self.sim.data.ctrl[:7] = np.clip(self.sim.data.ctrl[:7],
                                         ctrlrange[:7, 0], ctrlrange[:7, 1])

        self.sim.data.ctrl[7:9] = gripper_ctrl

        # object actions
        action_obj = action[8:]
        action_obj = action_obj.reshape(self.n_objects, -1)

        obj_ctrl = np.concatenate((np.zeros(
            (self.n_objects, 3)), np.ones(
                (self.n_objects, 1)), np.zeros((self.n_objects, 3))),
                                  axis=1)
        for i_action in range(len(self.obj_action_type)):
            obj_ctrl[:, self.obj_action_type[i_action]] = action_obj[:,
                                                                     i_action]

        if self.ai_object:
            obj_ctrl *= 0.05
        else:
            obj_ctrl *= 0.00

        obj_ctrl = np.concatenate(
            (obj_ctrl, np.zeros((self.sim.model.nmocap - self.n_objects, 7))),
            axis=0)

        action_obj = np.concatenate([obj_ctrl.ravel()])

        utils.mocap_set_action(self.sim, action_obj)
예제 #3
0
    def _set_action(self, action):

        assert action.shape == (self.n_actions, )
        action = action.copy(
        )  # ensure that we don't change the action outside of this scope

        ctrlrange = self.sim.model.actuator_ctrlrange
        actuation_range = (ctrlrange[:, 1] - ctrlrange[:, 0]) / 2.
        if self.relative_control:
            actuation_center = np.zeros_like(action[:20])
            for i in range(self.sim.data.ctrl.shape[0]):
                actuation_center[i] = self.sim.data.get_joint_qpos(
                    self.sim.model.actuator_names[i].replace(':A_', ':'))
            for joint_name in ['FF', 'MF', 'RF', 'LF']:
                act_idx = self.sim.model.actuator_name2id(
                    'robot0:A_{}J1'.format(joint_name))
                actuation_center[act_idx] += self.sim.data.get_joint_qpos(
                    'robot0:{}J0'.format(joint_name))
        else:
            actuation_center = (ctrlrange[:, 1] + ctrlrange[:, 0]) / 2.
        self.sim.data.ctrl[:] = actuation_center + action[:20] * actuation_range
        self.sim.data.ctrl[:] = np.clip(self.sim.data.ctrl, ctrlrange[:, 0],
                                        ctrlrange[:, 1])

        # object actions
        action_obj = action[20:]
        action_obj = action_obj.reshape(self.n_objects, -1)

        obj_ctrl = np.concatenate((np.zeros(
            (self.n_objects, 3)), np.ones(
                (self.n_objects, 1)), np.zeros((self.n_objects, 3))),
                                  axis=1)

        #for i_action in range(len(self.obj_action_type)):
        #    if self.obj_action_type[i_action] > 2:
        #        obj_ctrl[:,self.obj_action_type[i_action]] = action_obj[:,i_action] * 0.05
        #    else:
        #        obj_ctrl[:,self.obj_action_type[i_action]] = action_obj[:,i_action] * 0.05

        for i_action in range(len(self.obj_action_type)):
            obj_ctrl[:, self.obj_action_type[i_action]] = action_obj[:,
                                                                     i_action]

        if self.ai_object:
            obj_ctrl *= 0.05
        else:
            obj_ctrl *= 0.00

        action_obj = np.concatenate([obj_ctrl.ravel()])

        utils.mocap_set_action(self.sim, action_obj)
예제 #4
0
    def _set_action(self, action):
        assert action.shape == (4, )
        action = action.copy(
        )  # ensure that we don't change the action outside of this scope
        pos_ctrl, gripper_ctrl = action[:3], action[3]

        pos_ctrl *= 0.05  # limit maximum change in position
        rot_ctrl = [
            1., 0., 1., 0.
        ]  # fixed rotation of the end effector, expressed as a quaternion
        gripper_ctrl = np.array([gripper_ctrl, gripper_ctrl])
        assert gripper_ctrl.shape == (2, )
        if self.block_gripper:
            gripper_ctrl = np.zeros_like(gripper_ctrl)
        action = np.concatenate([pos_ctrl, rot_ctrl, gripper_ctrl])

        # Apply action to simulation.
        utils.ctrl_set_action(self.sim, action)
        utils.mocap_set_action(self.sim, action)