scenarioHingedRigidBodyMuJoCo

Review these prerequisite examples first:

  1. scenarioHingedRigidBody for the classic hinged-panel model.

  2. scenarioReactionWheel for MuJoCo bodies, joints, and actuators.

This script demonstrates how to run the classic Basilisk scenarioHingedRigidBody example using MuJoCo dynamics via MJScene instead of the traditional hub-centric Basilisk C++ Module: spacecraft dynamics.

Running the Example

Use a Basilisk installation with MuJoCo support and the example dependencies described in Install. When building from source, enable --mujoco True. With that Python environment active, run from the repository root:

python examples/mujoco/scenarioHingedRigidBodyMuJoCo.py

The script displays the result plots. When importing the scenario from examples/mujoco, call run(showPlots=False) to run without displaying windows; it still returns a dictionary of Matplotlib figures for inspection or saving.

Model and Force Setup

The multi-body system is created programmatically as a MuJoCo XML string. It consists of a free-floating spacecraft bus (“hub”) with two solar panel rigid bodies (“panel1”, “panel2”) attached via hinge joints (“hinge1”, “hinge2”), giving the system 8 total degrees of freedom (3 translational, 3 rotational, and 2 panel hinge DOFs).

Two existing library modules and a scenario-specific burn command are added to the MuJoCo dynamics task:

  1. MJJointPIDController computes a torsional spring-damper restoring torque for a hinge joint from its angle and angular rate, and writes the result as a SingleActuatorMsg command. One instance is attached to each panel hinge to emulate panel stiffness and damping.

  2. BurnWindowForceCommand, defined in this script, publishes a fixed force in inertial frame N during the inclusive interval [burnStart, burnEnd] and zero force outside it.

  3. MJCmdForceInertialToForceAtSite converts that command from inertial frame N into the thruster site frame S using the site’s current attitude. The site is fixed to the hub and aligned with body frame B in this example. The converter handles the rotation; the burn-command module determines when thrust is requested.

The force message chain is BurnWindowForceCommand -> MJCmdForceInertialToForceAtSite -> the MuJoCo force actuator at thrustSite. This keeps the requested force direction fixed in inertial space even as the spacecraft rotates.

Earth gravity is configured using NBodyGravity with a pointMassGravityModel as the central body. Gravity targets are registered manually for the hub and both panel bodies.

The spacecraft is placed on a near-circular low Earth orbit (LEO). The simulation runs for a coast phase lasting 1% of an orbit followed by a 935-second translational burn, during which the panels respond dynamically to the resulting body motion through their spring-damper hinges.

Inertial position, orbital radius, and the two panel hinge angular displacements are plotted at the end.

Illustration of Simulation Results

../../_images/scenarioHingedRigidBodyMuJoCo_inertPos.svg ../../_images/scenarioHingedRigidBodyMuJoCo_orbitalMotion.svg ../../_images/scenarioHingedRigidBodyMuJoCo_angDisp.svg
class scenarioHingedRigidBodyMuJoCo.BurnWindowForceCommand(*args, **kwargs)[source]

Bases: SysModel

Publish an inertial force during a burn window and zero outside it.

Parameters:
  • force_N – Three-component force expressed in inertial frame N [N].

  • burnStartNanos – Inclusive burn start time measured from simulation start [ns].

  • burnEndNanos – Inclusive burn end time measured from simulation start [ns].

Variables:

cmdForceOutMsg – Commanded inertial force consumed by MJCmdForceInertialToForceAtSite before reaching the actuator.

scenarioHingedRigidBodyMuJoCo.makeMjXmlString(hubMass: float = 800.0, busIDiag: Tuple[float, float, float] = (900.0, 800.0, 600.0))[source]

Build MuJoCo XML for a spacecraft hub with two hinged panels.

Parameters:
  • hubMass – Hub mass [kg]. Defaults to 800.0 kg.

  • busIDiag – Principal moments of inertia about the hub center of mass, ordered along the hub x, y, and z axes [kg m^2]. Defaults to (900.0, 800.0, 600.0) kg m^2.

Returns:

XML defining the hub, panel bodies, hinge joints, and thrust site.

Return type:

str

scenarioHingedRigidBodyMuJoCo.plotAngDisp(timeAxis: ndarray, panel1thetaLog: ndarray, panel2thetaLog: ndarray) → Figure[source]

Plots angular displacements of panels

scenarioHingedRigidBodyMuJoCo.plotInertialPos(timeAxis: ndarray, posData: ndarray) → Figure[source]

Plot the inertial position vector components.

scenarioHingedRigidBodyMuJoCo.plotOrbitalMotion(timeAxis: ndarray, posData: ndarray, velData: ndarray, mu: float) → Figure[source]

Plots orbital motion of spacecraft

scenarioHingedRigidBodyMuJoCo.run(showPlots: bool = False)[source]

Run a short orbital coast followed by a 935-second burn.

Parameters:

showPlots – Display the Matplotlib figures and wait for the plot windows to close when True. Defaults to False; figures are still generated and returned in either case.

Returns:

Dictionary mapping scenario-prefixed names to three Matplotlib figures: inertial position, orbital radius, and panel hinge angles. No files are saved by this function.

Return type:

dict