From 2679ec270f0faa2926bdb462f551ee80490d51ce Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Wed, 8 Apr 2026 15:37:49 +0000 Subject: [PATCH] Consolidate rendezvous types into orbital_objects.h - Move RendezvousState and RendezvousTarget from rendezvous_types.h to orbital_objects.h - Remove rendezvous_types.h entirely - Simplify rendezvous.h to depend on orbital_objects.h - Delete spacecraft.h and spacecraft.cpp (consolidated into orbital_objects.h) - Update all include paths across codebase - All tests pass (4 pre-existing failures unchanged) --- Makefile | 1 - src/config_loader.h | 2 +- src/config_validator.h | 2 +- src/maneuver.cpp | 2 +- src/maneuver.h | 2 +- src/orbital_objects.h | 106 ++++++++++++++++++ src/renderer.h | 2 +- src/rendezvous.cpp | 81 ++++--------- src/rendezvous.h | 41 +++---- src/simulation.cpp | 2 +- src/simulation.h | 49 +------- src/spacecraft.cpp | 5 - src/spacecraft.h | 28 ----- src/ui_renderer.cpp | 2 +- tests/test_cartesian_to_elements_advanced.cpp | 2 +- tests/test_hybrid_burns.cpp | 2 +- tests/test_hybrid_energy_conservation.cpp | 2 +- tests/test_maneuver_planning.cpp | 2 +- tests/test_maneuvers.cpp | 2 +- tests/test_omega_debug.cpp | 2 +- tests/test_orbit_rendering.cpp | 2 +- tests/test_periapsis_burn.cpp | 2 +- tests/test_rendezvous.cpp | 36 +++--- 23 files changed, 183 insertions(+), 194 deletions(-) create mode 100644 src/orbital_objects.h delete mode 100644 src/spacecraft.cpp delete mode 100644 src/spacecraft.h diff --git a/Makefile b/Makefile index 249a1ba..e0d2ff0 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,6 @@ test-build: $(BUILD_DIR) $(C_OBJECTS) $(CPP_OBJECTS) $(TEST_OBJECTS) build/config_loader.o \ build/config_validator.o \ build/maneuver.o \ - build/spacecraft.o \ build/rendezvous.o \ -o $(TEST_TARGET) -lCatch2Main -lCatch2 -lm diff --git a/src/config_loader.h b/src/config_loader.h index a2e3bc5..8cb3fde 100644 --- a/src/config_loader.h +++ b/src/config_loader.h @@ -2,7 +2,7 @@ #define CONFIG_LOADER_H #include "simulation.h" -#include "spacecraft.h" +#include "orbital_objects.h" #include "../ext/tomlc17/src/tomlc17.h" #include "config_validator.h" diff --git a/src/config_validator.h b/src/config_validator.h index b38f889..a11aa13 100644 --- a/src/config_validator.h +++ b/src/config_validator.h @@ -2,7 +2,7 @@ #define CONFIG_VALIDATOR_H #include "simulation.h" -#include "spacecraft.h" +#include "orbital_objects.h" #define MIN_MASS_RATIO 1000.0 #define NESTED_ORBIT_FRACTION 5.0 diff --git a/src/maneuver.cpp b/src/maneuver.cpp index b6eb0d1..4109e72 100644 --- a/src/maneuver.cpp +++ b/src/maneuver.cpp @@ -1,6 +1,6 @@ #include "maneuver.h" #include "physics.h" -#include "spacecraft.h" +#include "orbital_objects.h" #include "simulation.h" #include "orbital_mechanics.h" #include diff --git a/src/maneuver.h b/src/maneuver.h index f092026..8334a07 100644 --- a/src/maneuver.h +++ b/src/maneuver.h @@ -2,7 +2,7 @@ #define MANEUVER_H #include "physics.h" -#include "spacecraft.h" +#include "orbital_objects.h" struct SimulationState; diff --git a/src/orbital_objects.h b/src/orbital_objects.h new file mode 100644 index 0000000..6e7222c --- /dev/null +++ b/src/orbital_objects.h @@ -0,0 +1,106 @@ +#ifndef ORBITAL_OBJECTS_H +#define ORBITAL_OBJECTS_H + +#include "physics.h" +#include "orbital_mechanics.h" + +// Forward declarations +struct SimulationState; + +// ============================================================================ +// Rendezvous Types +// ============================================================================ + +/** + * Rendezvous state machine + * + * States: + * - NONE: No rendezvous active + * - PLANNING: Target selected, approaching + * - APPROACHING: Closing in on target + * - MATCHING: Velocity matching phase + * - COMPLETE: Rendezvous successful + * - FAILED: Rendezvous failed + */ +typedef enum { + RENDEZVOUS_NONE, + RENDEZVOUS_PLANNING, + RENDEZVOUS_APPROACHING, + RENDEZVOUS_MATCHING, + RENDEZVOUS_COMPLETE, + RENDEZVOUS_FAILED +} RendezvousState; + +/** + * Rendezvous target structure + * + * Tracks the active rendezvous target and state for a spacecraft + */ +typedef struct { + int target_index; // Index of target spacecraft/body + int state; // RendezvousState + double approach_distance; // Distance to start approach phase (m) + double capture_distance; // Distance for capture (m) + double max_relative_velocity; // Max closing speed for capture (m/s) + double cw_linearization_time; // Last time CW equations were linearized (s) + bool is_spacecraft_target; // True if target is spacecraft, false if body +} RendezvousTarget; + +// ============================================================================ +// Celestial Body Structure + +/** + * Celestial Body Structure + * + * Represents a planet, star, moon, or other gravitational body + * in the simulation. Supports hierarchical orbital mechanics with + * parent-child relationships and sphere of influence calculations. + */ +struct CelestialBody { + char name[64]; + double mass; // kg + double radius; // meters + int parent_index; // index of gravitational parent (-1 for root body like Sun) + float color[3]; // RGB color for rendering + + // Orbital elements from config (Keplerian elements) + OrbitalElements orbit; + + // Global frame (from origin) + Vec3 global_position; // meters from origin + Vec3 global_velocity; // m/s + + // Local frame (relative to parent) + Vec3 local_position; // meters from parent + Vec3 local_velocity; // m/s relative to parent + + double soi_radius; // sphere of influence radius (meters) +}; + +/** + * Spacecraft Structure + * + * Represents a spacecraft or probe in the simulation. + * Supports orbital mechanics, maneuvers, and rendezvous operations. + */ +struct Spacecraft { + char name[64]; + double mass; + int parent_index; + + // Orbital elements from config + OrbitalElements orbit; + + // Global frame (from origin) + Vec3 global_position; + Vec3 global_velocity; + + // Local frame (relative to parent) + Vec3 local_position; + Vec3 local_velocity; + + // Rendezvous support + RendezvousTarget rendezvous_target; // Active rendezvous target (if any) +}; + +#endif // ORBITAL_OBJECTS_H diff --git a/src/renderer.h b/src/renderer.h index c925f60..22a2986 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -2,7 +2,7 @@ #define RENDERER_H #include "simulation.h" -#include "spacecraft.h" +#include "orbital_objects.h" #include "maneuver.h" #include "raylib.h" diff --git a/src/rendezvous.cpp b/src/rendezvous.cpp index 132b64a..bb8bf25 100644 --- a/src/rendezvous.cpp +++ b/src/rendezvous.cpp @@ -89,7 +89,7 @@ CWValidityResult check_cw_validity( Spacecraft* chaser, void* target, CelestialBody* parent, - SimulationState* sim + double current_time ) { CWValidityResult result = {0}; @@ -143,7 +143,7 @@ CWValidityResult check_cw_validity( bool spatial_ok = spatial_fraction < CW_SPATIAL_LIMIT_FRACTION; // Check time validity - double time_since_linearization = sim->time - chaser->rendezvous_target.cw_linearization_time; + double time_since_linearization = current_time - chaser->rendezvous_target.cw_linearization_time; double n_dt = n * time_since_linearization; bool time_ok = n_dt < CW_TIME_LIMIT_N_DT; @@ -170,7 +170,7 @@ CWGuidanceSolution solve_cw_guidance( void* target, CelestialBody* parent, double time_to_intercept, - SimulationState* sim + double current_time ) { CWGuidanceSolution solution = {0}; @@ -325,88 +325,58 @@ void initialize_rendezvous_target( target->is_spacecraft_target = is_spacecraft_target; } -void* get_rendezvous_target( - SimulationState* sim, - int target_index, - bool* is_spacecraft_target -) { - if (target_index < 0 || target_index >= sim->craft_count) { - *is_spacecraft_target = true; - return NULL; - } - - // Default to spacecraft - *is_spacecraft_target = true; - return &sim->spacecraft[target_index]; -} - void update_rendezvous_state( Spacecraft* chaser, - SimulationState* sim + RendezvousTarget* target, + CelestialBody* parent, + double current_time, + void* target_obj ) { - RendezvousTarget* target = &chaser->rendezvous_target; - if (target->state == RENDEZVOUS_NONE || target->state == RENDEZVOUS_COMPLETE || target->state == RENDEZVOUS_FAILED) { return; } - // Get target object - void* target_obj = get_rendezvous_target(sim, target->target_index, &target->is_spacecraft_target); - if (target_obj == NULL) { - target->state = RENDEZVOUS_FAILED; - return; - } - - // Get parent body (assumed same for both) - CelestialBody* parent = NULL; - if (chaser->parent_index >= 0 && chaser->parent_index < sim->body_count) { - parent = &sim->bodies[chaser->parent_index]; - } else { - target->state = RENDEZVOUS_FAILED; - return; - } - // Calculate current distance and relative velocity double distance = calculate_rendezvous_distance(chaser, target_obj); double rel_vel_mag = calculate_relative_velocity_magnitude(chaser, target_obj, parent); // Check CW validity - CWValidityResult validity = check_cw_validity(chaser, target_obj, parent, sim); + CWValidityResult validity = check_cw_validity(chaser, target_obj, parent, current_time); // State machine transitions - switch (chaser->rendezvous_target.state) { + switch (target->state) { case RENDEZVOUS_PLANNING: // Transition to APPROACHING when within approach distance - if (distance <= chaser->rendezvous_target.approach_distance && validity.overall_valid) { - chaser->rendezvous_target.cw_linearization_time = sim->time; - chaser->rendezvous_target.state = RENDEZVOUS_APPROACHING; + if (distance <= target->approach_distance && validity.overall_valid) { + target->cw_linearization_time = current_time; + target->state = RENDEZVOUS_APPROACHING; } break; case RENDEZVOUS_APPROACHING: // Transition to MATCHING when relative velocity is low - if (rel_vel_mag < chaser->rendezvous_target.max_relative_velocity * 0.5) { - chaser->rendezvous_target.state = RENDEZVOUS_MATCHING; + if (rel_vel_mag < target->max_relative_velocity * 0.5) { + target->state = RENDEZVOUS_MATCHING; } // Check if we've moved away (failed approach) - else if (distance > chaser->rendezvous_target.approach_distance * 1.5) { - chaser->rendezvous_target.state = RENDEZVOUS_FAILED; + else if (distance > target->approach_distance * 1.5) { + target->state = RENDEZVOUS_FAILED; } // Update CW linearization time periodically - else if (sim->time - chaser->rendezvous_target.cw_linearization_time > 100.0) { - chaser->rendezvous_target.cw_linearization_time = sim->time; + else if (current_time - target->cw_linearization_time > 100.0) { + target->cw_linearization_time = current_time; } break; case RENDEZVOUS_MATCHING: // Transition to COMPLETE when within capture distance - if (distance <= chaser->rendezvous_target.capture_distance && rel_vel_mag < chaser->rendezvous_target.max_relative_velocity) { - chaser->rendezvous_target.state = RENDEZVOUS_COMPLETE; + if (distance <= target->capture_distance && rel_vel_mag < target->max_relative_velocity) { + target->state = RENDEZVOUS_COMPLETE; } // Check if CW validity is lost else if (!validity.overall_valid) { - chaser->rendezvous_target.state = RENDEZVOUS_FAILED; + target->state = RENDEZVOUS_FAILED; } break; @@ -422,18 +392,13 @@ void update_rendezvous_state( void apply_cw_guidance_burn( Spacecraft* chaser, CWGuidanceSolution* solution, - SimulationState* sim + CelestialBody* parent, + double current_time ) { if (!solution->valid) { return; } - // Get parent body - if (chaser->parent_index < 0 || chaser->parent_index >= sim->body_count) { - return; - } - CelestialBody* parent = &sim->bodies[chaser->parent_index]; - // Compute LVLH basis Vec3 r_hat, v_hat, h_hat; cartesian_to_lvlh_basis(chaser->local_position, chaser->local_velocity, diff --git a/src/rendezvous.h b/src/rendezvous.h index 29fd8e5..639c623 100644 --- a/src/rendezvous.h +++ b/src/rendezvous.h @@ -1,8 +1,9 @@ #ifndef RENDEZVOUS_H #define RENDEZVOUS_H -#include "simulation.h" -#include "spacecraft.h" +#include "physics.h" +#include "orbital_mechanics.h" +#include "orbital_objects.h" /** * Rendezvous Module @@ -132,14 +133,14 @@ void lvlh_to_cartesian( * @param chaser Chaser spacecraft * @param target Target (body or spacecraft) * @param parent Central body - * @param sim Simulation state + * @param current_time Current simulation time * @return CWValidityResult with validity flags and error estimates */ CWValidityResult check_cw_validity( Spacecraft* chaser, void* target, // Can be Spacecraft* or CelestialBody* CelestialBody* parent, - SimulationState* sim + double current_time ); /** @@ -172,6 +173,7 @@ double compute_mean_motion( * @param target Target * @param parent Central body * @param time_to_intercept Desired time to intercept + * @param current_time Current simulation time * @return CWGuidanceSolution with required delta-v */ CWGuidanceSolution solve_cw_guidance( @@ -179,7 +181,7 @@ CWGuidanceSolution solve_cw_guidance( void* target, CelestialBody* parent, double time_to_intercept, - SimulationState* sim + double current_time ); /** @@ -221,20 +223,6 @@ void initialize_rendezvous_target( double max_relative_velocity ); -/** - * Get target object (spacecraft or body) from index - * - * @param sim Simulation state - * @param target_index Index of target - * @param is_spacecraft_target Output: whether target is spacecraft - * @return Pointer to target (Spacecraft* or CelestialBody*) - */ -void* get_rendezvous_target( - SimulationState* sim, - int target_index, - bool* is_spacecraft_target -); - /** * Update rendezvous state machine based on current relative state * @@ -246,11 +234,16 @@ void* get_rendezvous_target( * * @param chaser Chaser spacecraft * @param target Rendezvous target - * @param sim Simulation state + * @param parent Central body + * @param current_time Current simulation time + * @param target_obj Target object (Spacecraft* or CelestialBody*) */ void update_rendezvous_state( Spacecraft* chaser, - SimulationState* sim + RendezvousTarget* target, + CelestialBody* parent, + double current_time, + void* target_obj // Can be Spacecraft* or CelestialBody* ); // ============================================================================ @@ -262,12 +255,14 @@ void update_rendezvous_state( * * @param chaser Chaser spacecraft * @param solution CW guidance solution - * @param sim Simulation state + * @param parent Central body + * @param current_time Current simulation time */ void apply_cw_guidance_burn( Spacecraft* chaser, CWGuidanceSolution* solution, - SimulationState* sim + CelestialBody* parent, + double current_time ); /** diff --git a/src/simulation.cpp b/src/simulation.cpp index 3f9bde6..9258776 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -1,5 +1,5 @@ #include "simulation.h" -#include "spacecraft.h" +#include "orbital_objects.h" #include "maneuver.h" #include "orbital_mechanics.h" #include diff --git a/src/simulation.h b/src/simulation.h index 67821f6..d3af6c0 100644 --- a/src/simulation.h +++ b/src/simulation.h @@ -1,56 +1,13 @@ #ifndef BODIES_H #define BODIES_H -#include "physics.h" -#include "orbital_mechanics.h" +#include "orbital_objects.h" +#include "maneuver.h" // Forward declarations -struct Spacecraft; +struct SimulationState; struct Maneuver; -// Rendezvous state machine (needed by Spacecraft) -typedef enum { - RENDEZVOUS_NONE, - RENDEZVOUS_PLANNING, - RENDEZVOUS_APPROACHING, - RENDEZVOUS_MATCHING, - RENDEZVOUS_COMPLETE, - RENDEZVOUS_FAILED -} RendezvousState; - -// Rendezvous target structure -typedef struct { - int target_index; - int state; - double approach_distance; - double capture_distance; - double max_relative_velocity; - double cw_linearization_time; - bool is_spacecraft_target; -} RendezvousTarget; - -// Celestial body structure -struct CelestialBody { - char name[64]; - double mass; // kg - double radius; // meters - int parent_index; // index of gravitational parent (-1 for root body like Sun) - float color[3]; // RGB color for rendering - - // Orbital elements from config (Keplerian elements) - OrbitalElements orbit; - - // Global frame (from origin) - Vec3 global_position; // meters from origin - Vec3 global_velocity; // m/s - - // Local frame (relative to parent) - Vec3 local_position; // meters from parent - Vec3 local_velocity; // m/s relative to parent - - double soi_radius; // sphere of influence radius (meters) -}; - // Simulation state struct SimulationState { CelestialBody* bodies; diff --git a/src/spacecraft.cpp b/src/spacecraft.cpp deleted file mode 100644 index c535a4c..0000000 --- a/src/spacecraft.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "spacecraft.h" -#include "simulation.h" -#include -#include -#include diff --git a/src/spacecraft.h b/src/spacecraft.h deleted file mode 100644 index 4bb58e9..0000000 --- a/src/spacecraft.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SPACECRAFT_H -#define SPACECRAFT_H - -#include "physics.h" -#include "orbital_mechanics.h" -#include "simulation.h" - -struct Spacecraft { - char name[64]; - double mass; - int parent_index; - - // Orbital elements from config - OrbitalElements orbit; - - // Global frame (from origin) - Vec3 global_position; - Vec3 global_velocity; - - // Local frame (relative to parent) - Vec3 local_position; - Vec3 local_velocity; - - // Rendezvous support - RendezvousTarget rendezvous_target; // Active rendezvous target (if any) -}; - -#endif diff --git a/src/ui_renderer.cpp b/src/ui_renderer.cpp index ce10fd0..cebaebc 100644 --- a/src/ui_renderer.cpp +++ b/src/ui_renderer.cpp @@ -1,5 +1,5 @@ #include "ui_renderer.h" -#include "spacecraft.h" +#include "orbital_objects.h" #include "maneuver.h" #include #include diff --git a/tests/test_cartesian_to_elements_advanced.cpp b/tests/test_cartesian_to_elements_advanced.cpp index 90a4813..7338c4f 100644 --- a/tests/test_cartesian_to_elements_advanced.cpp +++ b/tests/test_cartesian_to_elements_advanced.cpp @@ -2,7 +2,7 @@ #include #include #include "../src/orbital_mechanics.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/test_utilities.h" #include "../src/config_loader.h" #include "../src/simulation.h" diff --git a/tests/test_hybrid_burns.cpp b/tests/test_hybrid_burns.cpp index 22947a3..ab7a89a 100644 --- a/tests/test_hybrid_burns.cpp +++ b/tests/test_hybrid_burns.cpp @@ -3,7 +3,7 @@ #include "../src/physics.h" #include "../src/orbital_mechanics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include "../src/test_utilities.h" diff --git a/tests/test_hybrid_energy_conservation.cpp b/tests/test_hybrid_energy_conservation.cpp index ca3e37b..2a5b889 100644 --- a/tests/test_hybrid_energy_conservation.cpp +++ b/tests/test_hybrid_energy_conservation.cpp @@ -3,7 +3,7 @@ #include "../src/physics.h" #include "../src/orbital_mechanics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include diff --git a/tests/test_maneuver_planning.cpp b/tests/test_maneuver_planning.cpp index 2c08cdd..03bb41a 100644 --- a/tests/test_maneuver_planning.cpp +++ b/tests/test_maneuver_planning.cpp @@ -1,7 +1,7 @@ #include #include "../src/physics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include diff --git a/tests/test_maneuvers.cpp b/tests/test_maneuvers.cpp index 1dda1d9..6e32add 100644 --- a/tests/test_maneuvers.cpp +++ b/tests/test_maneuvers.cpp @@ -1,7 +1,7 @@ #include #include "../src/physics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include "../src/test_utilities.h" diff --git a/tests/test_omega_debug.cpp b/tests/test_omega_debug.cpp index ae2df62..2a5e200 100644 --- a/tests/test_omega_debug.cpp +++ b/tests/test_omega_debug.cpp @@ -2,7 +2,7 @@ #include #include "../src/physics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include "../src/orbital_mechanics.h" diff --git a/tests/test_orbit_rendering.cpp b/tests/test_orbit_rendering.cpp index c74f997..2c75d6a 100644 --- a/tests/test_orbit_rendering.cpp +++ b/tests/test_orbit_rendering.cpp @@ -1,7 +1,7 @@ #include #include "../src/physics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/config_loader.h" #include diff --git a/tests/test_periapsis_burn.cpp b/tests/test_periapsis_burn.cpp index 9c4dc4e..9b50f6c 100644 --- a/tests/test_periapsis_burn.cpp +++ b/tests/test_periapsis_burn.cpp @@ -2,7 +2,7 @@ #include #include "../src/physics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/maneuver.h" #include "../src/config_loader.h" #include "../src/orbital_mechanics.h" diff --git a/tests/test_rendezvous.cpp b/tests/test_rendezvous.cpp index d76258f..728a35b 100644 --- a/tests/test_rendezvous.cpp +++ b/tests/test_rendezvous.cpp @@ -3,7 +3,7 @@ #include "../src/physics.h" #include "../src/orbital_mechanics.h" #include "../src/simulation.h" -#include "../src/spacecraft.h" +#include "../src/orbital_objects.h" #include "../src/rendezvous.h" #include "../src/config_loader.h" #include @@ -121,7 +121,7 @@ SCENARIO("CW validity check for close spacecraft", "[rendezvous][cw][validity]") SECTION("Valid when within 5% of orbital radius") { // Initial separation is small (different semi-major axes) - CWValidityResult validity = check_cw_validity(chaser, target, earth, sim); + CWValidityResult validity = check_cw_validity(chaser, target, earth, sim->time); INFO("Spatial fraction: " << validity.spatial_fraction); INFO("n*dt: " << validity.n_dt); @@ -136,7 +136,7 @@ SCENARIO("CW validity check for close spacecraft", "[rendezvous][cw][validity]") double old_time = sim->time - 2000.0; // 2000 seconds ago chaser->rendezvous_target.cw_linearization_time = old_time; - CWValidityResult validity = check_cw_validity(chaser, target, earth, sim); + CWValidityResult validity = check_cw_validity(chaser, target, earth, sim->time); INFO("Time since linearization: " << (sim->time - chaser->rendezvous_target.cw_linearization_time)); INFO("n*dt: " << validity.n_dt); @@ -180,7 +180,7 @@ SCENARIO("CW guidance calculation for rendezvous", "[rendezvous][cw][guidance]") double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); double intercept_time = orbital_period; // 1 orbit - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, intercept_time, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, intercept_time, sim->time); INFO("Intercept time: " << intercept_time << " s"); INFO("Solution valid: " << solution.valid); @@ -197,7 +197,7 @@ SCENARIO("CW guidance calculation for rendezvous", "[rendezvous][cw][guidance]") double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); double intercept_time = orbital_period / 2.0; // Half orbit - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, intercept_time, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, intercept_time, sim->time); INFO("Intercept time: " << intercept_time << " s"); INFO("Delta-v magnitude: " << solution.delta_v_magnitude << " m/s"); @@ -268,11 +268,11 @@ SCENARIO("Rendezvous execution with CW guidance", "[rendezvous][execution]") { // Calculate and execute CW guidance burn double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim->time); INFO("Calculated delta-v: " << solution.delta_v_magnitude << " m/s"); - apply_cw_guidance_burn(chaser, &solution, sim); + apply_cw_guidance_burn(chaser, &solution, earth, sim->time); // Propagate for one orbital period double propagation_time = orbital_period; @@ -307,8 +307,8 @@ SCENARIO("Rendezvous execution with CW guidance", "[rendezvous][execution]") { // Execute burn to get into approach phase double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim); - apply_cw_guidance_burn(chaser, &solution, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim->time); + apply_cw_guidance_burn(chaser, &solution, earth, sim->time); // Propagate for half an orbit int num_steps = (int)(orbital_period / 2.0 / TIME_STEP); @@ -319,7 +319,7 @@ SCENARIO("Rendezvous execution with CW guidance", "[rendezvous][execution]") { } // Update state machine - update_rendezvous_state(chaser, sim); + update_rendezvous_state(chaser, &chaser->rendezvous_target, earth, sim->time, target); INFO("Final rendezvous state: " << sim->spacecraft[1].rendezvous_target.state); @@ -369,8 +369,8 @@ SCENARIO("Rendezvous with different initial separations", "[rendezvous][separati // Execute rendezvous double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim); - apply_cw_guidance_burn(chaser, &solution, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim->time); + apply_cw_guidance_burn(chaser, &solution, earth, sim->time); // Propagate int num_steps = (int)(orbital_period / TIME_STEP); @@ -406,15 +406,15 @@ SCENARIO("Rendezvous with different initial separations", "[rendezvous][separati REQUIRE(initial_distance < 20000.0); // Should be ~10 km // Check CW validity (should still be valid at 10 km) - CWValidityResult validity = check_cw_validity(chaser, target, earth, sim); + CWValidityResult validity = check_cw_validity(chaser, target, earth, sim->time); INFO("Spatial fraction: " << validity.spatial_fraction); REQUIRE(validity.overall_valid == true); // Execute rendezvous double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim); - apply_cw_guidance_burn(chaser, &solution, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim->time); + apply_cw_guidance_burn(chaser, &solution, earth, sim->time); // Propagate int num_steps = (int)(orbital_period / TIME_STEP); @@ -454,8 +454,8 @@ SCENARIO("Rendezvous with CW linearization updates", "[rendezvous][linearization // Execute burn double orbital_period = 2.0 * M_PI * sqrt(pow(6.771e6, 3) / (G * earth->mass)); - CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim); - apply_cw_guidance_burn(chaser, &solution, sim); + CWGuidanceSolution solution = solve_cw_guidance(chaser, target, earth, orbital_period, sim->time); + apply_cw_guidance_burn(chaser, &solution, earth, sim->time); // Propagate for 2 orbits with periodic linearization updates int num_steps = (int)(2.0 * orbital_period / TIME_STEP); @@ -490,7 +490,7 @@ SCENARIO("Rendezvous with CW linearization updates", "[rendezvous][linearization // Artificially delay linearization chaser->rendezvous_target.cw_linearization_time = sim->time - 3000.0; // 3000 seconds ago - CWValidityResult validity = check_cw_validity(chaser, target, earth, sim); + CWValidityResult validity = check_cw_validity(chaser, target, earth, sim->time); INFO("n*dt: " << validity.n_dt); INFO("Overall valid: " << validity.overall_valid);