Controllers Module¶
Ready-made control callbacks for Simulation.
Every controller has the signature f(model, data, **kwargs). Keyword
arguments given to Simulation beyond its own
parameters are forwarded to the controller on every step:
>>> import mujoco_toolbox as mjtb
>>> mjtb.Simulation("robot.xml", controller=mjtb.sin, amplitude=0.5, frequency=2).run()
Unless joint or axis is given, signals drive every actuator’s ctrl.
Unknown keyword arguments are ignored.
- mujoco_toolbox.controllers.step(model, data, *, amplitude=1, joint=None, axis=None, delay=0, **_)[source]¶
Apply a constant step signal.
- Parameters:
- mujoco_toolbox.controllers.sin(model, data, *, amplitude=1, frequency=1, phase=0, joint=None, delay=0, **_)[source]¶
Drive a sine wave of the given amplitude, frequency and phase.
- Parameters:
model (MjModel) – The
MjModel.data (MjData) – The
MjDatato drive.amplitude (float) – Peak value.
frequency (float) – Frequency in Hz.
phase (float) – Phase shift in radians.
joint (Iterable[int] | None) – Actuator indices to drive. Defaults to all.
delay (float) – Seconds to wait before starting.
- mujoco_toolbox.controllers.cos(model, data, *, amplitude=1, frequency=1, phase=0, joint=None, delay=0, **_)[source]¶
Drive a cosine wave of the given amplitude, frequency and phase.
- Parameters:
model (MjModel) – The
MjModel.data (MjData) – The
MjDatato drive.amplitude (float) – Peak value.
frequency (float) – Frequency in Hz.
phase (float) – Phase shift in radians.
joint (Iterable[int] | None) – Actuator indices to drive. Defaults to all.
delay (float) – Seconds to wait before starting.
- mujoco_toolbox.controllers.random(model, data, *, amplitude=1, joint=None, axis=None, delay=0, **_)[source]¶
Apply uniform random noise in
[0, amplitude)each step.- Parameters:
model (MjModel) – The
MjModel.data (MjData) – The
MjDatato drive.amplitude (float) – Upper bound of the noise.
joint (Iterable[int] | None) – Actuator indices to drive. Defaults to all.
axis (int | None) –
qposindex to set directly, instead of actuators.delay (float) – Seconds to wait before starting.
- mujoco_toolbox.controllers.real_time(_model, data, *args, **_)[source]¶
Copy values onto
dataon demand, for driving a digital twin.Call it yourself with a dict of
MjDatafields, e.g.sim.controller(sim.model, sim.data, {"qpos": q}). Unknown fields are skipped with aSimulationWarning. Called without values, as the per-step callback is, it does nothing.