Ejemplo n.º 1
0
 public void OnPostAutopilotUpdate(FlightCtrlState s)
 {
     if (!Valid || !CFG.Enabled)
     {
         return;
     }
     //handle engines
     VSL.PostUpdateState(s);
     VSL.Engines.Tune();
     if (VSL.Engines.NumActive > 0)
     {
         //:preset manual limits for translation if needed
         var translation = VSL.Controls.EnginesTranslation;
         if (VSL.Controls.HasTranslation)
         {
             translation += VSL.Controls.Translation;
         }
         if (!translation.IsZero())
         {
             EngineOptimizer.PresetLimitsForTranslation(VSL.Engines.Active.Maneuver, translation.normalized);
             if (CFG.VSCIsActive && !VSL.Controls.HasTranslation)
             {
                 EngineOptimizer.LimitInDirection(VSL.Engines.Active.Maneuver, VSL.Physics.UpL);
             }
         }
         ENG.Steer();
     }
     RCS.Steer();
     VSL.Engines.SetControls();
     VSL.FinalUpdate();
 }
Ejemplo n.º 2
0
        public bool OptimizeForZeroTorque(Vector3 MoI)
        {
            var   torque = Vector3.zero;
            float torque_error, angle_error, max_limit;

            if (Balanced.Count > 0)
            {
                torque = TorqueProps.CalculateImbalance(true, Manual, UnBalanced);
                EngineOptimizer.OptimizeLimitsForTorque(Balanced, Vector3.zero, torque, MoI, true,
                                                        out max_limit, out torque_error, out angle_error);
            }
            if (Steering.Count > 0)
            {
                torque = TorqueProps.CalculateImbalance(true, Manual, UnBalanced, Balanced);
                return(EngineOptimizer.OptimizeLimitsForTorque(Steering, Vector3.zero, torque, MoI, true,
                                                               out max_limit, out torque_error, out angle_error));
            }
            return(true);
        }
Ejemplo n.º 3
0
        void UpdateShipStats()
        {
            MinLimit = 0;
            var thrust         = Vector3.zero;
            var selected_parts = GetSelectedParts();

            CalculateMassAndCoM(selected_parts);
            if (CFG != null && CFG.Enabled && Engines.Count > 0)
            {
                ActiveEngines.Clear();
                for (int i = 0, EnginesCount = Engines.Count; i < EnginesCount; i++)
                {
                    var e    = Engines[i];
                    var ecfg = CFG.ActiveProfile.GetConfig(e);
                    if (ecfg == null || ecfg.On)
                    {
                        ActiveEngines.Add(e);
                    }
                }
                if (selected_parts.Count > 0)
                {
                    var selected_engines = new List <EngineWrapper>();
                    selected_parts.ForEach(p => find_engines_recursively(p, selected_engines));
                    ActiveEngines.AddRange(selected_engines);
                }
                if (ActiveEngines.Count > 0)
                {
                    ActiveEngines.ForEach(process_active_engine);
                    compute_inertia_tensor();
                    selected_parts.ForEach(update_inertia_tensor);
                    ActiveEngines.SortByRole();
                    float max_limit, torque_error, angle_error;
                    var   imbalance = TorqueProps.CalculateImbalance(true, ActiveEngines.Manual, ActiveEngines.UnBalanced);
                    if (ActiveEngines.Balanced.Count > 0)
                    {
                        EngineOptimizer.OptimizeLimitsForTorque(ActiveEngines.Balanced, Vector3.zero, imbalance, MoI, true,
                                                                out max_limit, out torque_error, out angle_error);
                        imbalance = TorqueProps.CalculateImbalance(true, ActiveEngines.Manual, ActiveEngines.UnBalanced, ActiveEngines.Balanced);
                    }
                    if (ActiveEngines.Steering.Count > 0)
                    {
                        if (!EngineOptimizer.OptimizeLimitsForTorque(ActiveEngines.Steering, Vector3.zero, imbalance, MoI, true,
                                                                     out max_limit, out torque_error, out angle_error))
                        {
                            ActiveEngines.Steering.ForEach(e => e.limit = 0);
                            ActiveEngines.Balanced.ForEach(e => e.limit = 0);
                        }
                    }
                    MinLimit = 1;
                    for (int i = 0, ActiveEnginesCount = ActiveEngines.Count; i < ActiveEnginesCount; i++)
                    {
                        var e = ActiveEngines[i];
                        thrust += e.wThrustDir * e.nominalCurrentThrust(e.limit);
                        if (e.Role != TCARole.MANUAL &&
                            e.Role != TCARole.MANEUVER &&
                            MinLimit > e.limit)
                        {
                            MinLimit = e.limit;
                        }
                        e.forceThrustPercentage(e.limit * 100);
                    }
                    var T = thrust.magnitude / Utils.G0;
                    MinTWR = T / Mass;
                    MaxTWR = T / DryMass;
                }
            }
        }