Skip to main content

Overview

SpiceInterface wraps the NASA NAIF CSPICE library and updates a set of output messages with planet and spacecraft states at each simulation time step. It reads UTC epoch, loads kernel files, and writes SpicePlanetStateMsgPayload and SCStatesMsgPayload messages consumed by other modules.
from Basilisk.simulation import spiceInterface
from Basilisk import __path__ as bskPath

spiceObject = spiceInterface.SpiceInterface()
spiceObject.ModelTag = "SpiceObject"

Configuration parameters

SPICEDataPath
str
Path to the directory containing SPICE kernel files (.bsp, .tls, .pck, etc.).
spiceObject.SPICEDataPath = bskPath[0] + "/supportData/EphemerisData/"
UTCCalInit
str
UTC calendar date-time string that sets the simulation epoch.
spiceObject.UTCCalInit = "2021 MAY 04 07:47:48.965 (UTC)"
referenceBase
str
SPICE reference frame name for all output state vectors (e.g., "J2000").
spiceObject.referenceBase = "J2000"
zeroBase
str
SPICE body name used as the origin for position vectors (e.g., "Earth").
spiceObject.zeroBase = "Earth"
timeOutPicture
str
Optional SPICE time-format picture string for getCurrentTimeString(). When empty the default SPICE format is used.

Kernel management

addKernelPath(kernelPath)
method
Registers a single kernel file by absolute or relative path. Call before InitializeSimulation().
spiceObject.addKernelPath("/path/to/de430.bsp")
addKernelPaths(kernelPaths)
method
Registers a list of kernel paths at once.
spiceObject.addKernelPaths(["/path/de430.bsp", "/path/naif0012.tls"])
clearKernelPaths()
method
Clears the configured kernel list without unloading already-loaded kernels.
addPlanetNames(planetNames)
method
Specifies which planets to query from SPICE. Each name must be a valid SPICE body name.
spiceObject.addPlanetNames(["earth", "sun", "mars barycenter"])
addSpacecraftNames(spacecraftNames)
method
Specifies which spacecraft SPICE IDs to query.
spiceObject.addSpacecraftNames(["-143"])  # MRO SPICE ID

Input messages

epochInMsg
ReadFunctor<EpochMsgPayload>
(Optional) Subscribe to override the epoch set by UTCCalInit at runtime.
spiceObject.epochInMsg.subscribeTo(epochMsg)

Output messages

spiceTimeOutMsg
SpiceTimeMsgPayload
Current SPICE time (J2000, Julian date, GPS week/seconds).
planetStateOutMsgs
vector<SpicePlanetStateMsgPayload>
One message per body added via addPlanetNames(), carrying inertial position, velocity, and rotation matrix.
scStateOutMsgs
vector<SCStatesMsgPayload>
One message per body added via addSpacecraftNames(), carrying inertial position and velocity.

Full setup example

from Basilisk.simulation import spiceInterface
from Basilisk import __path__ as bskPath
from Basilisk.utilities import SimulationBaseClass, macros

scSim = SimulationBaseClass.SimBaseClass()
proc  = scSim.CreateNewProcess("spiceProc")
scSim.CreateNewTask("spiceTask", macros.sec2nano(1.0))

spiceObject = spiceInterface.SpiceInterface()
spiceObject.ModelTag    = "SpiceObject"
spiceObject.SPICEDataPath = bskPath[0] + "/supportData/EphemerisData/"
spiceObject.UTCCalInit  = "2021 MAY 04 07:47:48.965 (UTC)"
spiceObject.referenceBase = "J2000"
spiceObject.zeroBase    = "Earth"
spiceObject.addPlanetNames(["earth", "sun"])

scSim.AddModelToTask("spiceTask", spiceObject)
scSim.InitializeSimulation()
scSim.ConfigureStopTime(macros.sec2nano(3600.0))
scSim.ExecuteSimulation()

Build docs developers (and LLMs) love