Random Attitudes

PyVista view of spacecraft with sampled orbits and body attitudes.

In addition to the orbit, MCConfig now samples the initial attitude quaternion q and body angular velocity w. The angular velocity plot below overlays the eight uncontrolled runs. Different starting rates lead to different torque-free paths.

random_attitudes.py
"""Sample orbit, initial attitude, and initial angular velocity."""

from pathlib import Path
import sys

sys.path.insert(0, str(Path(__file__).resolve().parents[3]))

import matplotlib.pyplot as plt
import numpy as np
import ADCS

satellite = ADCS.Satellite(mass=4.0, J_0=np.diag([0.03, 0.04, 0.05]))
initial_state = ADCS.State(
    w=np.zeros(3), q=np.array([1.0, 0.0, 0.0, 0.0])
)
orbit = ADCS.Orbital_State(
    ephem=ADCS.Ephemeris(), J2000=0.22,
    R=np.array([7000.0, 0.0, 0.0]),
    V=np.array([0.0, 7.5, 0.0]),
)
config = ADCS.MCConfig(
    orbit=lambda rng: ADCS.orbits.create_random_circular_os(
        radius_km=7000.0, J2000=0.22, rng=rng
    ),
    q=lambda rng: ADCS.helpers.normalize(rng.standard_normal(4)),
    w=lambda rng: np.deg2rad(rng.uniform(-3.0, 3.0, size=3)),
)
results = ADCS.simulate_mc(
    x=initial_state, satellite=satellite, os0=orbit,
    dt=2.0, tf=120.0, mc_config=config,
    num_runs=8, base_seed=42, max_workers=2,
)
ADCS.plot(results, ADCS.plots.AnimationPlot(), layout=(1, 1))
ADCS.plot(results, ADCS.plots.AngularVelocityPlot(), layout=(1, 1),
          title="Angular velocity across runs")

plt.show()

Sample an initial state

q must return a normalized four-component quaternion. w returns three body rates in radians per second. The example samples rates in degrees per second, then converts them with np.deg2rad.

Spaghetti plot of eight Monte Carlo angular-velocity histories.

Next: Random Goals.