-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplay_motion_ort.py
More file actions
49 lines (39 loc) · 1.82 KB
/
replay_motion_ort.py
File metadata and controls
49 lines (39 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pybullet as pb
import numpy as np
from scipy.spatial.transform import Rotation
import time
from argparse import ArgumentParser
from utils.params import ISAAC_TO_MUJOCO
from utils.math_utils import heading_quat
def set_joint_angles(robot_id, joint_angles):
j = 0
for i in range(pb.getNumJoints(robot_id)):
if pb.getJointInfo(robot_id, i)[2] == pb.JOINT_REVOLUTE:
pb.resetJointState(robot_id, i, joint_angles[j])
j += 1
parser = ArgumentParser()
parser.add_argument("--motion", type=str, required=True, help="Path to the motion file.")
args = parser.parse_args()
c = pb.connect(pb.GUI)
robot = pb.loadURDF("assets/g1/g1_29dof_kin_extended.urdf")
frame = pb.loadURDF("assets/frame.urdf")
motion = np.load(args.motion)
motion_length = motion["qpos"].shape[0]
fps = 50#float(motion["fps"])
init_root_pos = motion["qpos"][0,:3]
init_root_pos[2] = 0 # set initial height to 0
init_root_heading = Rotation.from_quat(heading_quat(motion["qpos"][0,3:7][[1,2,3,0]])) # xyzw to wxyz
frame_id = 13
while True:
for i in range(motion_length):
joint_pos = motion["qpos"][i,7:]
set_joint_angles(robot, joint_pos)
rel_root_pos = init_root_heading.inv().apply(motion["qpos"][i,:3] - init_root_pos)
rel_root_orn = (init_root_heading.inv() * Rotation.from_quat(motion["qpos"][i,3:7][[1,2,3,0]])).as_quat()
#rel_frame_pos = init_root_heading.inv().apply(motion["qpos"][i,frame_id] - init_root_pos)
#rel_frame_orn = (init_root_heading.inv() * Rotation.from_quat(motion["qpos"][i,frame_id][[1,2,3,0]])).as_quat()
pb.resetBasePositionAndOrientation(robot, rel_root_pos, rel_root_orn)
#pb.resetBasePositionAndOrientation(frame, rel_frame_pos, rel_frame_orn)
time.sleep(1.0 / fps)
#breakpoint()
input("Press Enter to replay the motion...")