-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer_sapien.py
56 lines (42 loc) · 1.46 KB
/
viewer_sapien.py
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
50
51
52
53
54
55
56
import sapien
def demo(fix_root_link, balance_passive_force):
scene = sapien.Scene()
scene.add_ground(0)
scene.set_ambient_light([0.5, 0.5, 0.5])
scene.add_directional_light([0, 1, -1], [0.5, 0.5, 0.5])
viewer = scene.create_viewer()
viewer.set_camera_xyz(x=-2, y=0, z=1)
viewer.set_camera_rpy(r=0, p=-0.3, y=0)
# Load URDF
loader = scene.create_urdf_loader()
loader.fix_root_link = fix_root_link
robot = loader.load("g1.urdf")
robot.set_root_pose(sapien.Pose([0, 0, 0.755], [1, 0, 0, 0]))
# Set initial joint positions
robot.set_qpos([0] * 37)
for joint in robot.get_joints():
if joint.type != "fixed":
print(joint.get_name())
while not viewer.closed:
for _ in range(4): # render every 4 steps
if balance_passive_force:
qf = robot.compute_passive_force(
gravity=True,
coriolis_and_centrifugal=True,
)
robot.set_qf(qf)
scene.step()
scene.update_render()
viewer.render()
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--fix-root-link", action="store_true")
parser.add_argument("--balance-passive-force", action="store_true")
args = parser.parse_args()
demo(
fix_root_link=args.fix_root_link,
balance_passive_force=args.balance_passive_force,
)
if __name__ == "__main__":
main()