scenarioBasicOrbit example: a spacecraft propagating around Earth using point-mass gravity. By the end you will have a working simulation that records position and velocity, then plots the orbit.
Prerequisites
Install Basilisk and download the example scripts:bskExamples command copies the examples/ folder into your current working directory. Work from this local copy — do not edit files inside the installed package.
Build the simulation
Import modules
Every Basilisk simulation starts with the same set of imports. The
spacecraft module provides the 6-DOF dynamics model; the utilities supply the simulation container, unit converters, and gravity body factories.Create the simulation container
SimBaseClass is the top-level container for every Basilisk simulation. All processes, tasks, and modules attach to this object.Create a process and add a dynamics task
Basilisk organizes execution into processes (parallel execution groups) and tasks (ordered lists of modules within a process). The integration step size is set here in nanoseconds.
Set up the spacecraft
Instantiate a
Spacecraft module and add it to the dynamics task. The ModelTag is a human-readable label used in logging and Vizard visualization.Add a gravity body
Use
gravBodyFactory to create a gravitational body and attach it to the spacecraft. Setting isCentralBody = True marks Earth as the primary attractor.To simulate Mars instead, call
gravFactory.createMarsBarycenter() and set isCentralBody = True on that object. To add spherical harmonics, call planet.useSphericalHarmonicsGravityModel(path, degree) before connecting the factory to the spacecraft.Set initial orbit conditions
Define a Low Earth Orbit (LEO) using classical orbital elements, then convert to inertial position and velocity vectors to initialize the spacecraft state.
Set simulation time and configure data logging
Compute the orbital period and run for 75% of one orbit. Attach a recorder to the spacecraft’s state output message to capture position and velocity at regular intervals.
Initialize and run the simulation
InitializeSimulation runs self_init() and reset() on every module. ConfigureStopTime and ExecuteSimulation advance the simulation to the specified end time.Run the complete example
After downloading the examples withbskExamples, run the full scenario directly:
LEO, GEO, GTO), planet (Earth, Mars), and whether to enable spherical harmonic gravity. These are set at the bottom of the file under the if __name__ == "__main__": block.
Next steps
Core concepts
Learn how processes, tasks, and message-passing work together.
Attitude feedback tutorial
Add a 3-DOF attitude controller to the spacecraft.
Vizard visualization
Connect the 3D Vizard application to view your simulation live.
Build from source
Link custom C++ modules or enable optional build features.