Ejemplo n.º 1
0
        private static void GetEngineMinMaxThrust(ModuleEngines engine, out double minThrust, out double maxThrust, bool log = false)
        {
            float isp          = (engine.realIsp > 0) ? engine.realIsp : 280;      // guess!
            float pressure     = (float)FlightGlobals.getStaticPressure() * 0.01f; // so 1.0 at Kerbin sea level?
            float atmMaxThrust = engine.MaxThrustOutputAtm(true, true, pressure, FlightGlobals.getExternalTemperature());

            minThrust = engine.GetEngineThrust(isp, 0); // can't get atmMinThrust (this ignore throttle limiting but thats ok)
            maxThrust = atmMaxThrust;                   // this uses throttle limiting and should give vac thrust as pressure/temp specified too
            if (log)
            {
                Debug.Log("  engine=" + engine + " isp=" + isp + " MinThrust=" + engine.GetEngineThrust(isp, 0) + " MaxThrust=" + atmMaxThrust + " operational=" + engine.isOperational);
            }
        }
Ejemplo n.º 2
0
        // Compute engine thrust if one set of symmetrical engines is shutdown
        // (primarily for a Falcon 9 landing to shutdown engines for slow touchdown)
        public static List <ModuleEngines> ShutdownOuterEngines(Vessel vessel, float desiredThrust, bool log = false)
        {
            List <ModuleEngines> shutdown = new List <ModuleEngines>();

            Debug.Log("ShutdownOuterEngines desiredThrust=" + desiredThrust + " mass=" + vessel.totalMass);
            // Find engine parts and sort by closest to centre first
            List <KeyValuePair <double, ModuleEngines> > allEngines = new List <KeyValuePair <double, ModuleEngines> >();

            foreach (Part part in vessel.GetActiveParts())
            {
                Vector3 relpos = vessel.transform.InverseTransformPoint(part.transform.position);
                part.isEngine(out List <ModuleEngines> engines);
                double dist = Math.Sqrt(relpos.x * relpos.x + relpos.z * relpos.z);
                foreach (ModuleEngines engine in engines)
                {
                    allEngines.Add(new KeyValuePair <double, ModuleEngines>(dist, engine));
                }
            }
            allEngines.Sort(Closest);

            // Loop through engines starting a closest to axis
            // Accumulate minThrust, once minThrust exceeds desiredThrust shutdown this and all
            // further out engines
            float  minThrust = 0, maxThrust = 0;
            double shutdownDist = float.MaxValue;

            foreach (var engDist in allEngines)
            {
                ModuleEngines engine = engDist.Value;
                if (engine.isOperational)
                {
                    minThrust += engine.GetEngineThrust(engine.realIsp, 0);
                    maxThrust += engine.GetEngineThrust(engine.realIsp, 1);
                    if (shutdownDist == float.MaxValue)
                    {
                        if ((minThrust < desiredThrust) && (desiredThrust < maxThrust)) // good amount of thrust
                        {
                            shutdownDist = engDist.Key + 0.1f;
                        }
                        if (minThrust > desiredThrust)
                        {
                            shutdownDist = engDist.Key - 0.1f;
                        }
                    }

                    if (engDist.Key > shutdownDist)
                    {
                        if (log)
                        {
                            Debug.Log("[BoosterGuidance] ComputeShutdownMinMaxThrust(): minThrust=" + minThrust + " desiredThrust=" + desiredThrust + " SHUTDOWN");
                        }
                        engine.Shutdown();
                        shutdown.Add(engine);
                    }
                    else
                    if (log)
                    {
                        Debug.Log("[BoosterGuidance] ComputeShutdownMinMaxThrust(): minThrust=" + minThrust + " desiredThrust=" + desiredThrust + " KEEP");
                    }
                }
            }
            Debug.Log(shutdown.Count + " engines shutdown");
            return(shutdown);
        }