-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy patharm_ur5e.py
86 lines (68 loc) · 2.56 KB
/
arm_ur5e.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
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
from pathlib import Path
import mujoco
import mujoco.viewer
import numpy as np
from loop_rate_limiters import RateLimiter
import mink
_HERE = Path(__file__).parent
_XML = _HERE / "universal_robots_ur5e" / "scene.xml"
if __name__ == "__main__":
model = mujoco.MjModel.from_xml_path(_XML.as_posix())
configuration = mink.Configuration(model)
tasks = [
end_effector_task := mink.FrameTask(
frame_name="attachment_site",
frame_type="site",
position_cost=1.0,
orientation_cost=1.0,
lm_damping=1.0,
),
]
# Enable collision avoidance between the following geoms:
collision_pairs = [
(["wrist_3_link"], ["floor", "wall"]),
]
limits = [
mink.ConfigurationLimit(model=model),
mink.CollisionAvoidanceLimit(model=model, geom_pairs=collision_pairs),
]
max_velocities = {
"shoulder_pan": np.pi,
"shoulder_lift": np.pi,
"elbow": np.pi,
"wrist_1": np.pi,
"wrist_2": np.pi,
"wrist_3": np.pi,
}
velocity_limit = mink.VelocityLimit(model, max_velocities)
limits.append(velocity_limit)
mid = model.body("target").mocapid[0]
model = configuration.model
data = configuration.data
solver = "quadprog"
with mujoco.viewer.launch_passive(
model=model, data=data, show_left_ui=False, show_right_ui=False
) as viewer:
mujoco.mjv_defaultFreeCamera(model, viewer.cam)
# Initialize to the home keyframe.
configuration.update_from_keyframe("home")
# Initialize the mocap target at the end-effector site.
mink.move_mocap_to_frame(model, data, "target", "attachment_site", "site")
rate = RateLimiter(frequency=500.0, warn=False)
while viewer.is_running():
# Update task target.
T_wt = mink.SE3.from_mocap_name(model, data, "target")
end_effector_task.set_target(T_wt)
# Compute velocity and integrate into the next configuration.
vel = mink.solve_ik(
configuration, tasks, rate.dt, solver, 1e-3, limits=limits
)
configuration.integrate_inplace(vel, rate.dt)
mujoco.mj_camlight(model, data)
# Note the below are optional: they are used to visualize the output of the
# fromto sensor which is used by the collision avoidance constraint.
mujoco.mj_fwdPosition(model, data)
mujoco.mj_sensorPos(model, data)
# Visualize at fixed FPS.
viewer.sync()
rate.sleep()