AstroCallbacks
AstroCallbacks provides fundamental calculations used throughout the Epicycle ecosystem. These calculations can be used in targeting and optimization variables and constraints, propagator stopping conditions, I/O operations, and eventally solver-for and consider parameters for orbit determination.
The module serves as a foundation for higher-level astrodynamics operations, providing core mathematical functions and utilities needed across multiple Epicycle packages.
Calculation Framework
AstroCallbacks contains the "Calcs" - a collection of structs that provide a unified interface for setting and getting quantities throughout Epicycle. These calculation objects can be used in stopping conditions, solver variables and constraints, and estimator solve-for and consider parameters.
The Calc framework provides type-stable access to commonly needed astrodynamics quantities while maintaining automatic differentiation compatibility. Each Calc struct implements standardized interfaces for both retrieving values from spacecraft states, celestial bodies, and setting target values for optimization.
Calc Types
The framework includes several categories of calculations, and is designed for extensibility. A few types of Calcs include:
- OrbitCalc: Semi-major axis, eccentricity, inclination, incoming/outgoing asymptotes, periapsis conditions, and other orbital properties
- BodyCalc: Celestial body gravitational parameters, physical properties, and other body-specific quantities
- ManeuverCalc: Δv components and magnitude, thrust direction, and other maneuver-related properties
Each Calc type supports both getter operations (extracting values) and setter operations (defining target values for optimization or constraints).
Quick Start
Examples of common orbital calculations: (see AstroProp and AstroSolve docs for interation into those packages in stopping conditions, optimization variables, and constraints.)
using AstroCallbacks, AstroStates, AstroModels
# Create a spacecraft with orbital state
sc = Spacecraft(state = CartesianState([7000.0, 0.0, 0.0, 0.0, 7.5, 0.0]),
time = Time("2024-01-01T12:00:00", UTC(), ISOT()),
mass = 1000.0)
# Get semi-major axis from current state
sma_calc = OrbitCalc(sc, SMA())
a = get_calc(sma_calc)
set_calc!(sma_calc, 10000.0)
# Set target incoming asymptote (rp = 6900, C3 = 14.0)
hyp = OrbitCalc(sc, IncomingAsymptote())
set_calc!(hyp, [6900.0, 14.0, 0.0, 0.0, 0.0, 0.0])
# Set and get Earth's mu
mu_calc = BodyCalc(earth, GravParam())
μ = get_calc(mu_calc)
set_calc!(mu_calc, 3.986e5)
# Set and get maneuver elements
toi = ImpulsiveManeuver()
dvvec_calc = ManeuverCalc(toi, sc, DeltaVVector())
Δv = get_calc(dvvec_calc)
set_calc!(dvvec_calc, [0.2, 0.3, 0.4])Table of Contents
AstroCallbacks.BodyCalcAstroCallbacks.ConstraintAstroCallbacks.ConstraintAstroCallbacks.DeltaVMagAstroCallbacks.EccAstroCallbacks.GravParamAstroCallbacks.IncAstroCallbacks.ManeuverCalcAstroCallbacks.OrbitCalcAstroCallbacks.OrbitCalcAstroCallbacks.OutGoingRLAAstroCallbacks.PosDotVelAstroCallbacks.PosMagAstroCallbacks.PosXAstroCallbacks.PosZAstroCallbacks.PositionVectorAstroCallbacks.RAANAstroCallbacks.SMAAstroCallbacks.TAAstroCallbacks.VelMagAstroCallbacks.VelocityVectorAstroCallbacks._extract_muAstroCallbacks._infer_numvarsAstroCallbacks._set_calc_type!AstroCallbacks._set_calc_type!AstroCallbacks._set_calc_type!AstroCallbacks._set_calc_type!AstroCallbacks._state_for_calcAstroCallbacks._subjects_from_calcAstroCallbacks.calc_input_statetagAstroCallbacks.calc_is_settableAstroCallbacks.convert_orbitcalc_stateAstroCallbacks.convert_orbitcalc_stateAstroCallbacks.func_evalAstroCallbacks.get_calcAstroCallbacks.get_calcAstroCallbacks.set_calc!AstroCallbacks.to_concrete_state
API Reference
AstroCallbacks.BodyCalc — Type
BodyCalc(body::AbstractCelestialBody, var::AbstractBodyVar)Calc struct for set/get body-derived variables for a CelestialBody
Fields
- body::B where B<:AbstractCelestialBody
- var::V where V<:AbstractBodyVar
Notes:
- For a list of all supported BodyCalc variables, see
?AbstractBodyVar.
Examples
mu_calc = BodyCalc(earth, GravParam())
muval = get_calc(mu_calc)
set_calc!(mu_calc, 3.986e5)AstroCallbacks.Constraint — Type
Constraint(calc; lower_bounds, upper_bounds, scale)Container that binds a calc and its bounds/scale for use in optimization, estimation, and analysis.
Fields
- calc::C where C<:AbstractCalc
- lower_bounds::Vector{T}
- upper_bounds::Vector{T}
- scale::Vector{T}
- numvars::Int
Notes:
- The keyword constructor infers
numvarsfrom the calc. - Element type
Tis promoted across the three vectors (supports Dual numbers and BigFloat). - Use
func_eval(::Constraint)to evaluate the calc and return a Vector.
Examples
mu_calc = BodyCalc(earth, GravParam())
con = Constraint(calc=mu_calc, lower_bounds=[3.9e5], upper_bounds=[4.1e5], scale=[1.0])AstroCallbacks.Constraint — Method
function Constraint(; calc::AbstractCalc,
lower_bounds::Union{AbstractVector{<:Real}, Nothing} = nothing,
upper_bounds::Union{AbstractVector{<:Real}, Nothing} = nothing,
scale::Union{AbstractVector{<:Real}, Nothing} = nothing)Keyword outer constructor for Constraint with intelligent defaults.
At least one of lower_bounds or upper_bounds must be specified.
- If
lower_boundsis not specified, defaults tofill(-Inf, n)wherenis inferred from calc - If
upper_boundsis not specified, defaults tofill(Inf, n)wherenis inferred from calc - If
scaleis not specified, defaults toones(T, n)whereTis inferred from bounds
AstroCallbacks.DeltaVMag — Type
DeltaVMag <: AbstractManeuverVarTag struct indicating magnitude of the delta-V vector of a maneuver.
Examples
# dv::ImpulsiveManeuver — replace with your maneuver
dvmag_calc = ManeuverCalc(dv, DeltaVMag())
Δv = get_calc(dvmag_calc) See also
- DeltaVVector
subtypes(AbstractManeuverVar)for a full list of supported variables
AstroCallbacks.Ecc — Type
Ecc <: AbstractOrbitVarTag struct indicating Keplerian eccentricity of an orbit.
Examples
# sc::Spacecraft — replace with your Spacecraft instance
ecc_calc = OrbitCalc(Spacecraft(), Ecc())
a = get_calc(ecc_calc)
set_calc!(ecc_calc, 0.02) # set Ecc to 0.02See also
- TA, RAAN, SMA
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.GravParam — Type
GravParam <: AbstractBodyVarTag struct indicating gravitational parameter μ of a celestial body.
Examples
mu_calc = BodyCalc(earth, GravParam())
μ = get_calc(mu_calc)
set_calc!(mu_calc, 3.986e5) See also
- BodyCalc
subtypes(AbstractBodyVar)for a full list of supported variables
AstroCallbacks.Inc — Type
Inc <: AbstractOrbitVarTag struct indicating Keplerian inclination (radians) of a spacecraft.
Examples
sc = Spacecraft()
inc_calc = OrbitCalc(sc, Inc())
inc = get_calc(inc_calc) # e.g., 0.4974 (28.5 degrees)
set_calc!(inc_calc, deg2rad(2.0)) # set inclination to 2 degreesAstroCallbacks.ManeuverCalc — Type
ManeuverCalc(man, sc::Spacecraft, var::AbstractManeuverVar)Calc struct for set/get maneuver-derived variables for a Maneuver and Spacecraft.
Fields
- man::M where M is a maneuver model (e.g., ImpulsiveManeuver)
- sc::S where S<:Spacecraft
- var::V where V<:AbstractManeuverVar
Notes:
- See ?AbstractManeuverVar for supported maneuver variables (e.g., DeltaVVector).
- Use getcalc(::ManeuverCalc) to evaluate and setcalc!(::ManeuverCalc, values) to assign when supported.
Examples
m = ImpulsiveManeuver(axes=Inertial(), Isp=300.0, element1=0.01, element2=0.02,
element3=-0.03)
sc = Spacecraft(
state = CartesianState([7000.0, 300.0, 0.0, 0.0, 7.5, 1.0]),
time = Time("2020-01-01T00:00:00", TAI(), ISOT()),
)
mc_vec = ManeuverCalc(m, sc, DeltaVVector())
dv = get_calc(mc_vec)
set_calc!(mc_vec, [0.01, 0.02, -0.03])
mc_mag = ManeuverCalc(m, sc, DeltaVMag())
dvm = get_calc(mc_mag)AstroCallbacks.OrbitCalc — Type
OrbitCalc(sc::Spacecraft, var::AbstractOrbitVar; dependency = nothing)Calc struct for set/get orbit-derived variables for a spacecraft.
Fields
- sc::Spacecraft: Subject spacecraft.
- var::AbstractOrbitVar: Orbit variable tag to evaluate (e.g., PositionVector()).
- dep: Optional dependency (e.g., another Spacecraft) or
nothing.
Notes:
- For a list of all supported BodyCalc variables, see
?AbstractOrbitVar. - Conversions that require μ obtain it from the
CoordinateSystemorigin when available. - Use
get_calc(::OrbitCalc)to evaluate - Use
set_calc!(::OrbitCalc, values)to assign when supported.
Examples
sc = Spacecraft(
state = CartesianState([7000.0, 300.0, 0.0, 0.0, 7.5, 1.0]),
time = Time("2020-09-21T12:23:12", TAI(), ISOT()),
)
oc = OrbitCalc(sc, PositionVector())
r = get_calc(oc)
set_calc!(oc, [7000.0, 300.0, 0.0])AstroCallbacks.OrbitCalc — Method
OrbitCalc(sc::Spacecraft, var::V; dependency=nothing) where {V<:AbstractOrbitVar}Outer constructor for OrbitCalc
AstroCallbacks.OutGoingRLA — Type
OutGoingRLA <: AbstractOrbitVarTag struct indicating outgoing hyperbolic asymptote right ascension (radians).
Examples
# sc::Spacecraft — replace with your Spacecraft instance
rla_calc = OrbitCalc(Spacecraft(), OutGoingRLA())
Ω_out = get_calc(rla_calc) # e.g., 1.047
set_calc!(rla_calc, pi/3) # set outgoing RLA to 60 degreesSee also
- SMA, TA, RAAN
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.PosDotVel — Type
PosDotVel <: AbstractOrbitVarTag struct indicating dot product of Cartesian position and velocity vectors.
Examples
sc = Spacecraft()
posdotvel_calc = OrbitCalc(Spacecraft(), PosDotVel())
r = get_calc(posdotvel_calc)
set_calc!(posdotvel_calc, [7000.0, 300.0, 0.0])AstroCallbacks.PosMag — Type
PosMag <: AbstractOrbitVarTag struct indicating Cartesian position vector magnitude (km) of a spacecraft.
Examples
posmag_calc = OrbitCalc(Spacecraft(), PosMag())
r = get_calc(posmag_calc) # e.g., 7020.31
set_calc!(posmag_calc, 10000.0) # set |r| to 10000 km (keeps direction)See also
- PositionVector, VelocityVector, SMA
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.PosX — Type
PosX <: AbstractOrbitVarTag struct indicating Cartesian position vector x-component (km) of a spacecraft.
Examples
posx_calc = OrbitCalc(Spacecraft(), PosX())
r = get_calc(posx_calc)
set_calc!(posx_calc, 10000.0) See also
- PositionVector, VelocityVector, SMA
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.PosZ — Type
PosZ <: AbstractOrbitVarTag struct indicating Cartesian position vector z-component (km) of a spacecraft.
Examples
posz_calc = OrbitCalc(Spacecraft(), PosZ())
r = get_calc(posz_calc)
set_calc!(posz_calc, 1000.0) AstroCallbacks.PositionVector — Type
PositionVector <: AbstractOrbitVarTag struct indicating Cartesian position vector (x, y, z) of a spacecraft.
Examples
# sc::Spacecraft — replace with your Spacecraft instance
posvec_calc = OrbitCalc(Spacecraft(), PositionVector())
r = get_calc(posvec_calc)
set_calc!(posvec_calc, [7000.0, 300.0, 0.0])See also
- PosMag, VelocityVector
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.RAAN — Type
RAAN <: AbstractOrbitVarTag struct indicating Keplerian right ascension of ascending node (radians) of a spacecraft.
Examples
raan_calc = OrbitCalc(Spacecraft(), RAAN())
Ω = get_calc(raan_calc) # e.g., 1.234
set_calc!(raan_calc, pi/2) # set RAAN to 90 degreesSee also
- SMA, TA, INC
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.SMA — Type
SMA <: AbstractOrbitVarTag struct indicating Keplerian semi-major axis (km) of a spacecraft.
Examples
sma_calc = OrbitCalc(Spacecraft(), SMA())
a = get_calc(sma_calc) # e.g., 7000.0
set_calc!(sma_calc, 10000.0) # set SMA to 10000 kmSee also
- TA, RAAN, PositionVector
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.TA — Type
TA <: AbstractOrbitVarTag struct indicating Keplerian true anomaly (radians) of a spacecraft.
Examples
ta_calc = OrbitCalc(Spacecraft(), TA())
θ = get_calc(ta_calc) # e.g., 0.5235987756
set_calc!(ta_calc, pi/6) # set TA to 30 degreesSee also
- SMA, RAAN, INC
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.VelMag — Type
VelMagMag <: AbstractOrbitVarTag struct indicating Cartesian velocity vector magnitude (km/s) of a spacecraft.
Examples
velmag_calc = OrbitCalc(Spacecraft(), VelMag())
r = get_calc(velmag_calc) # e.g., 7.5
set_calc!(velmag_calc, 10.0) # set |v| to 10 km/s (keeps direction)See also
- PositionVector, VelocityVector, SMA
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks.VelocityVector — Type
VelocityVector <: AbstractOrbitVarTag struct indicating Cartesian velocity vector (vx, vy, vz) of a spacecraft.
Examples
# sc::Spacecraft — replace with your Spacecraft instance
velvec_calc = OrbitCalc(Spacecraft(), VelocityVector())
r = get_calc(velvec_calc)
set_calc!(velvec_calc, [7000.0, 300.0, 0.0])See also
- PosMag, PositionVector
subtypes(AbstractOrbitVar)for a full list of supported variables
AstroCallbacks._extract_mu — Method
function _extract_mu(cs::CoordinateSystem)Extract μ from a coordinate system origin if it exists
AstroCallbacks._infer_numvars — Method
function _infer_numvars(c::AbstractCalc)Return the number of variables for a calc.
AstroCallbacks._set_calc_type! — Method
_set_calc_type!(c::AbstractCalc, newval)Fallback implementation for calc types that don't have specific _set_calc_type! methods. This should only be reached if settability checking is bypassed.
AstroCallbacks._set_calc_type! — Method
_set_calc_type!(c::ManeuverCalc, vals::AbstractVector{<:Real})Assign new value(s) to a settable maneuver-derived variable.
Arguments
- c::ManeuverCalc: Container holding the maneuver model, spacecraft, and variable tag.
- vals::AbstractVector{<:Real}: New value(s) for the variable.
Notes:
- Delegates to the variable-specific
_set!(c, vals)implementation. - Settability is checked by the generic
set_calc!method.
Returns
- Returns nothing. Performs inplace update of Maneuver.
- Spacecraft state is not modified. Use maneuver!() to apply maneuver effects.
Examples
m = ImpulsiveManeuver(axes=Inertial(), Isp=300.0, element1=0.01, element2=0.02, element3=-0.03)
sc = Spacecraft(state = CartesianState([7000.0, 300.0, 0.0, 0.0, 7.5, 1.0]),
time = Time("2020-01-01T00:00:00", TAI(), ISOT()))
mc = ManeuverCalc(m, sc, DeltaVVector())
set_calc!(mc, [0.01, 0.02, -0.03])
# outputAstroCallbacks._set_calc_type! — Method
_set_calc_type!(c::OrbitCalc, newval::Real)Type-specific implementation for OrbitCalc scalar assignments. Pass in real as a 1x1 vector to vector dispatch.
AstroCallbacks._set_calc_type! — Method
set_calc!(c::OrbitCalc, newval::Vector{<:Real})Assign a new value to a settable orbit-derived variable.
Arguments
- c::OrbitCalc: Container holding the spacecraft and variable tag.
- newval::Vector{<:Real}: New value(s) for the variable.
Notes:
- Required input state is determined by
calc_input_statetag(c.var)and converted as needed. - After assignment, the spacecraft’s state is converted back to its original type and updated.
- Non-settable variables throw an error (see
calc_is_settable).
Returns
- OrbitState: The updated spacecraft state.
Examples
sc = Spacecraft(
state = CartesianState([7000.0, 300.0, 0.0, 0.0, 7.5, 1.0]),
time = Time("2020-09-21T12:23:12", TAI(), ISOT()),
)
oc = OrbitCalc(sc, PositionVector())
set_calc!(oc, [7000.0, 300.0, 0.0])AstroCallbacks._state_for_calc — Method
function _state_for_calc(c::OrbitCalc)::AbstractOrbitStateCompute the state type required for the orbit calc variable. Performs conversion if needed.
AstroCallbacks._subjects_from_calc — Method
function _subjects_from_calc(c::AbstractCalc)Extract the references used in a Calc instance. For example, an OrbitCalc will return the spacecraft it references.
AstroCallbacks.calc_input_statetag — Method
function calc_input_statetag(v::AbstractOrbitVar)Fallback to catch undeclared OrbitCalc state type tags
AstroCallbacks.calc_is_settable — Method
calc_is_settable(::AbstractCalcVariable)::BoolFallback method to indicate if a Calc variable is settable.
AstroCallbacks.convert_orbitcalc_state — Method
function convert_orbitcalc_state(st::AbstractOrbitState, cs::CoordinateSystem,
target::AbstractOrbitStateType)::AbstractOrbitStateConvert AbstractOrbitState to state types and coordinates needed for OrbitCalc variable.
AstroCallbacks.convert_orbitcalc_state — Method
function convert_orbitcalc_state(os::OrbitState, cs::CoordinateSystem, target::AbstractOrbitStateType)::AbstractOrbitStateConvert OrbitState to state types and coordinates needed for OrbitCalc variable.
AstroCallbacks.func_eval — Method
function func_eval(constraint::Constraint)Evaluate the constraint's calc and return a Vector preserving eltype (AD-friendly)
AstroCallbacks.get_calc — Method
function get_calc(c::AbstractCalc)Compute the value of a Calc variable. Generic get_calc methods interface simple Calc types. More complicated types (i.e. OrbitCalc have custom interfaces)
AstroCallbacks.get_calc — Method
get_calc(c::OrbitCalc)Compute the value of an orbit-derived variable..
Arguments
- c::OrbitCalc: Container holding the spacecraft, variable tag, and optional dependency.
Returns
- Number or Vector{<:Real}: Computed value of the requested orbit variable.
Notes:
- Required input state is determined by
calc_input_statetag(c.var)and converted as needed. - If a conversion requires μ, it is taken from
c.sc.coord_sys.originwhen available.
Examples
sc = Spacecraft(
state = CartesianState([7000.0, 300.0, 0.0, 0.0, 7.5, 1.0]),
time = Time("2020-09-21T12:23:12", TAI(), ISOT()),
)
oc = OrbitCalc(sc, PositionVector())
val = get_calc(oc)AstroCallbacks.set_calc! — Method
set_calc!(c::AbstractCalc, newval)Set calc after checking if it is settable. (Generic dispatch to type-specific implementations.)
AstroCallbacks.to_concrete_state — Method
function to_concrete_state(os::OrbitState)::AbstractStateConverts an OrbitState to its equivalent concrete AbstractState
Arguments
os::OrbitState: The OrbitState instance to convert.