mjcf
Helpers for building MuJoCo models with the native mujoco.MjSpec API.
FlyGym composes its models with mujoco.MjSpec (MuJoCo's native model-editing
API) rather than dm_control.mjcf (PyMJCF). MjSpec's element constructors take
typed enum values where PyMJCF accepted strings, and it has no high-level actuator
"shortcut" classes (position/velocity/...). This module provides the thin
translation layer FlyGym needs: string-to-enum lookups and an add_actuator
helper that reproduces MuJoCo's actuator shortcuts.
add_actuator(spec, kind, *, name, joint=None, body=None, tendon=None, site=None, forcelimited=None, forcerange=None, ctrllimited=None, ctrlrange=None, gear=None, kp=None, kv=None, gain=None, **kwargs)
¶
Add an actuator to spec, reproducing MuJoCo's actuator shortcuts.
MjSpec only exposes the low-level "general" actuator (gain/bias/dyn/trn). This
helper expands the familiar motor/position/velocity/adhesion/
general shortcuts into the equivalent low-level parameters, matching what
the XML compiler (and PyMJCF) produced. The expansions were verified against
dm_control.mjcf compiled output.
Exactly one transmission target (joint, body, tendon or site)
must be given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
MjSpec
|
The spec to add the actuator to. |
required |
kind
|
str
|
Actuator shortcut name (e.g. |
required |
name
|
str
|
Actuator name. |
required |
joint
|
str | None
|
Transmission target joint name (give exactly one of
|
None
|
body
|
str | None
|
Transmission target body name. |
None
|
tendon
|
str | None
|
Transmission target tendon name. |
None
|
site
|
str | None
|
Transmission target site name. |
None
|
forcelimited
|
bool | None
|
Whether actuator force is clamped to |
None
|
forcerange
|
tuple[float, float] | None
|
Min/max actuator force. |
None
|
ctrllimited
|
bool | None
|
Whether the control input is clamped to |
None
|
ctrlrange
|
tuple[float, float] | None
|
Min/max control input. |
None
|
gear
|
float | None
|
Transmission gear ratio ( |
None
|
kp
|
float | None
|
Position/intvelocity gain. |
None
|
kv
|
float | None
|
Position/velocity/intvelocity damping. |
None
|
gain
|
float | None
|
Gain ( |
None
|
**kwargs
|
Any
|
Extra low-level attributes set directly on the actuator (e.g.
|
{}
|
Returns:
| Type | Description |
|---|---|
MjsActuator
|
The created |
Source code in src/flygym/utils/mjcf.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
add_material(spec, *, texture=None, **params)
¶
Add a material, optionally linking a texture by name in the RGB texture role
(PyMJCF exposed this as a single material.texture attribute).
Source code in src/flygym/utils/mjcf.py
add_texture(spec, **params)
¶
Add a texture, converting the type/builtin/mark string attributes
(which PyMJCF accepted as strings) to MjSpec enums.
Source code in src/flygym/utils/mjcf.py
set_mujoco_globals(spec, mujoco_globals_path)
¶
Load a YAML file of global MuJoCo settings and apply them to a spec.
Handles the compiler/option/statistic/visual groups, including the cases that
differ from a flat attribute set: compiler.angle maps to compiler.degree,
option.flag maps to the enable/disable bitmasks, option.integrator and
option.solver are string-named enums, statistic maps to spec.stat,
and visual.global maps to spec.visual.global_ (global is reserved).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
MjSpec
|
The spec to update. |
required |
mujoco_globals_path
|
PathLike
|
Path to the YAML file of global parameter overrides. |
required |