scenarioMonteCarloAttRW

Overview

Demonstrates how to run basic Monte-Carlo (MC) RW-based attitude simulations. This script duplicates the scenario in scenarioAttitudeFeedbackRW where a 6-DOF spacecraft is orbiting the Earth. Here some simulation parameters are dispersed randomly using a multi-threaded Monte-Carlo setup. Reaction Wheel (RW) state effector are added to the rigid spacecraft() hub, and what flight algorithm module is used to control these RWs. The scenario is run in a single configuration: by not using the Jitter model and by using the RW Voltage IO. Given this scenario we can add dispersions to the variables in between each MC run.

The script is found in the folder basilisk/examples and executed by using:

python3 scenarioMonteCarloAttRW.py

For more information on the Attitude Feedback Simulation with RW, please see the documentation on the scenarioAttitudeFeedbackRW file.

Bokeh Visualization and Data Management

This script includes options for interactive visualization using Bokeh and data management:

  1. To use the Bokeh server for interactive visualization, run the script with:

    python scenarioMonteCarloAttRW.py --bokeh-server
    

    IMPORTANT: When using Bokeh visualization, delete_data MUST be set to False in the run() function call. The –delete-data flag must not be used, as Bokeh requires the data files to remain available for interactive plotting. The run() function should be called with:

    dirName = run(saveFigures=True, case=1, show_plots=True, delete_data=False, useBokeh=True)
    
  2. For matplotlib visualization, you can automatically delete Monte Carlo data after generating plots by adding the –delete-data flag:

    python scenarioMonteCarloAttRW.py --delete-data
    

The –delete-data option will remove the Monte Carlo data directory after the plots are generated, helping to manage disk space when running multiple simulations. However, this option is incompatible with Bokeh visualization since Bokeh requires the data files to remain available for interactive plotting. When using Bokeh, delete_data must be explicitly set to False to ensure the data remains available for the interactive visualization.

Enable Terminal Bar to Show Simulation Progress

To enable progress bar, one need to set showProgressBar data member of class SimulationParameters to true:

monteCarlo = Controller()
monteCarlo.setShowProgressBar(True)

Method setShowProgressBar should be used to set variable showProgressBar as True with the above statement. After enabling the progress bar, all the simulation run by monteCarlo.ExecuteSimulation() and montoCarlo.runInitialConditions will show the progress bar in the terminal.

Setup Changes for Monte-Carlo Runs

In order to set up the multi-threaded MC simulation, the user must first instantiate the Controller class. The function that is being simulated is the set in this class (in this case, it’s defined in the same file as the MC scenario). The user can then set other variables such as the number of runs, the dispersion seeds, and number of cores.

The next important step to setting up the MC runs is to disperse the necessary variables. The dispersions that are set are listed in the following table:

Input

Description of Element

Distribution

Inertial attitude

Using Modified Rodrigues Parameters

Uniform for all 3 rotations between [0, 2 pi]

Inertial rotation rate

Using omega vector

Normal dispersions for each of the rotation components, each of mean 0 and standard deviation 0.25 deg/s

Mass of the hub

Total Mass of the spacecraft

Uniform around +/-5% of expected values. Bounds are [712.5, 787.5]

Center of Mass Offset

Position vector offset on the actual center of mass, and its theoretical position

Normally around a mean [0, 0, 1], with standard deviations of [0.05/3, 0.05/3, 0.1/3]

Inertia Tensor

3x3 inertia tensor. Dispersed by 3 rotations

Normally about mean value of diag(900, 800, 600). Each of the 3 rotations are normally distributed with angles of mean 0 and standard deviation 0.1 deg.

RW axes

The rotation axis for each of the 3 wheels

Normally around a respective means [1,0,0], [0,1,0], and [0,0,1] with respective standard deviations [0.01/3, 0.005/3, 0.005/3], [0.005/3, 0.01/3, 0.005/3], and [0.005/3, 0.005/3, 0.01/3].

RW speeds

The rotation speed for each of the 3 wheels

Uniform around +/-5% of expected values. Bounds are [95, 105], [190, 210], and [285, 315]

Voltage to Torque Gain

The gain between the commanded torque and the actual voltage

Uniform around +/-5% of expected values. Bounds are [0.019, 0.021]

Next a retention policy is used to log the desired data. The simulation can now be run. It returns the failed jobs, which should not occur. When the MC have been executed, the data can be accessed and tested in different ways. This is explained in the example python code comments.

Illustration of Simulation Results

saveFigures = False, case = 1, show_plots = True, useBokeh = False
../_images/scenarioMonteCarloAttRW_AttitudeError.svg ../_images/scenarioMonteCarloAttRW_RateTrackingError.svg ../_images/scenarioMonteCarloAttRW_RWMotorTorque.svg ../_images/scenarioMonteCarloAttRW_RWSpeed.svg ../_images/scenarioMonteCarloAttRW_RWVoltage.svg

Object Management in Monte Carlo Simulations

When creating Monte Carlo simulations, all simulation objects must be added as attributes to the simulation container (scSim). For example:

scSim.scObject = spacecraft.Spacecraft()
scSim.RW1 = RW1
scSim.rwVoltageIO = motorVoltageInterface.MotorVoltageInterface()

This pattern is required for the Monte Carlo framework to:

  1. Access and modify object parameters between runs (for dispersions)

  2. Properly retain data through the RetentionPolicy mechanism

  3. Ensure objects persist between simulation runs

  4. Allow the Controller class to track and manage simulation state

Without adding objects to scSim, the Monte Carlo framework wouldn’t be able to properly manage the simulation across multiple runs and thus unexpected behavior will occur.

scenarioMonteCarloAttRW.run(saveFigures, case, show_plots, delete_data=True, useBokeh=False)[source]

The scenarios can be run with the followings setups parameters:

Parameters:
  • saveFigures (bool) – flag if the scenario figures should be saved for html documentation

  • case (int) – Case 1 is normal MC, case 2 is initial condition run

  • show_plots (bool) – Determines if the script should display plots

  • delete_data (bool) – Flag to delete Monte Carlo data after running

  • useBokeh (bool) – Flag to use Bokeh for plotting instead of matplotlib