Skip to content

maneuver.ks mnv_time bugs and improvements #14

Description

@dewiniaid

I was adapting mnv_time for my own purposes and noticed a few things about it while making it fit my code style -- so here's a tiny bit of unsolicited code review

  • The calculation of average Isp (ens_isp) is incorrect, as it is not weighted to factor in the thrust of the individual engines. The KSP wiki page elaborates on this, including an example of a correct average.

  • The calculation of g is incorrect; it's reflecting g at sea level rather than at ship's current altitude. (Additionally, you can use ship:body rather than ship:orbit:body, and also body rather than ship:body). It should probably read:

    body:mu / (body:radius+ship:altitude)^2
    or
    body:mu / body:position:mag^2 // only correct if ship is the active vessel

    EDIT: This is all wrong, because you actually need the altitude where the maneuver node is being executed at, not the ship's current altitude.

  • Multiplying f and m by 1000 is unnecessary; the two terms cancel.

  • You can use ship:availablethrust rather than adding the available thrust from each engine.

  • You can use skip copying engines to a second list and do your processing for average ISP in the first for loop using something like this.

FUNCTION Ship_AverageISP {
    // Returns current average ISP.
    PARAMETER ship IS ship.
    PARAMETER activeOnly IS TRUE.
    PARAMETER includeFlameOut IS FALSE.
    LOCAL engines.
    IF activeonly { SET engines TO Ship_ActiveEngines(ship, includeFlameOut). }
    ELSE { SET engines TO Ship_Engines(ship). }

    LOCAL n IS 0.  // Numerator
    LOCAL d IS 0.  // Denominator

    FOR engine IN engines {
        // might want a check against 0 Isp being reported.
        SET n TO n+engine:availablethrust.
        SET d TO d+(engine:availablethrust / engine:isp).
    }
    RETURN n/d.
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions