Mujoco KDL Wrapper  0.5.1
MuJoCo + KDL bridge for robot kinematics and dynamics
Loading...
Searching...
No Matches
_mj_kdl_wrapper.pyi
Go to the documentation of this file.
1from __future__ import annotations
2
3from typing import Any, Callable, ClassVar, Optional, Sequence, Union
4
5import mujoco
6import numpy as np
7import numpy.typing as npt
8import PyKDL as kdl
9
10_JointValues = Union[Sequence[float], npt.NDArray[np.float64]]
11
12
13class _Enum:
14 """A pybind11 enum: members are class attributes, not an enum.Enum."""
15 __members__: ClassVar[dict[str, Any]]
16 def __init__(self, value: int) -> None: ...
17 def __int__(self) -> int: ...
18 def __index__(self) -> int: ...
19 @property
20 def name(self) -> str: ...
21 @property
22 def value(self) -> int: ...
23
24
26 """Log threshold: messages at or above it print; NONE prints nothing."""
27 INFO: ClassVar[LogLevel]
28 WARN: ClassVar[LogLevel]
29 ERROR: ClassVar[LogLevel]
30 NONE: ClassVar[LogLevel]
31
32
34 World: ClassVar[AttachKind]
35 Body: ClassVar[AttachKind]
36 Site: ClassVar[AttachKind]
37 Frame: ClassVar[AttachKind]
38
39
40class Shape(_Enum):
41 Unspecified: ClassVar[Shape]
42 BOX: ClassVar[Shape]
43 SPHERE: ClassVar[Shape]
44 CYLINDER: ClassVar[Shape]
45
46
48 Tangential: ClassVar[Condim]
49 Torsional: ClassVar[Condim]
50 Rolling: ClassVar[Condim]
51
52
54 POSITION: ClassVar[CtrlMode]
55 TORQUE: ClassVar[CtrlMode]
56 VELOCITY: ClassVar[CtrlMode]
57
58
60 R360p: ClassVar[VideoResolution]
61 R480p: ClassVar[VideoResolution]
62 R720p: ClassVar[VideoResolution]
63 R1080p: ClassVar[VideoResolution]
64 R2K: ClassVar[VideoResolution]
65 R4K: ClassVar[VideoResolution]
66
67
69 """A control mode build_scene adds to a robot, on its own actuator group."""
70 mode: CtrlMode
71 joints: list[str]
72 kv: float
74 self, mode: CtrlMode = CtrlMode.TORQUE, joints: Sequence[str] = (), kv: float = 0.0
75 ) -> None: ...
76
77
79 """Placement target in an accumulated scene spec."""
80 kind: AttachKind
81 name: str
82 def __init__(self, kind: AttachKind = AttachKind.World, name: str = "") -> None: ...
83
84
86 """MJCF attachment applied to a robot root or prior attachment."""
87 mjcf_path: str
88 attach_to: AttachTarget
89 prefix: str
90 pos: list[float]
91 quat: list[float]
92 modes: list[CtrlModeSpec]
93 """Control modes for its own joints; [] = native only."""
94 contact_exclusions: list[tuple[str, str]]
95 def __init__(self) -> None: ...
96
97
99 """Robot root MJCF plus placement and ordered attachment specs."""
100 path: str
101 prefix: str
102 attach_to: AttachTarget
103 pos: list[float]
104 quat: list[float]
105 attachments: list[AttachmentSpec]
106 modes: list[CtrlModeSpec]
107 """Extra control modes; default [TORQUE], [] = native only."""
108 def __init__(self) -> None: ...
109
110
112 """MJCF asset or primitive object. A primitive needs size, rgba and friction, and mass
113 unless fixed; rgba on an asset recolors its geoms."""
114 name: str
115 mjcf_path: str
116 prefix: str
117 attach_to: AttachTarget
118 shape: Shape
119 size: Optional[list[float]]
120 pos: list[float]
121 quat: list[float]
122 rgba: Optional[list[float]]
123 fixed: bool
124 mass: Optional[float]
125 condim: Condim
126 friction: Optional[list[float]]
127 def __init__(self) -> None: ...
128
129
131 """A frame marked on a body of the assembled scene."""
132 body: str
133 name: str
134 pos: list[float]
135 quat: list[float]
136 def __init__(self) -> None: ...
137
138
140 """Named camera on a body, or in the world when body is empty. pos and fovy are required."""
141 name: str
142 body: str
143 pos: Optional[list[float]]
144 quat: list[float]
145 fovy: Optional[float]
146 def __init__(self) -> None: ...
147
148
150 """Full scene description. timestep, add_floor, and add_skybox are required."""
151 robots: list[RobotSpec]
152 timestep: Optional[float]
153 gravity_z: float
154 add_floor: Optional[bool]
155 floor_z: float
156 add_skybox: Optional[bool]
157 objects: list[SceneObject]
158 sites: list[SiteSpec]
159 cameras: list[CameraSpec]
160 def __init__(self) -> None: ...
161
162
164 """Logical FT sensor backed by MuJoCo force and torque sensors."""
165 name: str
166 force_sensor: str
167 torque_sensor: str
168 frame_site: str
169 def __init__(self) -> None: ...
170
171
173 """Optional tool mass/TCP description for building the robot KDL chain."""
174 tool_body: str
175 tcp_site: str
176 ft_sensors: list[ForceTorqueSensorSpec]
177 def __init__(self) -> None: ...
178
179
181 keyframe: int
182 use_keyframe: bool
183 def __init__(self) -> None: ...
184
185
187 @property
188 def used_keyframe(self) -> bool: ...
189 @property
190 def keyframe(self) -> int: ...
191
192
194 """A copy of the reset's options and result, passed to Env.on_reset."""
195 @property
196 def options(self) -> ResetOptions: ...
197 @property
198 def info(self) -> ResetInfo: ...
199
200
201class Robot:
202 """Robot registered with an Env (Env.create_robot) and backed by a wrapper-built KDL chain.
203 Env.update() reads and commands it; Env.close() closes it."""
204 ctrl_mode: CtrlMode
205 paused: bool
206 @property
207 def n_joints(self) -> int: ...
208 @property
209 def joint_names(self) -> list[str]: ...
210 @property
211 def joint_limits(self) -> list[tuple[float, float]]: ...
212 # Ports read as read-only copies; assign the whole port to write it.
213 @property
214 def jnt_pos_msr(self) -> npt.NDArray[np.float64]: ...
215 @jnt_pos_msr.setter
216 def jnt_pos_msr(self, values: _JointValues) -> None: ...
217 @property
218 def jnt_vel_msr(self) -> npt.NDArray[np.float64]: ...
219 @jnt_vel_msr.setter
220 def jnt_vel_msr(self, values: _JointValues) -> None: ...
221 @property
222 def jnt_trq_msr(self) -> npt.NDArray[np.float64]: ...
223 @jnt_trq_msr.setter
224 def jnt_trq_msr(self, values: _JointValues) -> None: ...
225 @property
226 def jnt_pos_cmd(self) -> npt.NDArray[np.float64]: ...
227 @jnt_pos_cmd.setter
228 def jnt_pos_cmd(self, values: _JointValues) -> None: ...
229 @property
230 def jnt_vel_cmd(self) -> npt.NDArray[np.float64]: ...
231 @jnt_vel_cmd.setter
232 def jnt_vel_cmd(self, values: _JointValues) -> None: ...
233 @property
234 def jnt_trq_cmd(self) -> npt.NDArray[np.float64]: ...
235 @jnt_trq_cmd.setter
236 def jnt_trq_cmd(self, values: _JointValues) -> None: ...
237 @property
238 def jnt_saturated(self) -> npt.NDArray[np.bool_]: ...
239 def set_control_mode(self, mode: CtrlMode) -> None:
240 """Switch mode without a jump: seeds the new mode's commands from the current state."""
241 def set_joint_pos(self, q: Union[_JointValues, kdl.JntArray]) -> None:
242 """Write MuJoCo joint positions; frames read afterwards follow them."""
243 def kdl_chain(self) -> kdl.Chain:
244 """The robot's own chain as a PyKDL.Chain, valid while the robot lives."""
245 @property
246 def ft_sensor_names(self) -> list[str]: ...
247 def ft_sensor(self, name: str) -> kdl.Wrench:
248 """Return the latest measured force-torque sensor value as a PyKDL.Wrench."""
249 @property
250 def has_tcp_frame(self) -> bool: ...
251 @property
252 def tcp_site(self) -> str: ...
253 @property
254 def tip_T_tcp(self) -> kdl.Frame: ...
255 def joint_force_limits(self, fallback: float = 1e6) -> npt.NDArray[np.float64]:
256 """Per-joint force/torque limit of the active mode's actuators; fallback where
257 unlimited."""
258
259
260class Viewer:
261 """The simulate UI of an Env, opened by Env.open_viewer(); inert while closed."""
262 realtime_factor: float
263 def is_running(self) -> bool: ...
264 def key_pressed(self, key: int) -> bool:
265 """True while the GLFW key code is held; False headless."""
266 def capture_key(self, key: int, capture: bool = True) -> None:
267 """Claim a GLFW key so the UI does not act on it; capture=False gives it back."""
268 def clear_trace(self) -> None: ...
270 self,
271 a: Sequence[float],
272 b: Sequence[float],
273 rgba: Optional[Sequence[float]] = None,
274 ) -> None: ...
275 def use_camera(self, name: str = "") -> bool: ...
277 self,
278 distance: float,
279 azimuth: float,
280 elevation: float,
281 lookat: Sequence[float] = (0.0, 0.0, 0.0),
282 ) -> None: ...
283
284
286 """Offscreen MuJoCo video recorder for an Env."""
287 @staticmethod
288 def open(
289 env: Env,
290 out_path: str,
291 width: int = 1280,
292 height: int = 720,
293 fps: int = 60,
294 ) -> VideoRecorder: ...
295 @staticmethod
297 env: Env,
298 out_path: str,
299 resolution: VideoResolution = VideoResolution.R720p,
300 fps: int = 60,
301 ) -> VideoRecorder: ...
302 @staticmethod
303 def open_offscreen(env: Env, width: int, height: int) -> VideoRecorder:
304 """Open an offscreen renderer (no video file) for render_rgb()."""
305 def render_rgb(self) -> npt.NDArray[np.uint8]:
306 """The Env's current state as a (height, width, 3) array, top row first."""
307 def __enter__(self) -> VideoRecorder: ...
308 def __exit__(self, *args: object) -> None: ...
309 def record_frame(self) -> bool: ...
310 def use_camera(self, name: str = "") -> bool: ...
312 self,
313 distance: float,
314 azimuth: float,
315 elevation: float,
316 lookat: Sequence[float] = (0.0, 0.0, 0.0),
317 ) -> None: ...
318 def close(self) -> None: ...
319
320
321class Env:
322 """The simulation: compiled scene, its robots and viewer. The loop is step(), then
323 update() (read every robot, apply its commands), then pace()."""
324 on_reset: Optional[Callable[[ResetContext], None]]
325 """Called by reset() after every robot is re-seeded; its exception comes out of reset() or
326 step()."""
327 @property
328 def spec(self) -> SceneSpec:
329 """A copy of the SceneSpec the Env runs, with objects added or removed since build()."""
330 @property
331 def model(self) -> mujoco.MjModel:
332 """The live mujoco.MjModel; a new object after add_object()/remove_object()."""
333 @property
334 def data(self) -> mujoco.MjData:
335 """The live mujoco.MjData; a new object after add_object()/remove_object(). The viewer
336 thread reads it too: call mujoco functions on it only while the viewer is closed or
337 paused."""
338 @staticmethod
339 def build(spec: SceneSpec) -> Env: ...
340 def close(self) -> None:
341 """Close the viewer and free the model; robots become closed."""
342 def __enter__(self) -> Env: ...
343 def __exit__(self, *args: object) -> None: ...
345 self,
346 base_body: str,
347 tip_body: str,
348 prefix: str = "",
349 tool: Optional[ToolFrameSpec] = None,
350 ) -> Robot: ...
352 self,
353 chain: kdl.Chain,
354 joint_names: Sequence[str],
355 prefix: str = "",
356 tool: Optional[ToolFrameSpec] = None,
357 ) -> Robot:
358 """Register a robot driven by chain; joint_names are the MuJoCo joints in chain order."""
359 def step(self) -> bool:
360 """Advance one timestep; False once the viewer window is closed."""
361 def update(self) -> None:
362 """Read every robot, then apply its commands."""
363 def pace(self) -> None:
364 """Sleep out this step's share of wall time; no-op headless. step() never sleeps."""
365 def open_viewer(self, title: str = "MuJoCo") -> None:
366 """Open the simulate UI; step() drives it, close() closes it."""
367 @property
368 def viewer(self) -> Viewer: ...
369 def reset(self, options: Optional[ResetOptions] = None) -> ResetInfo:
370 """Reset MuJoCo state, re-seed every robot, then call on_reset; what it moves is read
371 back."""
372 def add_object(self, object: SceneObject) -> None:
373 """Rebuild with an added object; robots and the viewer follow the new model."""
374 def set_control_mode(self, robot: int, mode: CtrlMode) -> None:
375 """Switch robot (its SceneSpec.robots index) to mode, for robots driven without a
376 Robot."""
377 def remove_object(self, name: str) -> None:
378 """Rebuild without the named object; robots and the viewer follow the new model."""
379 def body_frame(self, name: str) -> kdl.Frame: ...
380 def site_frame(self, name: str) -> kdl.Frame: ...
382 self,
383 name: str,
384 pos: Sequence[float],
385 quat: Optional[Sequence[float]] = None,
386 ) -> None:
387 """Set a free body pose. quat is xyzw when provided."""
388 def save_model_xml(self, path: str) -> None: ...
389
390
391__version__: str
392__mujoco_version__: str
393
394def set_log_level(level: LogLevel) -> None:
395 """Print wrapper messages at level and above; NONE prints nothing."""
396def get_log_level() -> LogLevel: ...
None __init__(self, AttachKind kind=AttachKind.World, str name="")
None __init__(self, CtrlMode mode=CtrlMode.TORQUE, Sequence[str] joints=(), float kv=0.0)
kdl.Frame site_frame(self, str name)
None open_viewer(self, str title="MuJoCo")
None set_control_mode(self, int robot, CtrlMode mode)
kdl.Frame body_frame(self, str name)
ResetInfo reset(self, Optional[ResetOptions] options=None)
Robot create_robot_from_chain(self, kdl.Chain chain, Sequence[str] joint_names, str prefix="", Optional[ToolFrameSpec] tool=None)
None add_object(self, SceneObject object)
Robot create_robot(self, str base_body, str tip_body, str prefix="", Optional[ToolFrameSpec] tool=None)
None __exit__(self, *object args)
None set_body_pose(self, str name, Sequence[float] pos, Optional[Sequence[float]] quat=None)
npt.NDArray[np.float64] jnt_pos_cmd(self)
list[tuple[float, float]] joint_limits(self)
npt.NDArray[np.float64] jnt_vel_msr(self)
npt.NDArray[np.float64] jnt_trq_cmd(self)
npt.NDArray[np.float64] jnt_vel_cmd(self)
None set_control_mode(self, CtrlMode mode)
npt.NDArray[np.float64] jnt_trq_msr(self)
npt.NDArray[np.bool_] jnt_saturated(self)
npt.NDArray[np.float64] jnt_pos_msr(self)
kdl.Wrench ft_sensor(self, str name)
npt.NDArray[np.float64] joint_force_limits(self, float fallback=1e6)
None set_joint_pos(self, Union[_JointValues, kdl.JntArray] q)
None set_free_camera(self, float distance, float azimuth, float elevation, Sequence[float] lookat=(0.0, 0.0, 0.0))
VideoRecorder open_preset(Env env, str out_path, VideoResolution resolution=VideoResolution.R720p, int fps=60)
VideoRecorder open(Env env, str out_path, int width=1280, int height=720, int fps=60)
VideoRecorder open_offscreen(Env env, int width, int height)
None add_trace_segment(self, Sequence[float] a, Sequence[float] b, Optional[Sequence[float]] rgba=None)
None set_free_camera(self, float distance, float azimuth, float elevation, Sequence[float] lookat=(0.0, 0.0, 0.0))
None capture_key(self, int key, bool capture=True)
None set_log_level(LogLevel level)