Skip to main content

Overview

SimBaseClass is the root class you subclass (or instantiate directly) for every Basilisk simulation. It wraps the C-level SimModel object and exposes Python-level APIs for constructing processes, tasks, and modules, scheduling events, and running the simulation.
from Basilisk.utilities import SimulationBaseClass

scSim = SimulationBaseClass.SimBaseClass()

SimBaseClass

Constructor

SimBaseClass()
Creates a new simulation instance. Initializes TotalSim, empty task and process lists, the event map, and a BSKLogger.

Process and task setup

CreateNewProcess
method
Creates a simulation process and registers it with the simulation engine.
proc = scSim.CreateNewProcess(procName, priority=-1)
Returns a simulationArchTypes.ProcessBaseClass object.
CreateNewTask
method
Creates a simulation task with a fixed update rate.
task = scSim.CreateNewTask(TaskName, TaskRate, FirstStart=0)
Returns a simulationArchTypes.TaskBaseClass object.
AddModelToTask
method
Adds a module to a named task and optionally sets its execution priority within that task.
scSim.AddModelToTask(TaskName, NewModel, ModelData=None, ModelPriority=-1)
Raises ValueError if TaskName does not match any registered task.

Simulation execution

InitializeSimulation
method
Calls SelfInit() and Reset() on every module. You must call this before ExecuteSimulation().
scSim.InitializeSimulation()
ConfigureStopTime
method
Sets the simulation stop time.
scSim.ConfigureStopTime(TimeStop, StopCondition="<=")
ExecuteSimulation
method
Runs the simulation until the configured stop time or until a terminal event fires.
scSim.ExecuteSimulation()
SetProgressBar
method
Enables or disables a terminal progress bar during execution.
scSim.SetProgressBar(True)

Task control

enableTask
method
Enables a previously disabled task.
scSim.enableTask(TaskName)
disableTask
method
Prevents a task from executing without removing it.
scSim.disableTask(TaskName)
ResetTask
method
Resets all modules in the named task at the current simulation time.
scSim.ResetTask(taskName)

Visualization

ShowExecutionOrder
method
Prints the process → task → module execution order to the terminal with color coding.
scSim.ShowExecutionOrder()
ShowExecutionFigure
method
Renders a matplotlib figure showing the process/task/module hierarchy.
fig = scSim.ShowExecutionFigure(show_plots=False)

Event system

createNewEvent
method
Registers a new event handler.
scSim.createNewEvent(eventName, *args, **kwargs)
All extra arguments are forwarded to EventHandlerClass. See the EventHandlerClass section below.
setEventActivity
method
Activates or deactivates a named event.
scSim.setEventActivity(eventName, activityCommand)
setAllButCurrentEventActivity
method
Sets activity on all events except currentEventName. Pass useIndex=True to restrict changes to events sharing the same index suffix.
scSim.setAllButCurrentEventActivity(currentEventName, activityCommand, useIndex=False)

EventHandlerClass

Encapsulates an event’s check strategy, condition, and action.
EventHandlerClass(
    eventName,
    eventRate=int(1e9),
    eventActive=False,
    conditionFunction=None,
    actionFunction=None,
    conditionTime=None,
    terminal=False,
    exactRateMatch=True,
    conditionList=None,   # deprecated
    actionList=None,      # deprecated
)
eventName
str
required
Unique name for this event.
eventRate
int
default:"1000000000"
Check interval in nanoseconds (default 1 s).
eventActive
bool
default:"false"
Whether the event starts active.
conditionFunction
callable | None
default:"None"
Function (sim) -> bool. Called to test whether the event should fire. Mutually exclusive with conditionTime and conditionList.
actionFunction
callable | None
default:"None"
Function (sim) -> None. Called when the condition returns True. Mutually exclusive with actionList.
conditionTime
int | None
default:"None"
Fire the event at the first timestep at or after this nanosecond value. Mutually exclusive with conditionFunction.
terminal
bool
default:"false"
If True, the simulation terminates when this event fires.
exactRateMatch
bool
default:"true"
When True, the event is checked only at exact multiples of eventRate. When False, the event is checked whenever eventRate has elapsed since the last check.

Usage example

from Basilisk.utilities import SimulationBaseClass, macros

scSim = SimulationBaseClass.SimBaseClass()
proc  = scSim.CreateNewProcess("mainProc")
scSim.CreateNewTask("mainTask", macros.sec2nano(1.0))

# Terminate at t = 100 s
scSim.createNewEvent(
    "stopEvent",
    eventRate=macros.sec2nano(1.0),
    eventActive=True,
    terminal=True,
    conditionTime=macros.sec2nano(100.0),
    actionFunction=lambda sim: None,
)

scSim.InitializeSimulation()
scSim.ConfigureStopTime(macros.sec2nano(200.0))
scSim.ExecuteSimulation()

Module-level helpers

SetCArray
function
Writes a Python list into a SWIG-wrapped C array.
SetCArray(InputList, VarType, ArrayPointer)
getCArray
function
Reads a SWIG-wrapped C array into a Python list.
values = getCArray(varType, arrayPointer, arraySize)
synchronizeTimeHistories
function
Interpolates multiple time-history arrays onto a common time base.
synced = synchronizeTimeHistories(arrayList)
arrayList is a list of 2-D numpy arrays where column 0 is the time axis.

Build docs developers (and LLMs) love