A MoonBit orbital mechanics and spacecraft mission computation library.
moon check --deny-warn
moon test --deny-warn
moon run cmd/main///|
test {
let leo = circular_orbit(earth_radius_km + 500.0, radians(51.6))
let summary = summarize_orbit(earth_mu_km3_s2, leo)
assert_true(summary.period_s > 5600.0 && summary.period_s < 5700.0)
let transfer = hohmann_transfer(
earth_mu_km3_s2,
earth_radius_km + 500.0,
42164.0,
)
assert_true(transfer.delta_v_total_km_s > 3.7)
}kepler-solver: iterations=256,checksum=40.71431462450973
state-conversion: iterations=256,checksum=1783729.8704907342
wgs84-conversion: iterations=256,checksum=1631037.754922193fn AccelerationModel::with_drag(model : AccelerationModel, coefficient : Double, scale_height_km : Double) -> AccelerationModelpub struct AttitudeState {
attitude : Quaternion
angular_velocity_rad_s : Vec3
covariance_trace : Double
} derive(Eq, Debug)pub struct CatalogEntry {
id : String
name : String
elements : ClassicalElements
epoch_day : Double
active : Bool
} derive(Eq, Debug)fn CatalogEntry::new(id : String, name : String, elements : ClassicalElements, epoch_day : Double, active? : Bool) -> CatalogEntryfn ClassicalElements::new(semi_major_axis_km : Double, eccentricity : Double, inclination_rad : Double, raan_rad : Double, arg_periapsis_rad : Double, true_anomaly_rad : Double) -> ClassicalElementspub struct DesignCandidate {
elements : ClassicalElements
score : Double
feasible : Bool
violations : Array[String]
} derive(Eq, Debug)pub struct DynamicsState {
state : StateVector
acceleration_km_s2 : Vec3
elapsed_s : Double
} derive(Eq, Debug)pub struct EclipseResult {
kind : EclipseKind
occultation_fraction : Double
sun_angle_rad : Double
earth_angle_rad : Double
duration_estimate_s : Double
} derive(Eq, Debug)fn GroundStation::new(name : String, latitude_rad : Double, longitude_rad : Double, altitude_km? : Double, min_elevation_rad? : Double) -> GroundStationpub struct GroundTrackSegment {
points : Array[GroundTrackPoint]
start_time_s : Double
end_time_s : Double
path_length_km : Double
} derive(Eq, Debug)pub struct LambertSolution {
departure_velocity_km_s : Vec3
arrival_velocity_km_s : Vec3
transfer_angle_rad : Double
time_of_flight_s : Double
iterations : Int
status : SolveStatus
} derive(Eq, Debug)pub struct MissionEvent {
time_s : Double
kind : MissionEventKind
label : String
delta_v_km_s : Double
duration_s : Double
} derive(Eq, Debug)fn MissionEvent::new(time_s : Double, kind : MissionEventKind, label : String, delta_v_km_s? : Double, duration_s? : Double) -> MissionEventpub struct MissionScenario {
name : String
phases : Array[MissionPhase]
reserve_km_s : Double
} derive(Eq, Debug)fn MissionScenario::with_reserve(scenario : MissionScenario, reserve_km_s : Double) -> MissionScenariofn MissionTimeline::events_in_range(timeline : MissionTimeline, start_s : Double, end_s : Double) -> Array[MissionEvent]pub struct Observation {
epoch : Epoch
station : GroundStation
kind : ObservationKind
value : Double
predicted : Double
sigma : Double
quality : ObservationQuality
} derive(Eq, Debug)fn Observation::new(epoch : Epoch, station : GroundStation, kind : ObservationKind, value : Double, sigma : Double) -> Observationfn Observation::with_quality(observation : Observation, quality : ObservationQuality) -> Observationfn ObservationBatch::by_kind(batch : ObservationBatch, kind : ObservationKind) -> Array[Observation]pub struct OperationPlan {
name : String
steps : Array[OperationStep]
total_duration_s : Double
total_resource_cost : Double
} derive(Eq, Debug)pub struct OperationStep {
index : Int
name : String
mode : OperationMode
duration_s : Double
resource_cost : Double
completed : Bool
} derive(Eq, Debug)fn OperationStep::new(index : Int, name : String, mode : OperationMode, duration_s : Double, resource_cost : Double) -> OperationSteppub struct OrbitAnalysis {
elements : ClassicalElements
state : StateVector
altitude_km : Double
speed_km_s : Double
radial_speed_km_s : Double
flight_path_angle_rad : Double
energy_km2_s2 : Double
angular_momentum_km2_s : Double
} derive(Eq, Debug)pub struct PlannedWindow {
window : VisibilityWindow
score : Double
data_volume_mb : Double
selected : Bool
} derive(Eq, Debug)pub struct RootResult {
value : Double
residual : Double
iterations : Int
status : SolveStatus
} derive(Eq, Debug)pub struct ScalarEstimate {
value : Double
variance : Double
residual_rms : Double
used : Int
status : EstimateStatus
} derive(Eq, Debug)pub struct TelemetrySample {
time_s : Double
name : String
value : Double
unit : String
quality : TelemetryQuality
} derive(Eq, Debug)fn TelemetrySample::new(time_s : Double, name : String, value : Double, unit : String) -> TelemetrySamplefn TelemetrySample::with_quality(sample : TelemetrySample, quality : TelemetryQuality) -> TelemetrySamplepub struct TleRecord {
name : String
satellite_number : Int
classification : Char
epoch_year : Int
epoch_day : Double
inclination_rad : Double
raan_rad : Double
eccentricity : Double
arg_periapsis_rad : Double
mean_anomaly_rad : Double
mean_motion_rev_day : Double
revolution_number : Int
} derive(Eq, Debug)pub struct TrendEstimate {
intercept : Double
slope_per_s : Double
variance : Double
residual_rms : Double
used : Int
status : EstimateStatus
} derive(Eq, Debug)pub struct ValidationMessage {
level : ValidationLevel
code : String
message : String
} derive(Eq, Debug)fn ValidationMessage::new(level : ValidationLevel, code : String, message : String) -> ValidationMessagepub struct ValidationReport {
valid : Bool
messages : Array[ValidationMessage]
score : Double
} derive(Eq, Debug)fn WindowConstraint::new(minimum_elevation_rad : Double, maximum_range_km : Double, minimum_duration_s : Double) -> WindowConstraintfn WindowConstraint::with_score(constraint : WindowConstraint, required_score : Double) -> WindowConstraintpub struct WindowSchedule {
windows : Array[PlannedWindow]
total_duration_s : Double
total_volume_mb : Double
mean_score : Double
} derive(Eq, Debug)fn altitude_is_valid(elements : ClassicalElements, minimum_km : Double, maximum_km : Double) -> Boolfn antenna_link_margin_db(tx_power_dbw : Double, gains_db : Double, path_loss_db : Double, system_loss_db : Double, required_db : Double) -> Doublefn ballistic_coefficient(mass_kg : Double, area_m2 : Double, drag_coefficient : Double) -> Doublefn battery_energy_wh(power_w : Double, eclipse_fraction : Double, orbit_period_s : Double) -> Doublefn bi_elliptic_transfer_delta_v(mu : Double, radius_initial_km : Double, radius_final_km : Double, radius_intermediate_km : Double) -> Doublefn bisect(f : (Double) -> Double, lower : Double, upper : Double, tolerance? : Double, max_iterations? : Int) -> RootResultfn circularize_cost(mu : Double, radius_km : Double, eccentricity : Double) -> Doublefn collision_probability_proxy(distance_km : Double, covariance_radius_km : Double) -> Doublefn combined_plane_change(speed_before_km_s : Double, speed_after_km_s : Double, angle_rad : Double) -> Doublefn combined_plane_change_delta_v(before_speed : Double, after_speed : Double, angle_rad : Double) -> Doublefn compare_state_samples(expected : Array[StateSample], actual : Array[StateSample]) -> StateComparisonfn conjunction_screen(reference : StateVector, objects : Array[StateVector], threshold_km : Double) -> Array[SafetyAssessment]fn contact_data_volume_mb(rate_kbps : Double, duration_s : Double) -> Doublefn contingency_step(index : Int, name : String, duration_s : Double, resource_cost : Double) -> OperationStepfn control_command(attitude : Quaternion, target : PointingTarget, body_axis : Vec3, max_rate_rad_s : Double) -> ControlCommandfn coverage_cells_for_track(track : Array[GroundTrackPoint], latitude_step_rad : Double, longitude_step_rad : Double) -> Intfn coverage_report(station : GroundStation, points : Array[GroundTrackPoint], epoch : Epoch, elements : ClassicalElements, min_elevation_rad : Double) -> CoverageReportfn cylindrical_eclipse(satellite_position : Vec3, sun_direction : Vec3, earth_radius_km : Double) -> EclipseResultfn denormalize_parameter(value : Double, lower : Double, upper : Double) -> Doublefn detect_step_changes(samples : Array[TelemetrySample], threshold : Double) -> Array[TelemetrySample]fn doppler_corrected_frequency(carrier_hz : Double, radial_speed_km_s : Double) -> Doublefn doppler_shift_hz(carrier_hz : Double, radial_speed_km_s : Double) -> Doublefn eccentric_anomaly_from_true(true_anomaly_rad : Double, eccentricity : Double) -> Doublefn eclipse_geometry(satellite_to_sun : Vec3, satellite_to_earth : Vec3, earth_radius_km : Double, sun_radius_km : Double) -> EclipseResultfn effective_data_rate(rate_kbps : Double, packet_error : Double) -> Doublefn estimate_eclipse_duration(orbit_radius_km : Double, earth_radius_km : Double, orbital_speed_km_s : Double) -> Doublefn estimate_orbit_pass(station : GroundStation, elements : ClassicalElements, start_epoch : Epoch, duration_s : Double, step_s : Double, min_elevation_rad : Double) -> Array[PassWindow]fn evaluate_design(mu : Double, elements : ClassicalElements, constraint : DesignConstraint) -> DesignCandidatefn evaluate_launch_window(latitude_rad : Double, target_inclination_rad : Double, epoch_day : Double, duration_s : Double) -> LaunchWindowfn exponential_density_kg_m3(altitude_km : Double, scale_height_km : Double) -> Doublefn filter_windows_by_time(windows : Array[VisibilityWindow], start : Epoch, end : Epoch) -> Array[VisibilityWindow]fn find_bracket(f : (Double) -> Double, start : Double, end : Double, samples? : Int) -> (Double, Double)?fn free_space_path_loss_db(distance_km : Double, frequency_ghz : Double) -> Doublefn gradient_descent(objective : (Array[Double]) -> Double, initial : Array[Double], learning_rate : Double, iterations : Int) -> OptimizationResultfn grid_search_1d(objective : (Double) -> Double, lower : Double, upper : Double, samples : Int) -> (Double, Double)fn ground_track(mu : Double, elements : ClassicalElements, epoch : Epoch, duration_s : Double, step_s : Double) -> Array[GroundTrackPoint]fn health_flags(values : Array[(String, Double)], lower : Double, upper : Double) -> Array[HealthFlag]fn hohmann_like_lambert(mu : Double, start : Vec3, end : Vec3, time_of_flight_s : Double) -> LambertSolutionfn hohmann_transfer(mu : Double, radius_initial_km : Double, radius_final_km : Double) -> HohmannTransferfn inclination_change_cost(mu : Double, radius_km : Double, from_rad : Double, to_rad : Double) -> Doublefn inclination_is_valid(elements : ClassicalElements, minimum_rad : Double, maximum_rad : Double) -> Boolfn integrate_dynamics(model : AccelerationModel, initial : StateVector, duration_s : Double, step_s : Double) -> Array[DynamicsState]fn is_close(actual : Double, expected : Double, absolute? : Double, relative? : Double) -> Boolfn j2_secular_rates(mu : Double, radius_body_km : Double, j2_value : Double, elements : ClassicalElements) -> J2Ratesfn kilometers_per_second_to_meters_per_second(value : Double) -> Doublefn lambert_delta_v(solution : LambertSolution, initial_velocity : Vec3, final_velocity : Vec3) -> (Double, Double, Double)fn lambert_universal(mu : Double, start : Vec3, end : Vec3, time_of_flight_s : Double, prograde? : Bool, max_iterations? : Int) -> LambertSolutionfn launch_window_sequence(start_day : Double, count : Int, spacing_s : Double, latitude_rad : Double, inclination_rad : Double) -> Array[LaunchWindow]fn lifetime_margin_days(lifetime_days : Double, planned_days : Double) -> Doublefn link_budget(frequency_ghz : Double, distance_km : Double, tx_power_dbw : Double, antenna_gain_db : Double, losses_db : Double, required_db : Double) -> LinkBudgetfn local_gravity_m_s2(latitude_rad : Double, altitude_km : Double) -> Doublefn make_pointing_target(direction : Vec3, roll_rad : Double, tolerance_rad : Double) -> PointingTargetfn make_visibility_window(start : Epoch, end : Epoch, max_elevation_rad : Double, closest_range_km : Double) -> VisibilityWindowfn mean_anomaly_from_eccentric(eccentric_anomaly_rad : Double, eccentricity : Double) -> Doublefn mean_motion_rev_day_to_rad_s(mean_motion_rev_day : Double) -> Doublefn merge_adjacent_windows(windows : Array[VisibilityWindow], maximum_gap_s : Double) -> Array[VisibilityWindow]fn meters_per_second_to_kilometers_per_second(value : Double) -> Doublefn mission_phase(name : String, start_s : Double, end_s : Double, delta_v_km_s : Double) -> MissionPhasefn newton(f : (Double) -> Double, derivative : (Double) -> Double, initial : Double, tolerance? : Double, max_iterations? : Int) -> RootResultfn noise_from_density(density_w_hz : Double, bandwidth_hz : Double) -> Doublefn nominal_step(index : Int, name : String, duration_s : Double, resource_cost : Double) -> OperationStepfn normalize_parameter(value : Double, lower : Double, upper : Double) -> Doublefn objective_orbit_altitude(mu : Double, elements : ClassicalElements, target_altitude_km : Double) -> Doublefn observation_prediction(station : GroundStation, epoch : Epoch, state : StateVector, kind : ObservationKind) -> Doublefn observation_residual_summary(observations : Array[Observation], gate_sigma : Double) -> ResidualSummaryfn observe_state(station : GroundStation, epoch : Epoch, state : StateVector, kind : ObservationKind, bias? : Double, sigma? : Double) -> Observationfn phasing_delta_v(mu : Double, radius_km : Double, phase_angle_rad : Double, cycles : Int) -> Doublefn plan_windows(windows : Array[VisibilityWindow], constraint : WindowConstraint, rate_kbps : Double) -> WindowSchedulefn plane_change_delta_v(speed_km_s : Double, angle_rad : Double) -> Doublefn propagate_j2_mean_elements(mu : Double, radius_body_km : Double, j2_value : Double, elements : ClassicalElements, delta_t_s : Double) -> ClassicalElementsfn propagate_kepler(mu : Double, elements : ClassicalElements, delta_t_s : Double) -> ClassicalElementsfn propagate_state_samples(mu : Double, elements : ClassicalElements, times_s : Array[Double]) -> Array[StateSample]fn propellant_mass_from_delta_v(initial_mass_kg : Double, delta_v_km_s : Double, exhaust_velocity_km_s : Double) -> Doublefn rad_per_second_to_revolutions_per_day(value : Double) -> Doublefn refine_pass_peak(station : GroundStation, elements : ClassicalElements, epoch : Epoch, start_s : Double, end_s : Double, step_s : Double) -> Doublefn repeat_ground_track_period(mu : Double, semi_major_axis_km : Double, earth_rotation_s : Double, revolutions : Int) -> Doublefn resample_ground_track(track : Array[GroundTrackPoint], times : Array[Double]) -> Array[GroundTrackPoint]fn resample_linear(samples : Array[TelemetrySample], times : Array[Double]) -> Array[TelemetrySample]fn resource_profile(mass_kg : Double, dry_mass_fraction : Double, power_w : Double, data_rate_kbps : Double, lifetime_days : Double) -> ResourceProfilefn revolutions_per_day_to_rad_per_second(value : Double) -> Doublefn reynolds_number(density : Double, speed : Double, length : Double, viscosity : Double) -> Doublefn risk_weighted_cost(cost : Double, probability : Double, consequence : Double) -> Doublefn rocket_delta_v(initial_mass_kg : Double, final_mass_kg : Double, exhaust_velocity_km_s : Double) -> Doublefn sample_kepler_visibility(mu : Double, station : GroundStation, start : Epoch, elements : ClassicalElements, step_s : Double, count : Int) -> Array[VisibilitySample]fn sample_visibility(station : GroundStation, epoch : Epoch, satellite_eci_km : Vec3) -> VisibilitySamplefn schedule_filter_kind(events : Array[MissionEvent], kind : MissionEventKind) -> Array[MissionEvent]fn schedule_to_mission_timeline(schedule : WindowSchedule, label_prefix : String) -> MissionTimelinefn schedule_window(window : VisibilityWindow, constraint : WindowConstraint, rate_kbps : Double) -> PlannedWindowfn score_mission(safety : Double, coverage : Double, cost : Double, science : Double, weights : Array[Double]) -> MissionScorefn segment_ground_track(track : Array[GroundTrackPoint], maximum_gap_s : Double) -> Array[GroundTrackSegment]fn semi_major_axis_from_mean_motion(mu : Double, mean_motion_rev_day : Double) -> Doublefn slew_time(angle_rad : Double, max_rate_rad_s : Double, max_accel_rad_s2 : Double) -> Doublefn solar_array_area_m2(power_w : Double, efficiency : Double, flux_w_m2 : Double) -> Doublefn solar_escape_margin(mu : Double, radius_km : Double, speed_km_s : Double) -> Doublefn solve_kepler(mean_anomaly_rad : Double, eccentricity : Double, tolerance? : Double, max_iterations? : Int) -> Doublefn specific_orbital_energy(mu : Double, semi_major_axis_km : Double) -> Doublefn square_kilometers_to_square_meters(value : Double) -> Doublefn square_meters_to_square_kilometers(value : Double) -> Doublefn state_comparison_is_valid(comparison : StateComparison, position_tolerance_km : Double, velocity_tolerance_km_s : Double) -> Boolfn sun_synchronous_inclination(mu : Double, radius_body_km : Double, j2_value : Double, semi_major_axis_km : Double, eccentricity : Double, desired_raan_rate_rad_s : Double) -> Doublefn thermal_noise_power(temperature_k : Double, bandwidth_hz : Double) -> Doublefn thermal_power_margin(power_budget_w : Double, power_load_w : Double) -> Doublefn track_filter_altitude(track : Array[GroundTrackPoint], minimum_km : Double, maximum_km : Double) -> Array[GroundTrackPoint]fn track_filter_time(track : Array[GroundTrackPoint], start_s : Double, end_s : Double) -> Array[GroundTrackPoint]fn transfer_time_estimate(mu : Double, first_radius_km : Double, second_radius_km : Double) -> Doublefn true_anomaly_from_eccentric(eccentric_anomaly_rad : Double, eccentricity : Double) -> Doublefn vis_viva_speed(mu : Double, radius_km : Double, semi_major_axis_km : Double) -> Doublefn vis_viva_velocity(mu : Double, radius_km : Double, semi_major_axis_km : Double) -> DoubleInstall
Download zipA MoonBit orbital mechanics and spacecraft mission computation library.