Example #1
0
        public ReentrySimulation(Orbit initialOrbit, double UT, double dragCoefficient,
                                 IDescentSpeedPolicy descentSpeedPolicy, double endAltitudeASL, double maxThrustAccel)
        {
            CelestialBody body = initialOrbit.referenceBody;

            bodyHasAtmosphere       = body.atmosphere;
            seaLevelAtmospheres     = body.atmosphereMultiplier;
            scaleHeight             = 1000 * body.atmosphereScaleHeight;
            bodyRadius              = body.Radius;
            gravParameter           = body.gravParameter;
            this.dragCoefficient    = dragCoefficient;
            bodyAngularVelocity     = body.angularVelocity;
            this.descentSpeedPolicy = descentSpeedPolicy;
            landedRadius            = bodyRadius + endAltitudeASL;
            aerobrakedRadius        = bodyRadius + body.RealMaxAtmosphereAltitude();
            mainBody            = body;
            this.maxThrustAccel = maxThrustAccel;

            referenceFrame = ReferenceFrame.CreateAtCurrentTime(initialOrbit.referenceBody);

            orbitReenters = OrbitReenters(initialOrbit);

            if (orbitReenters)
            {
                startUT = UT;
                t       = startUT;
                AdvanceToFreefallEnd(initialOrbit);
            }

            maxDragGees    = 0;
            deltaVExpended = 0;
            trajectory     = new List <AbsoluteVector>();
        }
Example #2
0
        public ReentrySimulation(Orbit _initialOrbit, double _UT, double _dragMassExcludingUsedParachutes, List <SimulatedParachute> _parachuteList, double _mass,
                                 IDescentSpeedPolicy _descentSpeedPolicy, double _decelEndAltitudeASL, double _maxThrustAccel, double _parachuteSemiDeployMultiplier, double _probableLandingSiteASL, bool _multiplierHasError, double _dt)
        {
            // Store all the input values as they were given
            input_initialOrbit = _initialOrbit;
            input_UT           = _UT;
            input_dragMassExcludingUsedParachutes = _dragMassExcludingUsedParachutes;
            input_parachuteList                 = _parachuteList;
            input_mass                          = _mass;
            input_descentSpeedPolicy            = _descentSpeedPolicy;
            input_decelEndAltitudeASL           = _decelEndAltitudeASL;
            input_maxThrustAccel                = _maxThrustAccel;
            input_parachuteSemiDeployMultiplier = _parachuteSemiDeployMultiplier;
            input_probableLandingSiteASL        = _probableLandingSiteASL;
            input_multiplierHasError            = _multiplierHasError;
            input_dt = _dt;

            max_dt = _dt;
            dt     = max_dt;

            // Get a copy of the original orbit, to be more thread safe
            initialOrbit = new Orbit();
            initialOrbit.UpdateFromOrbitAtUT(_initialOrbit, _UT, _initialOrbit.referenceBody);

            CelestialBody body = _initialOrbit.referenceBody;

            bodyHasAtmosphere   = body.atmosphere;
            seaLevelAtmospheres = body.atmosphereMultiplier;
            scaleHeight         = 1000 * body.atmosphereScaleHeight;
            bodyRadius          = body.Radius;
            gravParameter       = body.gravParameter;
            this.dragMassExcludingUsedParachutes = _dragMassExcludingUsedParachutes;

            this.parachutes = _parachuteList;
            this.parachuteSemiDeployMultiplier = _parachuteSemiDeployMultiplier;
            this.multiplierHasError            = _multiplierHasError;

            this.mass               = _mass;
            bodyAngularVelocity     = body.angularVelocity;
            this.descentSpeedPolicy = _descentSpeedPolicy;
            decelRadius             = bodyRadius + _decelEndAltitudeASL;
            aerobrakedRadius        = bodyRadius + body.RealMaxAtmosphereAltitude();
            mainBody                       = body;
            this.maxThrustAccel            = _maxThrustAccel;
            this.probableLandingSiteASL    = _probableLandingSiteASL;
            this.probableLandingSiteRadius = _probableLandingSiteASL + bodyRadius;

            referenceFrame = ReferenceFrame.CreateAtCurrentTime(_initialOrbit.referenceBody);

            orbitReenters = OrbitReenters(_initialOrbit);

            if (orbitReenters)
            {
                startUT = _UT;
            }

            maxDragGees    = 0;
            deltaVExpended = 0;
            trajectory     = new List <AbsoluteVector>();
        }
Example #3
0
        //redraw the picture of the planned flight path
        public static void UpdateAtmoTexture(Texture2D texture, CelestialBody mainBody, double maxAltitude, bool realAtmo = false)
        {
            double scale = maxAltitude / texture.height; //meters per pixel

            double maxAtmosphereAltitude = mainBody.RealMaxAtmosphereAltitude();
            double pressureSeaLevel      = mainBody.atmospherePressureSeaLevel;

            for (int y = 0; y < texture.height; y++)
            {
                double alt = scale * y;

                if (realAtmo)
                {
                    alt = mainBody.GetPressure(alt) / pressureSeaLevel;
                }
                else
                {
                    alt = 1.0 - alt / maxAtmosphereAltitude;
                }

                float v = (float)(mainBody.atmosphere ? alt : 0.0F);
                Color c = new Color(0.0F, 0.0F, v);

                for (int x = 0; x < texture.width; x++)
                {
                    texture.SetPixel(x, y, c);

                    if (mainBody.atmosphere && (int)(maxAtmosphereAltitude / scale) == y)
                    {
                        texture.SetPixel(x, y, XKCDColors.LightGreyBlue);
                    }
                }
            }

            texture.Apply();
        }
        //redraw the picture of the planned flight path
        public static void UpdateAtmoTexture(Texture2D texture, CelestialBody mainBody, double maxAltitude, bool realAtmo = false)
        {
            double scale = maxAltitude / texture.height; //meters per pixel

            double maxAtmosphereAltitude = mainBody.RealMaxAtmosphereAltitude();
            double pressureSeaLevel = mainBody.atmospherePressureSeaLevel;

            for (int y = 0; y < texture.height; y++)
            {
                double alt = scale * y;

                if (realAtmo)
                {
                    alt = mainBody.GetPressure(alt) / pressureSeaLevel;
                }
                else
                {
                    alt = 1.0 - alt / maxAtmosphereAltitude;
                }

                float v = (float)(mainBody.atmosphere ? alt : 0.0F);
                Color c = new Color(0.0F, 0.0F, v);

                for (int x = 0; x < texture.width; x++)
                {
                    texture.SetPixel(x, y, c);

                    if (mainBody.atmosphere && (int)(maxAtmosphereAltitude / scale) == y)
                        texture.SetPixel(x, y, XKCDColors.LightGreyBlue);
                }
            }

            texture.Apply();
        }
        //        public override void OnStart(PartModule.StartState state)
        //        {
        //            base.OnStart(state);
        //            
        //            fiSelRes = Type.GetType("Kethane.KethaneController").GetField("SelectedResource");
        //        }
        public override void OnFixedUpdate()
        {
            //			base.OnFixedUpdate();
            if (HighLogic.LoadedScene != GameScenes.FLIGHT || KethaneData.Current == null) { return; }

            if (lastBody != vessel.orbit.referenceBody) { // thanks to The_Duck, Technogeeky and ian for helping me fix the orbit calculation
                lastBody = vessel.orbit.referenceBody;
            //				Debug.Log("GravParameter " + lastBody.gravParameter);
                Orbits = new List<float>();
                int y = 1;
                var u3 = Math.Pow(lastBody.gravParameter, 1.0 / 3.0);
                while (y > 0)
                {
                    var oP = lastBody.rotationPeriod * (y / 80f);
                    var alt = u3 * Math.Pow(oP / (2 * Math.PI), 2.0 / 3.0) - lastBody.Radius;
                    var msg = string.Format("Orbit {0} is at {1:F1} km", y, alt / 1000f);
                    if (y % 2 != 0 && y % 5 != 0 && alt > 0 && alt < lastBody.sphereOfInfluence && (lastBody.atmosphere ? alt > lastBody.RealMaxAtmosphereAltitude() : true))
                    {
                        msg += " added";
                        Orbits.Add((float)alt / 1000f);
            //						Debug.Log(msg);
                    }
                    y++;
                    if (alt >= lastBody.sphereOfInfluence) { break; }
                }
                Orbits.Sort();
                string str = "";
                foreach (var o in Orbits)
                {
                    str += o.ToString("#.0") + " km\n";
                }
                System.IO.File.WriteAllText(KSPUtil.ApplicationRootPath + "\\KethaneScanOrbits_" + lastBody.name + ".txt", str);
            }

            //			var scans = KethaneData.Current.Scans[(string)fiSelRes.GetValue(null)][vessel.mainBody.name];
            var scans = KethaneData.Current.Scans[MapOverlay.SelectedResource][vessel.mainBody.name];
            Coverage = (float)Math.Floor(ordered.Count(c => scans[c]) / (float)ordered.Length * 100f * 100f) / 100f;

            var cell = GetLowestUnscanned(scans);
            if (Coverage == 100 && Active) {
                print(vessel.mainBody.name + " completely scanned at " + vesselState.time);
                TimeWarp.SetRate(0, false);
                Active = false;
            }
            maxInc = CellToLonLat(cell).y;

            if (Active)
            {
                var curInc = Math.Abs(maxInc);
                var myInc = Math.Abs(vesselState.orbitInclination);
                var diff = Math.Abs(myInc - curInc);

                switch (Status)
                {
                    case ControllerState.Inactive:
                        Status = ControllerState.Idle;
                        break;

                    case ControllerState.Idle:
                        if (diff > IncChangeStep && curInc >= IncChangeLimit && vessel.patchedConicSolver.maneuverNodes.Count == 0) {
                            var planner = core.GetComputerModule<MechJebModuleManeuverPlanner>();

                            double newInc;
                            if (ChangeByStep) {
                                newInc = vesselState.orbitInclination - (IncChangeStep * (vesselState.orbitInclination < 0 ? -1 : 1));
                            }
                            else
                            {
                                newInc = (curInc * (vesselState.orbitInclination < 0 ? -1 : 1));
                            }
                            newInc = Math.Round(newInc, 2);

                            var result = planner.PlanNode(MechJebModuleManeuverPlanner.Operation.INCLINATION,
                                                          MechJebModuleManeuverPlanner.TimeReference.EQ_ASCENDING, 0, 0, 0, newInc, 0, 0, 0, false);

                            if (result.Success && core.node != null) {
                                core.node.ExecuteOneNode(this);
                            }
                            else {
                                Active = false;
                                Status = ControllerState.Inactive;
                                print("KSC node planning error: " + result.Error + "\ntime error: " + result.TimeError);
                            }

                            warp = TimeWarp.CurrentRateIndex;
                            TimeWarp.SetRate(0, true);
                            Status = ControllerState.Waiting;
                        }
                        break;

                    case ControllerState.Waiting:
                        if (vessel.patchedConicSolver.maneuverNodes.Count == 0 && vessel.ctrlState.mainThrottle == 0)
                        {
                            TimeWarp.SetRate(warp, false);
                            Status = ControllerState.Idle;
            //							if (myInc - IncChangeStep < IncChangeLimit) { Active = false; }
                        }
                        break;
                }

            //				if (!core.node.users.Contains(this)) { core.node.users.Add(this); }
            }
            else //if(!Active)
            {
                if (Status != ControllerState.Disabled && Status != ControllerState.Inactive) { Status = ControllerState.Inactive; }
            //				if (core.node.users.Contains(this)) { core.node.users.Remove(this); }
            }
        }
Example #6
0
        public ReentrySimulation(Orbit _initialOrbit, double _UT, SimulatedVessel _vessel, SimCurves _simcurves, IDescentSpeedPolicy _descentSpeedPolicy, double _decelEndAltitudeASL, double _maxThrustAccel, double _parachuteSemiDeployMultiplier, double _probableLandingSiteASL, bool _multiplierHasError, double _dt, double _min_dt)
        {
            // Store all the input values as they were given
            input_initialOrbit = _initialOrbit;
            input_UT           = _UT;

            vessel = _vessel;
            input_descentSpeedPolicy            = _descentSpeedPolicy;
            input_decelEndAltitudeASL           = _decelEndAltitudeASL;
            input_maxThrustAccel                = _maxThrustAccel;
            input_parachuteSemiDeployMultiplier = _parachuteSemiDeployMultiplier;
            input_probableLandingSiteASL        = _probableLandingSiteASL;
            input_multiplierHasError            = _multiplierHasError;
            input_dt = _dt;

            // the vessel attitude relative to the surface vel. Fixed for now
            attitude = Quaternion.Euler(180, 0, 0);

            min_dt = _min_dt;
            max_dt = _dt;
            dt     = max_dt;

            // Get a copy of the original orbit, to be more thread safe
            initialOrbit = new Orbit();
            initialOrbit.UpdateFromOrbitAtUT(_initialOrbit, _UT, _initialOrbit.referenceBody);

            CelestialBody body = _initialOrbit.referenceBody;

            bodyHasAtmosphere = body.atmosphere;
            bodyRadius        = body.Radius;
            gravParameter     = body.gravParameter;

            this.parachuteSemiDeployMultiplier = _parachuteSemiDeployMultiplier;
            this.multiplierHasError            = _multiplierHasError;

            bodyAngularVelocity     = body.angularVelocity;
            this.descentSpeedPolicy = _descentSpeedPolicy;
            decelRadius             = bodyRadius + _decelEndAltitudeASL;
            aerobrakedRadius        = bodyRadius + body.RealMaxAtmosphereAltitude();
            mainBody                       = body;
            this.maxThrustAccel            = _maxThrustAccel;
            this.probableLandingSiteASL    = _probableLandingSiteASL;
            this.probableLandingSiteRadius = _probableLandingSiteASL + bodyRadius;

            referenceFrame = ReferenceFrame.CreateAtCurrentTime(_initialOrbit.referenceBody);

            orbitReenters = OrbitReenters(_initialOrbit);

            if (orbitReenters)
            {
                startUT = _UT;
            }

            maxDragGees    = 0;
            deltaVExpended = 0;
            trajectory     = new List <AbsoluteVector>();

            simCurves = _simcurves;

            once = true;
        }