scenarioFlexiblePanelMuJoCo
Review these prerequisite examples first:
scenarioFlexiblePanel for the classic flexible-panel model.
scenarioHingedRigidBodyMuJoCo for MuJoCo hinge and force setup.
scenarioAttitudeFeedbackRWMuJoCo for attitude control with MuJoCo.
This script demonstrates how to model a flexible, multi-segment solar panel using MuJoCo dynamics via MJScene instead of the traditional hub-centric Basilisk C++ Module: spacecraft dynamics. This scenario is a translation of the classic Basilisk scenarioFlexiblePanel example.
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/scenarioFlexiblePanelMuJoCo.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 Control Setup
The multi-body system is created programmatically as a MuJoCo XML string.
It consists of a free-floating spacecraft bus (“hub”) with a single flexible
panel discretized into numberOfSegments rigid sub-panel bodies
(“subPanel1”, “subPanel2”, …), connected end-to-end. Each sub-panel is
connected to its neighbor by two colocated hinge joints: a “bend” joint
(bending degree of freedom, or DOF) and a “twist” joint (torsional DOF). The
panel’s continuous flexibility is approximated by a discretized series of
rigid links. As such, this system has 6 + 2 * numberOfSegments DOFs
(3 translational, 3 rotational, 2 DOFs per panel segment).
A torsional spring-damper torque is applied at every bend and twist joint to emulate the panel’s structural stiffness and damping:
MJJointPIDController computes a restoring torque from a joint’s angle and angular rate about a reference equilibrium angle, and writes the result as a
SingleActuatorMsgcommand. One instance is attached to each bend and twist joint, using separate bending and torsional stiffness/damping coefficients.
A standard Basilisk flight software (FSW) stack is used to point the hub at a fixed inertial attitude while the flexible panel dynamically responds to the resulting motion:
C++ Module: simpleNav provides the spacecraft’s navigation attitude solution.
C Module: inertial3D generates a fixed inertial attitude reference.
C Module: attTrackingError computes the attitude and rate tracking errors.
C Module: mrpFeedback computes the commanded body torque, using an inertia tensor for the hub plus panel computed via the parallel axis theorem.
A small adapter module bridges the FSW torque command to the MuJoCo torque actuator:
Python Module: cmdTorqueBodyToTorqueAtSite relays the commanded body-frame torque as a
TorqueAtSiteMsg(site and body frames are aligned, so the default identitydcm_SBis used), consumed by a torque actuator at the hub site.
Earth gravity is configured using NBodyGravity with a pointMassGravityModel as the central body. Gravity targets are registered manually for the hub and every sub-panel body.
The spacecraft is placed on an elliptical orbit with the panel initially undeformed and stationary relative to the hub (all bend/twist angles and rates initialized to zero) while the attitude controller maneuvers the hub to the commanded reference orientation. The simulation runs for 10 minutes.
Bending angles, torsional angles, and their rates are plotted for every sub-panel segment, along with the attitude error and attitude error rate from the FSW control loop.
Illustration of Simulation Results
- class scenarioFlexiblePanelMuJoCo.geometryClass(numberOfSegments)[source]
Bases:
objectStore hub and panel dimensions and derive equal-sized panel segments.
- Parameters:
numberOfSegments – Positive number of rigid segments used to approximate the flexible panel. The total panel length and mass are divided equally among these segments.
- scenarioFlexiblePanelMuJoCo.makeMjXmlString(scGeometry: geometryClass)[source]
Build MuJoCo XML for a spacecraft hub with a flexible panel.
- Parameters:
scGeometry – Hub and panel geometry, including dimensions [m], masses [kg], and the number of panel segments.
- Returns:
Complete MuJoCo model XML containing the hub and panel chain.
- Return type:
str
- scenarioFlexiblePanelMuJoCo.panelChainGen(scGeometry: geometryClass, baseIndent: int)[source]
Build the nested MuJoCo body elements for a flexible panel.
- Parameters:
scGeometry – Hub and panel geometry, including the number of segments, segment dimensions [m], and segment mass [kg].
baseIndent – Number of leading indentation tabs for the first segment.
- Returns:
XML defining the nested segment bodies, bending and twisting joints, inertial properties, and visual geometry.
- Return type:
str
- scenarioFlexiblePanelMuJoCo.plotAttitudeError(timeAxis: ndarray, sigma_BR: ndarray) Figure[source]
Plots attitude error MRP components
- scenarioFlexiblePanelMuJoCo.plotAttitudeErrorRate(timeAxis: ndarray, omega_BR_B: ndarray) Figure[source]
Plots attitude error rate components
- scenarioFlexiblePanelMuJoCo.plotBendingAngleRates(timeAxis: ndarray, thetaDot: list, numberOfSegments: int) Figure[source]
Plots bending angle rates for each segment
- scenarioFlexiblePanelMuJoCo.plotBendingAngles(timeAxis: ndarray, theta: list, numberOfSegments: int) Figure[source]
Plots bending angles for each segment
- scenarioFlexiblePanelMuJoCo.plotTorsionalAngleRates(timeAxis: ndarray, betaDot: list, numberOfSegments: int) Figure[source]
Plots torsional angle rates for each segment
- scenarioFlexiblePanelMuJoCo.plotTorsionalAngles(timeAxis: ndarray, beta: list, numberOfSegments: int) Figure[source]
Plots torsional angles for each segment
- scenarioFlexiblePanelMuJoCo.run(showPlots: bool = False)[source]
Run 10 minutes of attitude control with a flexible solar panel.
- 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 six Matplotlib figures: bending and twisting angles, their rates, attitude error, and angular-rate tracking error. No files are saved by this function.
- Return type:
dict