-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathbatched_IK.py
More file actions
54 lines (46 loc) · 1.59 KB
/
Copy pathbatched_IK.py
File metadata and controls
54 lines (46 loc) · 1.59 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
50
51
52
53
54
import os
import numpy as np
import genesis as gs
########################## init ##########################
gs.init()
########################## create a scene ##########################
scene = gs.Scene(
viewer_options=gs.options.ViewerOptions(
camera_pos=(0.0, -2, 1.5),
camera_lookat=(0.0, 0.0, 0.5),
camera_fov=40,
),
rigid_options=gs.options.RigidOptions(
enable_joint_limit=False,
),
)
########################## entities ##########################
plane = scene.add_entity(
gs.morphs.Plane(),
)
robot = scene.add_entity(
gs.morphs.MJCF(file="xml/franka_emika_panda/panda.xml"),
)
########################## build ##########################
n_envs = 16
scene.build(n_envs=n_envs, env_spacing=(1.0, 1.0))
target_quat = np.tile(np.array([0, 1, 0, 0]), [n_envs, 1]) # pointing downwards
center = np.tile(np.array([0.4, -0.2, 0.25]), [n_envs, 1])
angular_speed = np.random.uniform(-10, 10, n_envs)
r = 0.1
ee_link = robot.get_link("hand")
horizon = 1000 if "PYTEST_VERSION" not in os.environ else 5
for i in range(horizon):
target_pos = np.zeros([n_envs, 3])
target_pos[:, 0] = center[:, 0] + np.cos(i / 360 * np.pi * angular_speed) * r
target_pos[:, 1] = center[:, 1] + np.sin(i / 360 * np.pi * angular_speed) * r
target_pos[:, 2] = center[:, 2]
target_q = np.hstack([target_pos, target_quat])
q = robot.inverse_kinematics(
link=ee_link,
pos=target_pos,
quat=target_quat,
rot_mask=[False, False, True], # for demo purpose: only restrict direction of z-axis
)
robot.set_qpos(q)
scene.step()