Ejemplo n.º 1
0
    def state(self):
        p_pelvis = self.skel.getBodyPositionGlobal(0)
        R_pelvis = self.skel.getBodyOrientationGlobal(0)

        phase = min(1., (self.world.GetSimulationTime() + self.time_offset) /
                    self.motion_time)
        state = [phase]

        self.skel.getBodyPositionsGlobal()

        p = np.array([
            np.dot(R_pelvis.T, body_pos - p_pelvis)
            for body_pos in self.skel.getBodyPositionsGlobal()
        ]).flatten()
        R = np.array([
            mm.rot2quat(np.dot(R_pelvis.T, body_ori))
            for body_ori in self.skel.getBodyOrientationsGlobal()
        ]).flatten()
        v = np.array([
            np.dot(R_pelvis.T, body_vel)
            for body_vel in self.skel.getBodyVelocitiesGlobal()
        ]).flatten()
        w = np.array([
            np.dot(R_pelvis.T, body_angvel) / 20.
            for body_angvel in self.skel.getBodyAngVelocitiesGlobal()
        ]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)

        return np.asarray(state).flatten()
Ejemplo n.º 2
0
    def state(self):
        pelvis = self.skel.body(0)
        p_pelvis = pelvis.world_transform()[:3, 3]
        R_pelvis = pelvis.world_transform()[:3, :3]

        phase = min(1.,
                    (self.world.time() + self.time_offset) / self.motion_time)
        state = [phase]

        p = np.array([
            np.dot(R_pelvis.T,
                   body.to_world() - p_pelvis) for body in self.skel.bodynodes
        ]).flatten()
        R = np.array([
            mm.rot2quat(np.dot(R_pelvis.T,
                               body.world_transform()[:3, :3]))
            for body in self.skel.bodynodes
        ]).flatten()
        v = np.array([
            np.dot(R_pelvis.T, body.world_linear_velocity())
            for body in self.skel.bodynodes
        ]).flatten()
        w = np.array([
            np.dot(R_pelvis.T, body.world_angular_velocity()) / 20.
            for body in self.skel.bodynodes
        ]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)

        return np.asarray(state).flatten()
Ejemplo n.º 3
0
    def state(self):
        pelvis = self.skel.body(0)
        p_pelvis = pelvis.world_transform()[:3, 3]
        R_pelvis = pelvis.world_transform()[:3, :3]

        phase = min(1., (self.world.time() + self.time_offset)/self.motion_time)
        if self.env_name == 'walk_repeated':
            if self.phase_frame <= 156:
                phase = self.phase_frame / 156.
            else:
                phase = ((self.phase_frame - 113) % 43 + 113)/156.

        state = [phase]

        p = np.array([np.dot(R_pelvis.T, body.to_world() - p_pelvis) for body in self.skel.bodynodes]).flatten()
        R = np.array([mm.rot2quat(np.dot(R_pelvis.T, body.world_transform()[:3, :3])) for body in self.skel.bodynodes]).flatten()
        v = np.array([np.dot(R_pelvis.T, body.world_linear_velocity()) for body in self.skel.bodynodes]).flatten()
        w = np.array([np.dot(R_pelvis.T, body.world_angular_velocity())/20. for body in self.skel.bodynodes]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)

        return np.asarray(state).flatten()
Ejemplo n.º 4
0
    def state(self):
        state = [self.goal[0], self.goal[1]]

        pelvis = self.skel.body(0)
        p_pelvis = pelvis.world_transform()[:3, 3]
        R_pelvis = pelvis.world_transform()[:3, :3]

        ref_pelvis = self.ref_skel.body(0)
        ref_p_pelvis = ref_pelvis.world_transform()[:3, 3]
        ref_R_pelvis = ref_pelvis.world_transform()[:3, :3]

        # deep mimic style
        p = np.array([np.dot(R_pelvis.T, body.to_world() - p_pelvis) for body in self.skel.bodynodes]).flatten()
        R = np.array([mm.rot2quat(np.dot(R_pelvis.T, body.world_transform()[:3, :3])) for body in self.skel.bodynodes]).flatten()
        v = np.array([np.dot(R_pelvis.T, body.world_linear_velocity()) for body in self.skel.bodynodes]).flatten()
        w = np.array([np.dot(R_pelvis.T, body.world_angular_velocity())/20. for body in self.skel.bodynodes]).flatten()
        ref_p = np.array([np.dot(ref_R_pelvis.T, body.to_world() - ref_p_pelvis) for body in self.ref_skel.bodynodes]).flatten()
        ref_R = np.array([mm.rot2quat(np.dot(ref_R_pelvis.T, body.world_transform()[:3, :3])) for body in self.ref_skel.bodynodes]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)
        state.extend(ref_p)
        state.extend(ref_R)

        # soohwan style
        # p = 0.8 * np.array([np.dot(R_pelvis.T, body.to_world() - p_pelvis) for body in self.skel.bodynodes]).flatten()
        # v = 0.2 * np.array([np.dot(R_pelvis.T, body.world_linear_velocity()) for body in self.skel.bodynodes]).flatten()
        # _R = 2. * self.skel.positions()
        # _w = .2 * self.skel.velocities()
        # R = np.append(_R[:3], _R[6:]).flatten()
        # w = np.append(_w[:3], _w[6:]).flatten()
        # _ref_R = 2. * self.prev_ref_q
        # ref_R = np.append(_ref_R[:3], _ref_R[6:]).flatten()

        # state.extend(p)
        # state.extend(R)
        # state.extend(v)
        # state.extend(w)
        # state.extend(ref_R)

        return np.asarray(state).flatten()
Ejemplo n.º 5
0
    def state(self):
        pelvis = self.skel.body(0)
        p_pelvis = pelvis.world_transform()[:3, 3]
        R_pelvis = pelvis.world_transform()[:3, :3]

        phase = min(1.,
                    (self.world.time() + self.time_offset) / self.motion_time)
        state = [
            0. if len(self.ref_motions) == 1 else self.specified_motion_num /
            (len(self.ref_motions) - 1), phase
        ]

        p = np.array([
            np.dot(R_pelvis.T,
                   body.to_world() - p_pelvis) for body in self.skel.bodynodes
        ]).flatten()
        R = np.array([
            mm.rot2quat(np.dot(R_pelvis.T,
                               body.world_transform()[:3, :3]))
            for body in self.skel.bodynodes
        ]).flatten()
        v = np.array([
            np.dot(R_pelvis.T, body.world_linear_velocity())
            for body in self.skel.bodynodes
        ]).flatten()
        w = np.array([
            np.dot(R_pelvis.T, body.world_angular_velocity()) / 20.
            for body in self.skel.bodynodes
        ]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)
        # print('p', np.linalg.norm(p))
        # print('R', np.linalg.norm(R))
        # print('v', np.linalg.norm(v))
        # print('w', np.linalg.norm(w))

        return np.asarray(state).flatten()
Ejemplo n.º 6
0
    def state(self):
        pelvis = self.skel.body(0)
        p_pelvis = pelvis.world_transform()[:3, 3]
        R_pelvis = pelvis.world_transform()[:3, :3]

        state = []
        state.extend(np.asarray(self.goals).flatten())

        p = np.array([np.dot(R_pelvis.T, body.to_world() - p_pelvis) for body in self.skel.bodynodes]).flatten()
        R = np.array([mm.rot2quat(np.dot(R_pelvis.T, body.world_transform()[:3, :3])) for body in self.skel.bodynodes]).flatten()
        v = np.array([np.dot(R_pelvis.T, body.world_linear_velocity()) for body in self.skel.bodynodes]).flatten()
        w = np.array([np.dot(R_pelvis.T, body.world_angular_velocity())/20. for body in self.skel.bodynodes]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)
        # print('p', np.linalg.norm(p))
        # print('R', np.linalg.norm(R))
        # print('v', np.linalg.norm(v))
        # print('w', np.linalg.norm(w))

        return np.asarray(state).flatten()
Ejemplo n.º 7
0
    def state(self):
        p_pelvis = self.skel.body(0).world_transform()[:3, 3]
        R_pelvis = self.skel.body(0).world_transform()[:3, :3]

        phase = (self.world.time() + self.time_offset) / self.total_time
        state = [phase]

        p = np.array([
            self.skel.body(i).to_world() - p_pelvis
            for i in range(self.body_num)
        ]).flatten()
        # R = [mm.logSO3(np.dot(R_pelvis.T, self.skel.body(i).world_transform()[:3, :3]))/pi for i in range(self.body_num)]
        R = np.array([
            mm.rot2quat(
                np.dot(R_pelvis.T,
                       self.skel.body(i).world_transform()[:3, :3]))
            for i in range(self.body_num)
        ]).flatten()
        v = np.array([
            self.skel.body(i).world_linear_velocity()
            for i in range(self.body_num)
        ]).flatten()
        w = np.array([
            self.skel.body(i).world_angular_velocity() / 20.
            for i in range(self.body_num)
        ]).flatten()

        state.extend(p)
        state.extend(R)
        state.extend(v)
        state.extend(w)
        # print('p', np.linalg.norm(p))
        # print('R', np.linalg.norm(R))
        # print('v', np.linalg.norm(v))
        # print('w', np.linalg.norm(w))

        return np.asarray(state).flatten()