Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions src/md/opti/raphson_finite_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl<const V: usize, const O: usize> Targeter<'_, V, O> {

let mut finite_burn_target = false;

// Apply the initial guess
// Apply the initial guess: first accumulate, then apply once (matching
// the pattern used in the iteration loop at lines ~608-729).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the pattern used in the iteration loop at lines ~608-729).
// the pattern used in the iteration loop).

I prefer not referring specific line numbers in comments.

for (i, var) in self.variables.iter().enumerate() {
// Check the validity (this function will report to log and raise an error)
var.valid()?;
Expand Down Expand Up @@ -171,27 +172,29 @@ impl<const V: usize, const O: usize> Targeter<'_, V, O> {
info!("Initial maneuver guess: {mnvr}");
} else {
state_correction[var.component.vec_index()] += var.init_guess;
// Now, let's apply the correction to the initial state
if let Some(frame) = self.correction_frame {
// The following will error if the frame is not local
let dcm_vnc2inertial = frame
.dcm_to_inertial(xi.orbit)
.context(AstroPhysicsSnafu)
.context(AstroSnafu)?
.rot_mat;

let velocity_correction =
dcm_vnc2inertial * state_correction.fixed_rows::<3>(3);
xi.orbit.apply_dv_km_s(velocity_correction);
Comment thread
ChristopherRabotin marked this conversation as resolved.
} else {
xi.orbit.radius_km += state_correction.fixed_rows::<3>(0).to_owned();
xi.orbit.velocity_km_s += state_correction.fixed_rows::<3>(3).to_owned();
}
}

total_correction[i] += var.init_guess;
}

// Apply the accumulated initial guess to xi (once, after the loop)
if !finite_burn_target {
if let Some(frame) = self.correction_frame {
let dcm_vnc2inertial = frame
.dcm_to_inertial(xi.orbit)
.context(AstroPhysicsSnafu)
.context(AstroSnafu)?
.rot_mat;

let velocity_correction =
dcm_vnc2inertial * state_correction.fixed_rows::<3>(3);
xi.orbit.apply_dv_km_s(velocity_correction);
} else {
xi.orbit.radius_km += state_correction.fixed_rows::<3>(0).to_owned();
xi.orbit.velocity_km_s += state_correction.fixed_rows::<3>(3).to_owned();
}
}
Comment thread
ChristopherRabotin marked this conversation as resolved.

let mut prev_err_norm = f64::INFINITY;

// Determine padding in debugging info
Expand Down Expand Up @@ -545,8 +548,7 @@ impl<const V: usize, const O: usize> Targeter<'_, V, O> {
.dcm_to_inertial(corrected_state.orbit)
.context(AstroPhysicsSnafu)
.context(AstroSnafu)?
.rot_mat
.transpose();
.rot_mat;

let velocity_correction =
dcm_vnc2inertial * state_correction.fixed_rows::<3>(3);
Expand Down
Loading