# BORG Guidance Plan 20260808

## Overall Plan

Current approach relies on `Trajectories` to perform impact point prediction. Here we build a kOS addon `kOS-LTR` (`LTR` means "Lifting Trajectory") to efficiently predict impact point with preset AOA. Then Boostback, Entryburn and Landingburn all rely on its prediction.

Then plan is:

- Write C# kOS addon `src/kOS-LTR` to predict impact point with preset speed-AOA profile
- Modify `Script/Falcon9_lib` to use LTR prediction to perform Boostback, Entryburn, atmosphere gliding phase and Landingburn

## kOS-LTR

It is actually a simple version of `kOS-AFS`, you can mimic that project to build this one. `kOS-LTR` is responsible for building an celestial model with interpolated air density, given mass, reference area and speed-AOA profile and double linear interpolation of `CD(speed, density), CL(speed, density)` of a vessel, using RKF45 integrator to predict impact point at given altitude. The difference between `kOS-AFS` and `kOS-LTR` is that `kOS-LTR` assume Bank=0 along the trajectory, it doesn't have bank control loop, just predict the trajectory under open-looped control.

The `kOS-LTR` addon provides suffixes

Same part with `kOS-AFS`: all get-only args, all celectial body parameters, all vessel parameters, Task management

Other parts

```
// Target parameters
target_altitude: ScalarDoubleValue, Get/Set, target impact altitude
RTarget: Vector, Get/Set, Position of target

// Guidance parameters
predict_min_step: same with AFS
predict_max_step: same with AFS
predict_tmax: same with AFS

// Sync operations
GetAOACmd: Input speed, interpolate Speed-AOA profile to get current reference AOA command
GetState: Get current state (R vector and V vector)
GetFARAeroCoefs: Same with AFS
GetFARAeroCoefsEst: Same with AFS
GetDensityAt: Same with AFS
GetDensityEst: Same with AFS
GetAltEst: Same with AFS
InitAtmModel: Same with AFS
DirectionToAngleAxis: Same with AFS

// Async operations
AsyncSimAtmTraj: Start a background atmosphere flight simulation; returns integer handle
```

**Trajectory simulation**

Simpler than AFS, it doesn't have a complicated bank control. Assume that the attitude of the vessel is `rotation * attitude(AOA=command AOA, AOS=0, Bank=0)`

Use RKF45 step to integrate, upon reaching target altitude, use newton's method to solve the accurate time at hitting target altitude (Very same to AFS)

**kOS front end side**

You can refer to `uentry` project to use a similar flavor to initialize and use the addon

**Implement Requirements**

I need to maintain the code, so I want you to keep the code of `kOS-LTR` similar with `kOS-AFS` so that I'll know where to find the functions.

## BoostBack phase

Instead of using remaining speed guidance, use MPC based on impact point prediction

$$
v_g=\frac{1}{T}(r_T-r_P)
$$

Where $T$ is predicted falling time (vaccum), $r_T$ is the target landing site vector, $r_P$ is the predicted impact point.

In practice, we don't calculate falling time, we just point the thrust along $r_T-r_P$ direction and fire the engines, until the error is not decreasing anymore.

The $r_T$ is the raw target geoposition plus `aeroTargetOffset` in downrange direction

## Entryburn phase

Use a hybrid remaining speed guidance based on impact point prediction

$$
\text{Remaining velocity vector  } v_g=\frac{r_T}{T_T}-\frac{r_P}{T_P}-\frac{1}{2}g(T_T-T_P)\\
\text{Target time  } T_T=\frac{1}{g}\left(v_E+\sqrt{v_E^2+2gh}\right)\\
\text{Impact time (vaccum)  } T_P=\frac{1}{g}\left(v_r+\sqrt{v_r^2+2gh}\right)
$$

In practice, using real-time prediction to update remaining velocity (closed-loop guidance)

The $r_T$ is the raw target geoposition plus `aeroTargetOffset` in downrange direction

## Aerodynamic gliding phase

Just a small modification: Switch the prediction from `Trajectories` to `kOS-LTR`

## Landing Burn

Untouched
