Overview
The Spacecraft module integrates the translational and rotational equations of motion for a rigid spacecraft hub. You attach StateEffector objects (reaction wheels, fuel slosh, flexible panels) and DynamicEffector objects (thrusters, SRP, gravity) to build up the full system.
from Basilisk.simulation import spacecraft
scObject = spacecraft.Spacecraft()
scObject.ModelTag = "bsk-Sat"
Hub configuration parameters
Set these on scObject.hub before calling InitializeSimulation().
Total hub mass [kg].scObject.hub.mHub = 750.0 # [kg]
Inertia tensor of the hub about the body-frame origin point B, expressed in the body frame [kg·m²].scObject.hub.IHubPntBc_B = [
[900.0, 0.0, 0.0],
[ 0.0, 800.0, 0.0],
[ 0.0, 0.0, 600.0],
] # [kg*m^2]
Position of the hub center of mass relative to point B in the body frame [m].scObject.hub.r_BcB_B = [0.0, 0.0, 0.0] # [m]
Initial conditions
Initial inertial position of the spacecraft center of mass [m].
Initial inertial velocity of the spacecraft center of mass [m/s].
Initial attitude of the body frame B with respect to the inertial frame N, expressed as an MRP.
Initial angular velocity of the body frame relative to the inertial frame, expressed in the body frame [rad/s].
attRefInMsg
ReadFunctor<AttRefMsgPayload>
(Optional) Subscribe to this message to prescribe rotational motion rather than integrating free dynamics.scObject.attRefInMsg.subscribeTo(someAttRefMsg)
transRefInMsg
ReadFunctor<TransRefMsgPayload>
(Optional) Subscribe to this message to prescribe translational motion.scObject.transRefInMsg.subscribeTo(someTransRefMsg)
Output messages
Full spacecraft state (position, velocity, attitude MRP, angular rate, accumulated delta-v) in the inertial frame.
Total spacecraft mass properties (total mass, center of mass, inertia tensor).
Attaching effectors
scObject.addStateEffector(rwStateEffector) # e.g. reaction wheels
scObject.addDynamicEffector(thrusterEffector) # e.g. thrusters, SRP
The gravField attribute exposes the built-in GravityEffector:
earth = gravityEffector.GravBodyData()
earth.planetName = "earth_planet_data"
earth.mu = 3.986004418e14 # [m^3/s^2]
earth.isCentralBody = True
scObject.gravField.gravBodies = spacecraft.GravBodyVector([earth])
Full setup example
from Basilisk.simulation import spacecraft
from Basilisk.utilities import SimulationBaseClass, macros, orbitalMotion
scSim = SimulationBaseClass.SimBaseClass()
proc = scSim.CreateNewProcess("dynProc")
scSim.CreateNewTask("dynTask", macros.sec2nano(0.1))
scObject = spacecraft.Spacecraft()
scObject.ModelTag = "bsk-Sat"
# Hub mass properties
scObject.hub.mHub = 750.0 # [kg]
scObject.hub.IHubPntBc_B = [[900, 0, 0], [0, 800, 0], [0, 0, 600]] # [kg*m^2]
scObject.hub.r_BcB_B = [0.0, 0.0, 0.0] # [m]
# Initial orbit (LEO)
mu = orbitalMotion.MU_EARTH * 1e9 # convert km^3/s^2 -> m^3/s^2
oe = orbitalMotion.ClassicElements()
oe.a, oe.e, oe.i = (6778e3, 0.001, 0.5)
oe.Omega = oe.omega = oe.f = 0.0
rVec, vVec = orbitalMotion.elem2rv_parab(mu, oe)
scObject.hub.r_CN_NInit = rVec.tolist() # [m]
scObject.hub.v_CN_NInit = vVec.tolist() # [m/s]
scObject.hub.sigma_BNInit = [0.0, 0.0, 0.0]
scObject.hub.omega_BN_BInit = [0.0, 0.0, 0.0] # [rad/s]
scSim.AddModelToTask("dynTask", scObject)
scSim.InitializeSimulation()
scSim.ConfigureStopTime(macros.sec2nano(100.0))
scSim.ExecuteSimulation()