Esempio n. 1
0
        public void UpdateImbalance(bool useDefTorque, params IList <EngineWrapper>[] engines)
        {
            var torque = CalculateImbalance(useDefTorque, engines);

//            if(VSL.OnPlanet) torque += VSL.LocalDir(VSL.OnPlanetParams.AeroTorque);
            Imbalance.Update(EnginesLimits.Clamp(torque));
        }
Esempio n. 2
0
 public EnginesStats(EnginesDB engines, VesselWrapper vsl)
     : base(vsl)
 {
     engines.SortByRole();
     TorqueInfo = new TorqueInfo(VSL);
     for (int i = 0, count = engines.Count; i < count; i++)
     {
         var e = engines[i];
         e.InitState();
         e.InitTorque(VSL, EngineOptimizer.C.TorqueRatioFactor);
         e.UpdateCurrentTorque(1);
     }
     engines.OptimizeForZeroTorque(VSL.Physics.MoI);
     for (int i = 0, count = engines.Count; i < count; i++)
     {
         var e        = engines[i];
         var throttle = e.Role == TCARole.MANUAL ? e.limit : e.thrustLimit;
         if (throttle > 0)
         {
             if (e.Role != TCARole.MANEUVER)
             {
                 var thrust = e.nominalCurrentThrust(throttle);
                 MaxThrust    += e.wThrustDir * thrust;
                 MaxDefThrust += e.defThrustDir * thrust;
                 MaxMassFlow  += e.MaxFuelFlow * throttle;
             }
             if (e.isSteering)
             {
                 TorqueLimits.Add(e.specificTorque * e.nominalCurrentThrust(throttle));
             }
         }
     }
     TorqueInfo.Update(TorqueLimits.Max + VSL.Torque.NoEngines.Torque);
 }
        public override void Update()
        {
            //engines
            EnginesLimits = Vector6.zero;
            var MaxEnginesLimits = Vector6.zero;

            for (int i = 0, count = VSL.Engines.Steering.Count; i < count; i++)
            {
                var e = VSL.Engines.Steering[i];
                EnginesLimits.Add(e.currentTorque);
                MaxEnginesLimits.Add(e.specificTorque * e.nominalCurrentThrust(1));
            }
            //wheels
            WheelsLimits = Vector6.zero;
            for (int i = 0, count = Wheels.Count; i < count; i++)
            {
                var w = Wheels[i];
                if (!w.operational)
                {
                    continue;
                }
                var torque = new Vector3(w.PitchTorque, w.RollTorque, w.YawTorque);
                WheelsLimits.Add(torque);
                WheelsLimits.Add(-torque);
            }
            //RCS
            RCSLimits = Vector6.zero;
            for (int i = 0; i < VSL.Engines.NumActiveRCS; i++)
            {
                var r = VSL.Engines.ActiveRCS[i];
                for (int j = 0, tcount = r.rcs.thrusterTransforms.Count; j < tcount; j++)
                {
                    var t = r.rcs.thrusterTransforms[j];
                    if (t == null)
                    {
                        continue;
                    }
                    RCSLimits.Add(refT.InverseTransformDirection(Vector3.Cross(t.position - VSL.Physics.wCoM, t.up) * r.rcs.thrusterPower));
                }
            }
            //torque and angular acceleration
            Engines.Update(EnginesLimits.Max);
            NoEngines.Update(RCSLimits.Max + WheelsLimits.Max);
            MaxEngines.Update(MaxEnginesLimits.Max);
            MaxCurrent.Update(NoEngines.Torque + Engines.Torque);
            MaxPossible.Update(NoEngines.Torque + MaxEngines.Torque);
            MaxPitchRoll.Update(Vector3.ProjectOnPlane(MaxCurrent.Torque, VSL.Engines.CurrentThrustDir));

            if (MaxCurrent.AA_rad > 0)
            {
                MaxAAMod  = MaxAAFilter.Update(MaxCurrent.AA_rad) / MaxCurrent.AA_rad;
                MaxAAMod *= MaxAAMod * MaxAAMod;
            }
            else
            {
                MaxAAMod = 1;
            }
        }
Esempio n. 4
0
        public void UpdateImbalance(bool useDefTorque, params IList <EngineWrapper>[] engines)
        {
            var torque = CalculateImbalance(useDefTorque, engines);

            if (VSL.OnPlanet)
            {
                torque -= VSL.OnPlanetParams.AeroTorqueL;
            }
            Imbalance.Update(EnginesLimits.ClampComponents(torque));
        }
        public void UpdateImbalance(params IList <EngineWrapper>[] engines)
        {
            var torque = Vector3.zero;

            for (int i = 0; i < engines.Length; i++)
            {
                for (int j = 0; j < engines[i].Count; j++)
                {
                    var e = engines[i][j];
                    torque += e.Torque(e.throttle * e.limit);
                }
            }
            Imbalance.Update(EnginesLimits.Clamp(torque));
        }
 public override void Update()
 {
     //engines
     Slow = false;
     EnginesResponseTime = Vector3.zero;
     EnginesResponseTimeM = 0f;
     EnginesLimits = Vector6.zero;
     RCSLimits = Vector6.zero;
     OtherLimits = Vector6.zero;
     var MaxEnginesLimits = Vector6.zero;
     var EnginesSpecificTorque = Vector6.zero;
     var EnginesMaxSpecificTorque = Vector6.zero;
     var TorqueResponseSpeed = Vector6.zero;
     var TotalSlowTorque = Vector6.zero;
     var TotalSlowSpecificTorque = Vector6.zero;
     var RCSSpecificTorque = Vector6.zero;
     for(int i = 0, count = VSL.Engines.Active.Steering.Count; i < count; i++)
     {
         var e = VSL.Engines.Active.Steering[i];
         var max_torque = e.defSpecificTorque * e.nominalFullThrust;
         Vector3 pos, neg, max_spec_torque = e.defSpecificTorque;
         if(e.gimbal != null && e.gimbal.gimbalActive && !e.gimbal.gimbalLock)
         {
             Gimball = true;
             e.gimbal.GetPotentialTorque(out pos, out neg);
             max_torque += new Vector3(Mathf.Max(pos.x, neg.x), Mathf.Max(pos.y, neg.y), Mathf.Max(pos.z, neg.z));
             max_spec_torque = max_torque / e.nominalFullThrust;
         }
         EnginesLimits.Add(e.defCurrentTorque);
         EnginesSpecificTorque.Add(e.defSpecificTorque);
         MaxEnginesLimits.Add(max_torque);
         EnginesMaxSpecificTorque.Add(max_spec_torque);
         if(e.useEngineResponseTime)
         {
             TotalSlowTorque.Add(max_torque);
             TotalSlowSpecificTorque.Add(max_spec_torque);
             TorqueResponseSpeed.Add(max_torque* Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed));
         }
     }
     //RCS
     for(int i = 0; i < VSL.Engines.NumActiveRCS; i++)
     {
         var r = VSL.Engines.ActiveRCS[i];
         for(int j = 0, tcount = r.rcs.thrusterTransforms.Count; j < tcount; j++)
         {
             var t = r.rcs.thrusterTransforms[j];
             if(t == null) continue;
             var specificTorque = refT.InverseTransformDirection(Vector3.Cross(t.position-VSL.Physics.wCoM, t.up));
             RCSLimits.Add(specificTorque*r.rcs.thrusterPower);
             RCSSpecificTorque.Add(specificTorque);
         }
     }
     //wheels and control surfaces
     for(int i = 0, count = Wheels.Count; i < count; i++)
     {
         var w = Wheels[i];
         var limit = w.authorityLimiter/100;
         Vector3 pos, neg;
         w.GetPotentialTorque(out pos, out neg);
         OtherLimits.Add(pos*limit);
         OtherLimits.Add(-neg*limit);
     }
     for(int i = 0, count = ControlSurfaces.Count; i < count; i++)
     {
         var s = ControlSurfaces[i];
         Vector3 pos, neg;
         s.GetPotentialTorque(out pos, out neg);
         OtherLimits.Add(pos);
         OtherLimits.Add(-neg);
     }
     //torque and angular acceleration
     Engines.Update(EnginesLimits.Max);
     NoEngines.Update(RCSLimits.Max+OtherLimits.Max);
     MaxEngines.Update(MaxEnginesLimits.Max);
     MaxCurrent.Update(NoEngines.Torque+Engines.Torque);
     MaxPossible.Update(NoEngines.Torque+MaxEngines.Torque);
     MaxPitchRoll.Update(Vector3.ProjectOnPlane(MaxCurrent.Torque, VSL.Engines.CurrentThrustDir).AbsComponents());
     SlowMaxPossible.Update(TotalSlowTorque.Max);
     Instant.Update(MaxPossible.Torque-SlowMaxPossible.Torque);
     //specifc torque
     Engines.SpecificTorque = EnginesSpecificTorque.Max;
     NoEngines.SpecificTorque = RCSSpecificTorque.Max;
     MaxEngines.SpecificTorque = EnginesMaxSpecificTorque.Max;
     MaxCurrent.SpecificTorque = Engines.SpecificTorque+NoEngines.SpecificTorque;
     MaxPossible.SpecificTorque = MaxEngines.SpecificTorque + NoEngines.SpecificTorque;
     MaxPitchRoll.SpecificTorque = Vector3.ProjectOnPlane(MaxCurrent.SpecificTorque, VSL.Engines.CurrentThrustDir).AbsComponents();
     SlowMaxPossible.SpecificTorque = TotalSlowSpecificTorque.Max;
     Instant.SpecificTorque = MaxPossible.SpecificTorque-SlowMaxPossible.SpecificTorque;
     //torque response time
     if(!TorqueResponseSpeed.IsZero()) 
     { 
         EnginesResponseTime = Vector3.Scale(SlowMaxPossible.Torque, TorqueResponseSpeed.Max.Inverse(0));
         EnginesResponseTime = EnginesResponseTime.ScaleChain(SlowMaxPossible.Torque, MaxPossible.Torque.Inverse(0));
         EnginesResponseTimeM = EnginesResponseTime.MaxComponentF();
         Slow = true;
     }
     //Max AA filter
     if(MaxCurrent.AA_rad > 0)
     {
         MaxAAMod = MaxAAFilter.Update(MaxCurrent.AA_rad)/MaxCurrent.AA_rad;
         MaxAAMod *= MaxAAMod*MaxAAMod;
     }
     else MaxAAMod = 1;
 }
 public override void Update()
 {
     TorqueInfo.Update(TorqueLimits.Max);
 }
        public override void Update()
        {
            //engines
            EnginesResponseTime  = Vector3.zero;
            EnginesResponseTimeM = 0f;
            EnginesLimits        = Vector6.zero;
            var MaxEnginesLimits      = Vector6.zero;
            var EnginesSpecificTorque = Vector6.zero;
            var TorqueResponseSpeed   = Vector6.zero;
            var TotalSlowTorque       = Vector6.zero;

            for (int i = 0, count = VSL.Engines.Active.Steering.Count; i < count; i++)
            {
                var e = VSL.Engines.Active.Steering[i];
                EnginesLimits.Add(e.currentTorque);
                EnginesSpecificTorque.Add(e.specificTorque);
                MaxEnginesLimits.Add(e.specificTorque * e.nominalCurrentThrust(1));
                if (e.useEngineResponseTime && (e.Role == TCARole.MAIN || e.Role == TCARole.MANEUVER))
                {
                    TotalSlowTorque.Add(e.currentTorque);
                    TorqueResponseSpeed.Add(e.currentTorque * Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed));
                }
            }
            //wheels
            WheelsLimits = Vector6.zero;
            for (int i = 0, count = Wheels.Count; i < count; i++)
            {
                var w = Wheels[i];
                if (w.State != ModuleReactionWheel.WheelState.Active)
                {
                    continue;
                }
                var torque = new Vector3(w.PitchTorque, w.RollTorque, w.YawTorque);
                WheelsLimits.Add(torque);
                WheelsLimits.Add(-torque);
            }
            //RCS
            RCSLimits = Vector6.zero;
            var RCSSpecificTorque = Vector6.zero;

            for (int i = 0; i < VSL.Engines.NumActiveRCS; i++)
            {
                var r = VSL.Engines.ActiveRCS[i];
                for (int j = 0, tcount = r.rcs.thrusterTransforms.Count; j < tcount; j++)
                {
                    var t = r.rcs.thrusterTransforms[j];
                    if (t == null)
                    {
                        continue;
                    }
                    var specificTorque = refT.InverseTransformDirection(Vector3.Cross(t.position - VSL.Physics.wCoM, t.up));
                    RCSLimits.Add(specificTorque * r.rcs.thrusterPower);
                    RCSSpecificTorque.Add(specificTorque);
                }
            }
            //torque and angular acceleration
            Engines.Update(EnginesLimits.Max);
            NoEngines.Update(RCSLimits.Max + WheelsLimits.Max);
            MaxEngines.Update(MaxEnginesLimits.Max);
            MaxCurrent.Update(NoEngines.Torque + Engines.Torque);
            MaxPossible.Update(NoEngines.Torque + MaxEngines.Torque);
            MaxPitchRoll.Update(Vector3.ProjectOnPlane(MaxCurrent.Torque, VSL.Engines.CurrentThrustDir));
            //specifc angular acceleration
            Engines.SpecificTorque = EnginesSpecificTorque.Max;
//			Log("Engines.SpecificTorque: {}, TorqueResponseTime: {}", Engines.SpecificTorque, VSL.Engines.TorqueResponseTime);//debug
            NoEngines.SpecificTorque    = RCSSpecificTorque.Max;
            MaxEngines.SpecificTorque   = Engines.SpecificTorque;
            MaxCurrent.SpecificTorque   = Engines.SpecificTorque + NoEngines.SpecificTorque;
            MaxPossible.SpecificTorque  = MaxCurrent.SpecificTorque;
            MaxPitchRoll.SpecificTorque = Vector3.ProjectOnPlane(MaxCurrent.SpecificTorque, VSL.Engines.CurrentThrustDir);
            //torque response time
            if (!TorqueResponseSpeed.IsZero())
            {
                var slow_torque = TotalSlowTorque.Max;
                EnginesResponseTime  = Vector3.Scale(slow_torque, TorqueResponseSpeed.Max.Inverse(0));
                EnginesResponseTime  = EnginesResponseTime.ScaleChain(slow_torque, MaxCurrent.Torque.Inverse(0));
                EnginesResponseTimeM = EnginesResponseTime.MaxComponentF();
            }
            //Max AA filter
            if (MaxCurrent.AA_rad > 0)
            {
                MaxAAMod  = MaxAAFilter.Update(MaxCurrent.AA_rad) / MaxCurrent.AA_rad;
                MaxAAMod *= MaxAAMod * MaxAAMod;
            }
            else
            {
                MaxAAMod = 1;
            }
        }
        public void UpdateImbalance(params IList <EngineWrapper>[] engines)
        {
            var torque = CalculateImbalance(engines);

            Imbalance.Update(EnginesLimits.Clamp(torque));
        }
Esempio n. 10
0
        public override void Update()
        {
            //engines
            Slow = false;
            EnginesResponseTime  = Vector3.zero;
            EnginesResponseTimeM = 0f;
            EnginesLimits        = Vector6.zero;
            var MaxEnginesLimits        = Vector6.zero;
            var EnginesSpecificTorque   = Vector6.zero;
            var TorqueResponseSpeed     = Vector6.zero;
            var TotalSlowTorque         = Vector6.zero;
            var TotalSlowSpecificTorque = Vector6.zero;

            for (int i = 0, count = VSL.Engines.Active.Steering.Count; i < count; i++)
            {
                var e          = VSL.Engines.Active.Steering[i];
                var max_torque = e.defSpecificTorque * e.nominalFullThrust;
                EnginesLimits.Add(e.defCurrentTorque);
                EnginesSpecificTorque.Add(e.defSpecificTorque);
                MaxEnginesLimits.Add(max_torque);
                if (e.useEngineResponseTime)
                {
                    TotalSlowTorque.Add(max_torque);
                    TotalSlowSpecificTorque.Add(e.defSpecificTorque);
                    TorqueResponseSpeed.Add(max_torque * Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed));
                }
                Gimball |= e.gimbal != null && e.gimbal.gimbalActive && !e.gimbal.gimbalLock;
            }
            //wheels
            WheelsLimits = Vector6.zero;
            for (int i = 0, count = Wheels.Count; i < count; i++)
            {
                var w = Wheels[i];
                if (w.State != ModuleReactionWheel.WheelState.Active)
                {
                    continue;
                }
                var torque = new Vector3(w.PitchTorque, w.RollTorque, w.YawTorque) * w.authorityLimiter / 100;
                WheelsLimits.Add(torque);
                WheelsLimits.Add(-torque);
            }
            //RCS
            RCSLimits = Vector6.zero;
            var RCSSpecificTorque = Vector6.zero;

            for (int i = 0; i < VSL.Engines.NumActiveRCS; i++)
            {
                var r = VSL.Engines.ActiveRCS[i];
                for (int j = 0, tcount = r.rcs.thrusterTransforms.Count; j < tcount; j++)
                {
                    var t = r.rcs.thrusterTransforms[j];
                    if (t == null)
                    {
                        continue;
                    }
                    var specificTorque = refT.InverseTransformDirection(Vector3.Cross(t.position - VSL.Physics.wCoM, t.up));
                    RCSLimits.Add(specificTorque * r.rcs.thrusterPower);
                    RCSSpecificTorque.Add(specificTorque);
                }
            }
            //torque and angular acceleration
            Engines.Update(EnginesLimits.Max);
            NoEngines.Update(RCSLimits.Max + WheelsLimits.Max);
            MaxEngines.Update(MaxEnginesLimits.Max);
            MaxCurrent.Update(NoEngines.Torque + Engines.Torque);
            MaxPossible.Update(NoEngines.Torque + MaxEngines.Torque);
            MaxPitchRoll.Update(Vector3.ProjectOnPlane(MaxCurrent.Torque, VSL.Engines.CurrentThrustDir).AbsComponents());
            SlowMaxPossible.Update(TotalSlowTorque.Max);
            Instant.Update(MaxPossible.Torque - SlowMaxPossible.Torque);
            //specifc torque
            Engines.SpecificTorque         = EnginesSpecificTorque.Max;
            NoEngines.SpecificTorque       = RCSSpecificTorque.Max;
            MaxEngines.SpecificTorque      = Engines.SpecificTorque;
            MaxCurrent.SpecificTorque      = Engines.SpecificTorque + NoEngines.SpecificTorque;
            MaxPossible.SpecificTorque     = MaxCurrent.SpecificTorque;
            MaxPitchRoll.SpecificTorque    = Vector3.ProjectOnPlane(MaxCurrent.SpecificTorque, VSL.Engines.CurrentThrustDir).AbsComponents();
            SlowMaxPossible.SpecificTorque = TotalSlowSpecificTorque.Max;
            Instant.SpecificTorque         = MaxPossible.SpecificTorque - SlowMaxPossible.SpecificTorque;
            //torque response time
            if (!TorqueResponseSpeed.IsZero())
            {
                EnginesResponseTime  = Vector3.Scale(SlowMaxPossible.Torque, TorqueResponseSpeed.Max.Inverse(0));
                EnginesResponseTime  = EnginesResponseTime.ScaleChain(SlowMaxPossible.Torque, MaxPossible.Torque.Inverse(0));
                EnginesResponseTimeM = EnginesResponseTime.MaxComponentF();
                Slow = true;
            }
            //Max AA filter
            if (MaxCurrent.AA_rad > 0)
            {
                MaxAAMod  = MaxAAFilter.Update(MaxCurrent.AA_rad) / MaxCurrent.AA_rad;
                MaxAAMod *= MaxAAMod * MaxAAMod;
            }
            else
            {
                MaxAAMod = 1;
            }
        }