-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathfranka_grasp_rigid_cube.py
More file actions
91 lines (74 loc) · 2.58 KB
/
Copy pathfranka_grasp_rigid_cube.py
File metadata and controls
91 lines (74 loc) · 2.58 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import argparse
import sys
import numpy as np
import genesis as gs
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--cpu", action="store_true", default=(sys.platform == "darwin"))
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
########################## init ##########################
gs.init(backend=gs.cpu if args.cpu else gs.gpu, precision="64")
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=1.0 / 60,
substeps=2,
),
rigid_options=gs.options.RigidOptions(
enable_self_collision=False,
),
coupler_options=gs.options.SAPCouplerOptions(
pcg_threshold=1e-10,
sap_convergence_atol=1e-10,
sap_convergence_rtol=1e-10,
linesearch_ftol=1e-10,
),
viewer_options=gs.options.ViewerOptions(
camera_pos=(1.3, 0.0, 0.1),
camera_lookat=(0.65, 0.0, 0.1),
),
show_viewer=args.vis,
)
########################## entities ##########################
franka = scene.add_entity(
gs.morphs.MJCF(file="xml/franka_emika_panda/panda.xml"),
material=gs.materials.Rigid(
coup_friction=1.0,
friction=1.0,
),
)
cube = scene.add_entity(
morph=gs.morphs.Box(
size=(0.04, 0.04, 0.04),
pos=(0.65, 0.0, 0.02),
),
material=gs.materials.Rigid(
coup_friction=1.0,
friction=1.0,
),
)
########################## build ##########################
scene.build()
motors_dof = np.arange(7)
fingers_dof = np.arange(7, 9)
end_effector = franka.get_link("hand")
########################## simulate ##########################
# init
franka.set_qpos((-1.0124, 1.5559, 1.3662, -1.6878, -1.5799, 1.7757, 1.4602, 0.04, 0.04))
# hold
qpos = franka.inverse_kinematics(link=end_effector, pos=(0.65, 0.0, 0.13), quat=(0, 1, 0, 0))
franka.control_dofs_position(qpos[motors_dof], motors_dof)
for i in range(15):
scene.step()
# grasp
for i in range(10):
franka.control_dofs_force(np.array([-1.0, -1.0]), fingers_dof)
scene.step()
# lift
qpos = franka.inverse_kinematics(link=end_effector, pos=(0.65, 0.0, 0.3), quat=(0, 1, 0, 0))
franka.control_dofs_position(qpos[motors_dof], motors_dof)
for i in range(40):
franka.control_dofs_force(np.array([-1.0, -1.0]), fingers_dof)
scene.step()
if __name__ == "__main__":
main()