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; } }
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 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() { //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; } }