Post · 8 min read· pp. 391–396

SimulationBaseClass 

SimulationBaseClass

class SimulationBaseClass.EventHandlerClass(eventName, eventRate=1000000000, eventActive=False, conditionList=None, actionList=None, conditionFunction=None, actionFunction=None, conditionTime=None, terminal=False, exactRateMatch=True)[source] : Bases: object

code
Class for defining event checking behavior, conditions, and actions.

Three checking strategies are supported:

> 1. **Exact Interval Checking**: (default) The event is checked only when the
>    current time is an exact multiple of the `eventRate`. This behavior is similar
>    to how tasks are scheduled in Basilisk. Note that if no task leads to a timestep
>    at a checking time, the event will not be checked.
> 2. **Elapsed Interval Checking**: The event is checked whenever the `eventRate`
>    has elapsed since the last check. This is enabled by setting `exactRateMatch`
>    to `False`. This behavior is similar to how Basilisk loggers operate.
> 3. **Condition Time Checking**: An alternative to interval-based checking when
>    an event should occur at a specific time. This is enabled by setting
>    `conditionTime`, and will lead to the event being triggered at the first
>    timestep at or after the specified time.

When an event is checked, the `conditionFunction` is called to determine if the
event should occur. If the condition returns `True`, the `actionFunction` is executed.
and the event is deactivated. To continue checking the event, it must be reactivated.
If the event is marked as `terminal`, the simulation will be instructed to terminate
when the event condition occurs.

Parameters:
:   - **eventName** (*str*) – Name of the event
    - **eventRate** (*int*) – Rate at which the event is checked in nanoseconds
    - **eventActive** (*bool*) – Whether the event is active or not
    - **terminal** (*bool*) – Whether this event should terminate the simulation when it occurs
    - **conditionFunction** (*function*) – Function to check if the event should occur. The
      function should take the simulation object as an argument and return a boolean.
      This is the preferred manner to set conditions as it enables the use of arbitrary
      packages and objects in events and allows for event code to be parsed by IDE tools.
    - **conditionTime** (*int*) – Alternative to conditionFunction, a time in nanoseconds to trigger
      the event. Does not depend on eventRate for checking.
    - **actionFunction** (*function*) – Function to execute when the event occurs. The
      function should take the simulation object as an argument.
      This is the preferred manner to set conditions as it enables the use of arbitrary
      packages and objects in events and allows for event code to be parsed by IDE tools.
    - **exactRateMatch** (*bool*) – If True, the event is checked only when the current time is an
      exact multiple of the eventRate. If False, the event is checked whenever the
      `eventRate` has elapsed since the last check.
    - **conditionList** (*list*) – (deprecated) List of conditions to check for the event,
      expressed as strings of code to execute within the class.
    - **actionList** (*list*) – (deprecated) List of actions to perform when the event occurs,
      expressed as strings of code to execute within the class.

checkEvent(*parentSim*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#EventHandlerClass.checkEvent)
:   Check the condition and execute the action if condition is met.

nextCheckTime(*currentTime*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#EventHandlerClass.nextCheckTime)
:   Get the earliest upcoming time this event should be checked.

shouldBeChecked(*currentTime*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#EventHandlerClass.shouldBeChecked)
:   See if the event should be checked at the current time.

class SimulationBaseClass.SimBaseClass[source] : Bases: object

code
Simulation Base Class

AddModelToTask(*TaskName*, *NewModel*, *ModelData=None*, *ModelPriority=-1*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.AddModelToTask)
:   This function is responsible for passing on the logger to a module instance (model), adding the
    model to a particular task, and defining
    the order/priority that the model gets updated within the task.

    Parameters:
    :   - **(****str****)** (*TaskName*) – Name of the task
        - **(****obj****)** (*NewModel*) – Model to add to the task
        - **ModelData** – None or struct containing, only used for C BSK modules
        - **(****int****)** (*ModelPriority*) – Priority that determines when the model gets updated. (Higher number = Higher priority)

    Returns:

ConfigureStopTime(*TimeStop*, *StopCondition: Literal['<=', '>='] = '<='*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.ConfigureStopTime)
:   Set the simulation stop time in nano-seconds.

    Parameters:
    :   - **TimeStop** (*int*) – Time to stop the simulation in nanoseconds
        - **StopCondition** (*str*) –

          Condition for meeting the stop time. Two behaviors
          are supported:

          - `<=`: (default) The simulation will run as far as it can such that the
            `StopTime` is met if possible, but not exceeded.
          - `>=`: The simulation will run as far as it can such that the
            `StopTime` is minimally exceeded, but met if possible.

CreateNewProcess(*procName*, *priority=-1*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.CreateNewProcess)
:   Creates a process and adds it to the sim

    Parameters:
    :   - **(****str****)** (*procName*) – Name of process
        - **(****int****)** (*priority*) – Priority that determines when the model gets updated. (Higher number = Higher priority)

    Returns:
    :   simulationArchTypes.ProcessBaseClass object

CreateNewTask(*TaskName*, *TaskRate*, *InputDelay=None*, *FirstStart=0*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.CreateNewTask)
:   Creates a simulation task on the C-level with a specific update-frequency (TaskRate), an optional delay, and
    an optional start time.

    Parameters:
    :   - **TaskName** (*str*) – Name of Task
        - **TaskRate** (*int*) – Number of nanoseconds to elapse before update() is called
        - **InputDelay** (*int*) – (deprecated, unimplemented) Number of nanoseconds simulating a lag of the particular task
        - **FirstStart** (*int*) – Number of nanoseconds to elapse before task is officially enabled

    Returns:
    :   simulationArchTypes.TaskBaseClass object

ExecuteSimulation()[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.ExecuteSimulation)
:   run the simulation until the prescribed stop time or termination.

GetMessageConnectionDot(*extraMessages=None*, *includeUnlinked=True*, *includeRecorders=True*, *graphvizLayout='vertical'*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.GetMessageConnectionDot)
:   Return a Graphviz DOT description of the simulation message graph.

    Parameters:
    :   - **extraMessages** (*dict* *or* *list**[**dict**]**,* *optional*) – Stand-alone messages to
          include as possible source messages.
        - **includeUnlinked** (*bool*) – If `True`, include unlinked input message
          endpoints.
        - **includeRecorders** (*bool*) – If `True`, include message recorder modules.
        - **graphvizLayout** (*str*) – Graphviz module layout direction. Use
          `"vertical"` for a top-to-bottom layout or `"horizontal"`
          for a left-to-right layout.

    Returns:
    :   Graphviz DOT source text.

    Return type:
    :   str

GetMessageConnectionGraph(*extraMessages=None*, *includeUnlinked=True*, *includeRecorders=True*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.GetMessageConnectionGraph)
:   Extract Basilisk message connections from the configured simulation.

    Parameters:
    :   - **extraMessages** (*dict* *or* *list**[**dict**]**,* *optional*) – Stand-alone messages to
          include as possible source messages. The dictionary keys are used
          as labels in the returned graph and any generated figure.
        - **includeUnlinked** (*bool*) – If `True`, include unlinked input message
          endpoints in the returned graph.
        - **includeRecorders** (*bool*) – If `True`, include message recorder modules
          in the returned graph.

    Returns:
    :   A graph dictionary containing module records, stand-alone
        message records, endpoint records, connection edge records, unlinked
        inputs, and linked inputs whose source was not found.

    Return type:
    :   dict

InitializeSimulation()[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.InitializeSimulation)
:   Initialize the BSK simulation. This runs the SelfInit() and Reset() methods on each module.

SetProgressBar(*value*, *targetUpdates=None*, *updateInterval=None*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.SetProgressBar)
:   Shows a dynamic progress in the terminal while the simulation is executing.

    Parameters:
    :   - **value** (*bool*) – Flag indicating if progress should be displayed.
        - **targetUpdates** (*int**,* *optional*) – Approximate number of progress updates
          to produce over the simulation run.
        - **updateInterval** (*int**,* *optional*) – Fixed progress update interval in
          nanoseconds.

ShowExecutionFigure(*show\_plots=False*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.ShowExecutionFigure)
:   Shows in what order the Basilisk processes, task lists and modules are executed

ShowExecutionOrder()[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.ShowExecutionOrder)
:   Shows in what order the Basilisk processes, task lists and modules are executed

ShowMessageConnectionFigure(*show\_plots=False*, *extraMessages=None*, *includeUnlinked=True*, *includeRecorders=True*, *renderer='matplotlib'*, *fileName=None*, *graphvizFormat='svg'*, *graphvizLayout='vertical'*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.ShowMessageConnectionFigure)
:   Show how Basilisk messages are connected between simulation modules.

    Parameters:
    :   - **show\_plots** (*bool*) – If `True`, display the Matplotlib figure or
          open the rendered Graphviz output file.
        - **extraMessages** (*dict* *or* *list**[**dict**]**,* *optional*) – Stand-alone messages to
          draw as source messages. The dictionary keys are used as labels.
        - **includeUnlinked** (*bool*) – If `True`, draw unlinked input message
          endpoints.
        - **includeRecorders** (*bool*) – If `True`, draw message recorder modules.
        - **renderer** (*str*) – Rendering backend. Use `"matplotlib"` to return a
          Matplotlib figure, or `"graphviz"` to render through the
          Graphviz `dot` executable.
        - **fileName** (*str**,* *optional*) – Output path for the Graphviz renderer. If
          no extension is provided, `graphvizFormat` is appended.
        - **graphvizFormat** (*str*) – Graphviz output format, such as `"svg"`,
          `"png"`, `"pdf"`, or `"dot"`.
        - **graphvizLayout** (*str*) – Graphviz module layout direction. Use
          `"vertical"` for a top-to-bottom layout or `"horizontal"`
          for a left-to-right layout.

    Returns:
    :   Matplotlib figure for the
        `"matplotlib"` renderer, or the Graphviz output file path for the
        `"graphviz"` renderer.

    Return type:
    :   matplotlib.figure.Figure or str

<a id="SimulationBaseClass.SimBaseClass.activeEvents"></a> activeEvents()[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.activeEvents)
:   Return an immutable snapshot of the currently active events.

    The cache is itself an immutable tuple, so it is returned directly:
    external callers cannot mutate it to silently change which events fire,
    and no per-call copy is allocated. See `_ensureActiveEventCache()`
    for the caching behaviour.

createNewEvent(*eventName*, *\*args*, *\*\*kwargs*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.createNewEvent)
:   Create an event sequence that contains a series of tasks to be executed.

    Parameters:
    :   - **eventName** (*str*) – Name of the event
        - **\*args** – Arguments to pass to the [`EventHandlerClass`](#SimulationBaseClass.EventHandlerClass) constructor
        - **\*\*kwargs** – Keyword arguments to pass to the [`EventHandlerClass`](#SimulationBaseClass.EventHandlerClass) constructor

disableTask(*TaskName*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.disableTask)
:   Disable this particular task from being executed.

enableTask(*TaskName*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.enableTask)
:   Enable this particular task to be executed.

setAllButCurrentEventActivity(*currentEventName*, *activityCommand*, *useIndex=False*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.setAllButCurrentEventActivity)
:   Set all event activity variables except for the currentEventName event. The `useIndex` flag can be used to
    prevent enabling or disabling every task, and instead only alter the ones that belong to the same group (for
    example, the same spacecraft). The distinction is made through an index set after the `_` symbol in the event
    name. All events of the same group must have the same index.

setEventActivity(*eventName*, *activityCommand*)[[source]](https://avslab.github.io/basilisk/_modules/SimulationBaseClass.html#SimBaseClass.setEventActivity)
:   Enable or disable the named event.

    `activityCommand` is the boolean value assigned to the event’s
    `eventActive` flag. The cached active-event list (see
    [`activeEvents()`](#SimulationBaseClass.SimBaseClass.activeEvents)) is invalidated only when the flag actually
    changes, so setting an event to the activity state it already has does
    not force an unnecessary rebuild.

class SimulationBaseClass.StructDocData(strName)[source] : Bases: object

code
Structure data documentation class

SimulationBaseClass.methodizeAction(actionList)[source] : Methodize an action list to a function

SimulationBaseClass.methodizeCondition(conditionList)[source] : Methodize a condition list to a function