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

API Reference

AstroCallbacks.BodyCalcType
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)
source
AstroCallbacks.ConstraintType
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 numvars from the calc.
  • Element type T is 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])
source
AstroCallbacks.ConstraintMethod
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_bounds is not specified, defaults to fill(-Inf, n) where n is inferred from calc
  • If upper_bounds is not specified, defaults to fill(Inf, n) where n is inferred from calc
  • If scale is not specified, defaults to ones(T, n) where T is inferred from bounds
source
AstroCallbacks.DeltaVMagType
DeltaVMag <: AbstractManeuverVar

Tag 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
source
AstroCallbacks.EccType
Ecc <: AbstractOrbitVar

Tag 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.02

See also

  • TA, RAAN, SMA
  • subtypes(AbstractOrbitVar) for a full list of supported variables
source
AstroCallbacks.GravParamType
GravParam <: AbstractBodyVar

Tag 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
source
AstroCallbacks.IncType
Inc <: AbstractOrbitVar

Tag 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 degrees
source
AstroCallbacks.ManeuverCalcType
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)
source
AstroCallbacks.OrbitCalcType
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 CoordinateSystem origin 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])
source
AstroCallbacks.OrbitCalcMethod
OrbitCalc(sc::Spacecraft, var::V; dependency=nothing) where {V<:AbstractOrbitVar}

Outer constructor for OrbitCalc

source
AstroCallbacks.OutGoingRLAType
OutGoingRLA <: AbstractOrbitVar

Tag 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 degrees

See also

  • SMA, TA, RAAN
  • subtypes(AbstractOrbitVar) for a full list of supported variables
source
AstroCallbacks.PosDotVelType
PosDotVel <: AbstractOrbitVar

Tag 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])
source
AstroCallbacks.PosMagType
PosMag <: AbstractOrbitVar

Tag 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
source
AstroCallbacks.PosXType
PosX <: AbstractOrbitVar

Tag 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
source
AstroCallbacks.PosZType
PosZ <: AbstractOrbitVar

Tag 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)    
source
AstroCallbacks.PositionVectorType
PositionVector <: AbstractOrbitVar

Tag 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
source
AstroCallbacks.RAANType
RAAN <: AbstractOrbitVar

Tag 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 degrees

See also

  • SMA, TA, INC
  • subtypes(AbstractOrbitVar) for a full list of supported variables
source
AstroCallbacks.SMAType
SMA <: AbstractOrbitVar

Tag 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 km

See also

  • TA, RAAN, PositionVector
  • subtypes(AbstractOrbitVar) for a full list of supported variables
source
AstroCallbacks.TAType
TA <: AbstractOrbitVar

Tag 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 degrees

See also

  • SMA, RAAN, INC
  • subtypes(AbstractOrbitVar) for a full list of supported variables
source
AstroCallbacks.VelMagType
VelMagMag <: AbstractOrbitVar

Tag 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
source
AstroCallbacks.VelocityVectorType
VelocityVector <: AbstractOrbitVar

Tag 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
source
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.

source
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])

# output
source
AstroCallbacks._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.

source
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])
source
AstroCallbacks._state_for_calcMethod
function _state_for_calc(c::OrbitCalc)::AbstractOrbitState

Compute the state type required for the orbit calc variable. Performs conversion if needed.

source
AstroCallbacks._subjects_from_calcMethod
function _subjects_from_calc(c::AbstractCalc)

Extract the references used in a Calc instance. For example, an OrbitCalc will return the spacecraft it references.

source
AstroCallbacks.convert_orbitcalc_stateMethod
function convert_orbitcalc_state(st::AbstractOrbitState, cs::CoordinateSystem, 
                        target::AbstractOrbitStateType)::AbstractOrbitState

Convert AbstractOrbitState to state types and coordinates needed for OrbitCalc variable.

source
AstroCallbacks.convert_orbitcalc_stateMethod
function convert_orbitcalc_state(os::OrbitState, cs::CoordinateSystem, target::AbstractOrbitStateType)::AbstractOrbitState

Convert OrbitState to state types and coordinates needed for OrbitCalc variable.

source
AstroCallbacks.func_evalMethod
function func_eval(constraint::Constraint)

Evaluate the constraint's calc and return a Vector preserving eltype (AD-friendly)

source
AstroCallbacks.get_calcMethod
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)

source
AstroCallbacks.get_calcMethod
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.origin when 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)
source
AstroCallbacks.set_calc!Method
set_calc!(c::AbstractCalc, newval)

Set calc after checking if it is settable. (Generic dispatch to type-specific implementations.)

source
AstroCallbacks.to_concrete_stateMethod
function to_concrete_state(os::OrbitState)::AbstractState

Converts an OrbitState to its equivalent concrete AbstractState

Arguments

  • os::OrbitState: The OrbitState instance to convert.
source