untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

issue following node.burn_vector #173

Open PhilouDS opened 1 month ago

PhilouDS commented 1 month ago

When I execute a burn for a maneuver node, I have this in my script:

while (dv_min.value >= 0.01) {
    const ut = current_time()
    craft.autopilot.target_orientation = nextNode.burn_vector
    const dv = nextNode.expected_orbit.orbital_velocity(ut) - craft.orbit.orbital_velocity(ut)
    let max_acc = craft.available_thrust / craft.mass
    craft_throttle.throttle = min(dv.magnitude / max_acc, 1)

    if(dv0 * dv < 0) break
    if (current_time() > start_mnv + burn_duration + 20) break

    yield()
  }

Most of the time, it works well but I've noticed 2 strange situations where the craft.autopilot.target_orientation = nextNode.burn_vector doesn't seem to work very well.

1- around Minmus with a very elliptic orbit, I change my inclination's orbit at the apoapsis. The vessel doesn't stay aligned with the burn vector. 2- fly by of the Mun (picture below) when I start a maneuver at the periapsis of the mun to lower the periapsis around Kerbin.

image

Where should I investigate to understand those problems?

(I have plenty of electricity, I have gimbal and reaction wheel working perfectly... when I execute a long maneuver (for example from Kerbin to Minmus), I have no problem even if the maneuvers lasts more than 90 sec)

untoldwind commented 1 month ago

Instead of manually overriding the target_orientation you could just set the SAS to maneuver mode directly:

vessel.autopilot.mode = AutopilotMode.Maneuver

It should be the same, but I am still not sure if overriding the target_orientation on every yield somehow messes up the internal state of PID-loops in the SAS.

Concerning "following the burn vector" in general: For short burn there is a problem of a "run-away" burn-vector, since

Then again, controlling a course correction is actually a pretty complex problem: https://www.orbiterwiki.org/wiki/Powered_Explicit_Guidance

PhilouDS commented 1 month ago

Instead of manually overriding the target_orientation you could just set the SAS to maneuver mode directly:

vessel.autopilot.mode = AutopilotMode.Maneuver

It should be the same, but I am still not sure if overriding the target_orientation on every yield somehow messes up the internal state of PID-loops in the SAS.

I'll try this. Thanks.