Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pandas
matplotlib
numpy
scipy
colorama
tqdm
pillow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added :ref:`scenarioThrArmControl`, a MuJoCo example scenario for spacecraft control using thruster arms.
10 changes: 10 additions & 0 deletions examples/_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ It's recommended to study the first 6 scenarios in order:
Pointing with Reaction Wheels in MuJoCo <mujoco/scenarioAttitudeFeedbackRWMuJoCo>
Translation-only formation flying under differential drag <mujoco/scenarioFormationFlyingWithDrag>
Satellite Drag with Stochastic (Random) Density using MuJoCo <mujoco/scenarioStochasticDrag>
Spacecraft Control with Thruster Arms using MuJoCo <mujoco/scenarioThrArmControl>

Support Files
^^^^^^^^^^^^^

.. toctree::
:maxdepth: 1

Master File <mujoco/BSK_mujocoMasters>
Models Folder <mujoco/mujocoModels/index>

Constrained Spacecraft Dynamics Simulations
-------------------------------------------
Expand Down
94 changes: 94 additions & 0 deletions examples/mujoco/BSK_mujocoMasters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# ISC License
#
# Copyright (c) 2026, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# Get current file path
import inspect
import os
import sys

# Import architectural modules
from Basilisk.utilities import SimulationBaseClass

filename = inspect.getframeinfo(inspect.currentframe()).filename
path = os.path.dirname(os.path.abspath(filename))

# Import MuJoCo Dynamics and FSW models
sys.path.append(path + '/mujocoModels')


class BSKSim(SimulationBaseClass.SimBaseClass):
"""Main bskSim simulation class"""

def __init__(self, fswRate=0.01, dynRate=0.01):
self.dynRate = dynRate
self.fswRate = fswRate
# Create a sim module as an empty container
SimulationBaseClass.SimBaseClass.__init__(self)

self.DynModels = []
self.FSWModels = []
self.DynamicsProcessName = None
self.FSWProcessName = None
self.dynProc = None
self.fswProc = None

self.dynamics_added = False
self.fsw_added = False

def get_DynModel(self):
assert (self.dynamics_added is True), "It is mandatory to use a dynamics model as an argument"
return self.DynModels

def set_DynModel(self, dynModel):
self.dynamics_added = True
self.DynamicsProcessName = 'DynamicsProcess' # Create simulation process name
self.dynProc = self.CreateNewProcess(self.DynamicsProcessName) # Create process
self.DynModels = dynModel.BSKMujocoDynamicsModels(self, self.dynRate) # Create Dynamics class

def get_FswModel(self):
assert (self.fsw_added is True), "A flight software model has not been added yet"
return self.FSWModels

def set_FswModel(self, fswModel):
self.fsw_added = True
self.FSWProcessName = "FSWProcess" # Create simulation process name
self.fswProc = self.CreateNewProcess(self.FSWProcessName) # Create process
self.FSWModels = fswModel.BSKMujocoFSWModels(self, self.fswRate) # Create FSW class


class BSKScenario(object):
def __init__(self):
self.name = "scenario"

def configure_initial_conditions(self):
"""
Developer must override this method in their BSK_Scenario derived subclass.
"""
pass

def log_outputs(self):
"""
Developer must override this method in their BSK_Scenario derived subclass.
"""
pass

def pull_outputs(self):
"""
Developer must override this method in their BSK_Scenario derived subclass.
"""
pass
87 changes: 87 additions & 0 deletions examples/mujoco/mujocoModels/BSK_MujocoDynamics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# ISC License
#
# Copyright (c) 2026, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import os
from Basilisk.simulation import(
mujoco,
MJSystemCoM,
MJSystemMassMatrix,
MJJointReactionForces,
svIntegrators,
)
from Basilisk.utilities import macros as mc

XML_PATH = os.path.join(os.path.dirname(__file__), "..", "sat_w_thruster_arms.xml")


class BSKMujocoDynamicsModels():
"""
bskSim simulation class that sets up the MuJoCo spacecraft dynamics models.
"""
def __init__(self, SimBase, dynRate):
# Define process name, task name and task time-step
self.processName = SimBase.DynamicsProcessName
self.taskName = "DynamicsTask"
self.processTasksTimeStep = mc.sec2nano(dynRate)

# Create task
SimBase.dynProc.addTask(SimBase.CreateNewTask(self.taskName, self.processTasksTimeStep))

# Instantiate Dyn modules as objects
self.scene = mujoco.MJScene.fromFile(XML_PATH)
self.systemCoM = MJSystemCoM.MJSystemCoM()
self.systemMassMatrix = MJSystemMassMatrix.MJSystemMassMatrix()
self.jointReactionForces = MJJointReactionForces.MJJointReactionForces()
self.integrator = svIntegrators.svIntegratorRKF45(self.scene)

# Initialize all modules
self.InitAllDynObjects()

# Assign all initialized modules to tasks
SimBase.AddModelToTask(self.taskName, self.scene, 200)
SimBase.AddModelToTask(self.taskName, self.systemCoM, 199)
SimBase.AddModelToTask(self.taskName, self.systemMassMatrix, 198)
SimBase.AddModelToTask(self.taskName, self.jointReactionForces, 197)


# ------------------------------------------------------------------------------------------- #
# These are module-initialization methods

def setScene(self):
self.scene.extraEoMCall = True
self.scene.ModelTag = "mujocoScene"
self.scene.setIntegrator(self.integrator)

def setSystemCoM(self):
self.systemCoM.ModelTag = "systemCoM"
self.systemCoM.scene = self.scene

def setSystemMassMatrix(self):
self.systemMassMatrix.ModelTag = "systemMassMatrix"
self.systemMassMatrix.scene = self.scene

def setJointReactionForces(self):
self.jointReactionForces.ModelTag = "jointReactionForces"
self.jointReactionForces.scene = self.scene


# Global call to initialize every module
def InitAllDynObjects(self):
self.setScene()
self.setSystemCoM()
self.setSystemMassMatrix()
self.setJointReactionForces()
Loading
Loading