public bool Execute(Vector3d dV, float MinDeltaV = 0.1f, ManeuverCondition condition = null) { THR.Throttle = 0; dVrem.Value = dV.magnitude; //end if below the minimum dV if(dVrem < MinDeltaV) return false; VSL.Engines.ActivateEngines(); if(VSL.Engines.MaxThrustM.Equals(0)) return true; //orient along the burning vector if(dVrem && VSL.Controls.RCSAvailableInDirection(-dV)) CFG.AT.OnIfNot(Attitude.KillRotation); else { CFG.AT.OnIfNot(Attitude.Custom); ATC.SetThrustDirW(-dV); } //check the condition if(condition != null && !condition((float)dVrem)) return true; if(VSL.Controls.TranslationAvailable) { if(dVrem || VSL.Controls.AttitudeError > GLB.ATCB.AttitudeErrorThreshold) TRA.AddDeltaV(-VSL.LocalDir(dV)); if(dVrem && CFG.AT[Attitude.KillRotation]) { var errorF = Utils.ClampL(Vector3.Dot(VSL.Engines.Thrust.normalized, -dV.normalized), 0); THR.DeltaV = (float)dVrem * errorF*errorF; } else THR.DeltaV = (float)dVrem; } else THR.DeltaV = (float)dVrem; // Log("\ndVrem: {}\nAttitudeError {}, DeltaV: {}, Throttle {}, RCS {}", // dVrem, VSL.Controls.AttitudeError, THR.DeltaV, THR.Throttle, VSL.Controls.RCSAvailableInDirection(-dV));//debug return true; }
public bool Execute(Vector3d dV, float MinDeltaV = 0.1f, ManeuverCondition condition = null) { THR.Throttle = 0; dVrem.Value = dV.magnitude; //end if below the minimum dV if (dVrem < MinDeltaV) { return(false); } VSL.Engines.ActivateEngines(); //test: flameouted engines are automatically excluded from Active, //so this should work without this check; but this needs to be tested //in-game anyway with: MAN, REN, DEO // if(VSL.Engines.MaxThrustM.Equals(0)) // return VSL.Engines.HaveNextStageEngines; //orient along the burning vector if (dVrem && VSL.Controls.RCSAvailableInDirection(-dV)) { CFG.AT.OnIfNot(Attitude.KillRotation); } else { CFG.AT.OnIfNot(Attitude.Custom); ATC.SetThrustDirW(-dV); VSL.Engines.RequestClusterActivationForManeuver(-dV); } //check the condition if (condition != null && !condition((float)dVrem)) { return(true); } if (VSL.Controls.TranslationAvailable) { if (dVrem || VSL.Controls.AttitudeError > GLB.ATCB.AttitudeErrorThreshold) { TRA.AddDeltaV(-VSL.LocalDir(dV)); } if (dVrem && CFG.AT[Attitude.KillRotation]) { var errorF = Utils.ClampL(Vector3.Dot(VSL.Engines.Thrust.normalized, -dV.normalized), 0); THR.DeltaV = (float)dVrem * errorF * errorF; } else { THR.DeltaV = (float)dVrem; } } else { THR.DeltaV = (float)dVrem; } // Log("\ndVrem: {}\nAttitudeError {}, DeltaV: {}, Throttle {}, RCS {}", // dVrem, VSL.Controls.AttitudeError, THR.DeltaV, THR.Throttle, VSL.Controls.RCSAvailableInDirection(-dV));//debug return(true); }
public bool Execute(Vector3d dV, float MinDeltaV = 0.1f, ManeuverCondition condition = null) { THR.Throttle = 0; dVrem.Value = dV.magnitude; //end if below the minimum dV if (dVrem < MinDeltaV) { return(false); } VSL.Engines.ActivateEngines(); if (VSL.Engines.MaxThrustM.Equals(0)) { return(true); } //orient along the burning vector if (dVrem && VSL.Controls.RCSAvailableInDirection(-dV)) { CFG.AT.OnIfNot(Attitude.KillRotation); } else { CFG.AT.OnIfNot(Attitude.Custom); ATC.SetThrustDirW(-dV); } //check the condition if (condition != null && !condition((float)dVrem)) { return(true); } if (VSL.Controls.TranslationAvailable) { if (dVrem || VSL.Controls.AttitudeError > GLB.ATCB.AttitudeErrorThreshold) { TRA.AddDeltaV(-VSL.LocalDir(dV)); } if (dVrem && CFG.AT[Attitude.KillRotation]) { var errorF = Utils.ClampL(Vector3.Dot(VSL.Engines.Thrust.normalized, -dV.normalized), 0); THR.DeltaV = (float)dVrem * errorF * errorF; } else { THR.DeltaV = (float)dVrem; } } else { THR.DeltaV = (float)dVrem; } // Log("\ndVrem: {}\nAttitudeError {}, DeltaV: {}, Throttle {}, RCS {}", // dVrem, VSL.Controls.AttitudeError, THR.DeltaV, THR.Throttle, VSL.Controls.RCSAvailableInDirection(-dV));//debug return(true); }
public bool Execute(Vector3d dV, float MinDeltaV = 0.1f, ManeuverCondition condition = null) { THR.Throttle = 0; var has_correction = !course_correction.IsZero(); if (has_correction) { dV += course_correction; course_correction = Vector3d.zero; } dVrem.Lower = MinDeltaV * 5; dVrem.Upper = dVrem.Lower + 1; dVrem.Value = dV.magnitude; //prepare for the burn VSL.Engines.ActivateEngines(); //orient along the burning vector if (dVrem && VSL.Controls.RCSAvailableInDirection(-dV, (float)dVrem)) { CFG.AT.OnIfNot(Attitude.KillRotation); } else { CFG.AT.OnIfNot(Attitude.Custom); ATC.SetThrustDirW(-dV); } //check if need to be working if (!working) { VSL.Engines.RequestClusterActivationForManeuver(dV); working |= condition == null || condition((float)dVrem); } //end conditions for working execution if (working && !has_correction) { //end if below the minimum dV if (dVrem < MinDeltaV) { return(false); } //end if stalled stalled.Update(dVrem, VSL.Controls.AttitudeError); if (stalled) { return(false); } //prevent infinite dV tuning with inaccurate thrust-attitude systems if (StopAtMinimum) { if (dVrem) { VSL.Controls.GimbalLimit = 0; } if (dVmin < 0) { dVmin = dVrem; } else if (dVrem || !ThrustWhenAligned || VSL.Controls.Aligned) { if (dVrem < dVmin) { dVmin = dVrem; } else if (dVrem - dVmin > MinDeltaV) { return(false); } } } } //if not working and no correction, nothing left to do if (!working && !has_correction) { return(true); } //use translation controls if (VSL.Controls.TranslationAvailable && (dVrem || VSL.Controls.AttitudeError > AttitudeControlBase.C.AttitudeErrorThreshold)) { TRA.AddDeltaV(-VSL.LocalDir(dV)); } //use main throttle if (ThrustWhenAligned) { THR.MaxThrottle = VSL.Controls.Aligned ? VSL.Engines.MaxThrottleForDeltaV(dV) : 0; } THR.CorrectThrottle = ThrustWhenAligned; THR.DeltaV = (float)dVrem; return(true); }
public bool Execute(Vector3d dV, float MinDeltaV = 0.1f, ManeuverCondition condition = null) { THR.Throttle = 0; var has_correction = !course_correction.IsZero(); if (has_correction) { dV += course_correction; course_correction = Vector3d.zero; } dVrem.Lower = MinDeltaV * 5; dVrem.Upper = dVrem.Lower + 1; dVrem.Value = dV.magnitude; //end if below the minimum dV if (dVrem < MinDeltaV) { return(false); } VSL.Engines.ActivateEngines(); //orient along the burning vector if (dVrem && VSL.Controls.RCSAvailableInDirection(-dV)) { CFG.AT.OnIfNot(Attitude.KillRotation); } else { CFG.AT.OnIfNot(Attitude.Custom); ATC.SetThrustDirW(-dV); } if (!working) { VSL.Engines.RequestClusterActivationForManeuver(dV); if (!has_correction && condition != null && !condition((float)dVrem)) { return(true); } working = true; } //prevent infinite dV tuning with inaccurate thrust-attitude systems if (StopAtMinimum) { if (dVrem) { VSL.Controls.GimbalLimit = 0; } if (dVmin < 0) { dVmin = dVrem; ddV.Set(dVmin); } else if (!ThrustWhenAligned || VSL.Controls.Aligned) { ddV.Update(Math.Max(dVmin - dVrem, 0) / TimeWarp.fixedDeltaTime); // Log("dVrem {}, dVmin {}, ddV {}, aliF {}, aliE {}", // dVrem.Value, dVmin, // ddV, VSL.Controls.AlignmentFactor, VSL.Controls.AttitudeError);//debug if (ddV < MinDeltaV) { return(false); } if (dVrem < dVmin) { dVmin = dVrem; } else if (dVrem - dVmin > MinDeltaV) { return(false); } } } //use translation controls if (VSL.Controls.TranslationAvailable) { if (dVrem || VSL.Controls.AttitudeError > GLB.ATCB.AttitudeErrorThreshold) { TRA.AddDeltaV(-VSL.LocalDir(dV)); } if (dVrem && CFG.AT[Attitude.KillRotation]) { var errorF = Utils.ClampL(Vector3.Dot(VSL.Engines.Thrust.normalized, -dV.normalized), 0); THR.DeltaV = (float)dVrem * errorF * errorF; return(true); } } //use main throttle if (ThrustWhenAligned) { THR.DeltaV = VSL.Controls.Aligned ? (float)dVrem * VSL.Controls.AlignmentFactor : 0; } else { THR.DeltaV = (float)dVrem; } return(true); }