public static ScalarValue Multiply(ScalarValue val1, ScalarValue val2) { return Create(val1.GetDoubleValue() * val2.GetDoubleValue()); }
public static bool GreaterThan(ScalarValue val1, ScalarValue val2) { return val1.GetDoubleValue() > val2.GetDoubleValue(); }
public static ScalarValue Min(ScalarValue val1, ScalarValue val2) { return Create(Math.Min(val1.GetDoubleValue(), val2.GetDoubleValue())); }
public ScalarValue GetMaxThrustAtAtm(ScalarValue atmPressure) { return engine.MaxThrustAtAtm(atmPressure); }
public static ScalarValue Add(ScalarValue val1, ScalarValue val2) { return Create(val1.GetDoubleValue() + val2.GetDoubleValue()); }
public ScalarValue GetMaxThrustAt(ScalarValue atmPressure) { return VesselUtils.GetMaxThrust(Vessel, atmPressure); }
public void MoveTo(ScalarValue position, ScalarValue speed) { servo.MoveTo(position, speed); }
public static ScalarValue Divide(ScalarValue val1, ScalarValue val2) { return(Create(val1.GetDoubleValue() / val2.GetDoubleValue())); }
public static ScalarValue Power(ScalarValue val1, ScalarValue val2) { return(Create(Math.Pow(val1.GetDoubleValue(), val2.GetDoubleValue()))); }
public static ScalarValue Subtract(ScalarValue val1, ScalarValue val2) { return(Create(val1.GetDoubleValue() - val2.GetDoubleValue())); }
public static ScalarValue Multiply(ScalarValue val1, ScalarValue val2) { return(Create(val1.GetDoubleValue() * val2.GetDoubleValue())); }
public static ScalarValue Add(ScalarValue val1, ScalarValue val2) { return(Create(val1.GetDoubleValue() + val2.GetDoubleValue())); }
public ScalarValue Update(ScalarValue sampleTime, ScalarValue input) { double error = Setpoint - input; if (error > -Epsilon && error < Epsilon) { // Pretend there is no error (get everything to zero out) // because the error is within the epsilon: error = 0; input = Setpoint; Input = input; Error = error; } double pTerm = error * Kp; double iTerm = 0; double dTerm = 0; if (LastSampleTime < sampleTime) { double dt = sampleTime - LastSampleTime; if (Ki != 0) { if (ExtraUnwind) { if (Math.Sign(error) != Math.Sign(ErrorSum)) { if (!unWinding) { Ki *= 2; unWinding = true; } } else if (unWinding) { Ki /= 2; unWinding = false; } } iTerm = ITerm + error * dt * Ki; } ChangeRate = (input - Input) / dt; if (Kd != 0) { dTerm = -ChangeRate * Kd; } } else { dTerm = DTerm; iTerm = ITerm; } Output = pTerm + iTerm + dTerm; if (Output > MaxOutput) { Output = MaxOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Min(pTerm + dTerm, MaxOutput); } } if (Output < MinOutput) { Output = MinOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Max(pTerm + dTerm, MinOutput); } } LastSampleTime = sampleTime; Input = input; Error = error; PTerm = pTerm; ITerm = iTerm; DTerm = dTerm; if (Ki != 0) { ErrorSum = iTerm / Ki; } else { ErrorSum = 0; } return(Output); }
public ScalarValue Update(ScalarValue sampleTime, ScalarValue input) { double error = Setpoint - input; double pTerm = error * Kp; double iTerm = 0; double dTerm = 0; if (LastSampleTime < sampleTime) { double dt = sampleTime - LastSampleTime; if (Ki != 0) { if (ExtraUnwind) { if (Math.Sign(error) != Math.Sign(ErrorSum)) { if (!unWinding) { Ki *= 2; unWinding = true; } } else if (unWinding) { Ki /= 2; unWinding = false; } } iTerm = ITerm + error * dt * Ki; } ChangeRate = (input - Input) / dt; if (Kd != 0) { dTerm = -ChangeRate * Kd; } } else { dTerm = DTerm; iTerm = ITerm; } Output = pTerm + iTerm + dTerm; if (Output > MaxOutput) { Output = MaxOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Min(pTerm + dTerm, MaxOutput); } } if (Output < MinOutput) { Output = MinOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Max(pTerm + dTerm, MinOutput); } } LastSampleTime = sampleTime; Input = input; Error = error; PTerm = pTerm; ITerm = iTerm; DTerm = dTerm; if (Ki != 0) { ErrorSum = iTerm / Ki; } else { ErrorSum = 0; } return(Output); }
public static ScalarValue Subtract(ScalarValue val1, ScalarValue val2) { return Create(val1.GetDoubleValue() - val2.GetDoubleValue()); }
public static bool GreaterThan(ScalarValue val1, ScalarValue val2) { return(val1.GetDoubleValue() > val2.GetDoubleValue()); }
public static bool TryParseDouble(string str, out ScalarValue result) { result = null; // default the out value to null str = trimPattern.Replace(str, "E"); // remove white space around "e" double val; if (double.TryParse(str, out val)) { // use Create instead of new ScalarDoubleValue so doubles that // represent integers will output a ScalarIntValue instead result = Create(val); return true; } return false; }
public static bool LessThan(ScalarValue val1, ScalarValue val2) { return(val1.GetDoubleValue() < val2.GetDoubleValue()); }
/// <summary> /// The pair of velocities representing this spot's velocity due to /// planetary rotation, at this (sea level) altitude: /// </summary> /// <returns>velocities pair </returns> public OrbitableVelocity GetAltitudeVelocities(ScalarValue altitude) { Vector3d pos = Body.GetWorldSurfacePosition(Latitude, Longitude, altitude); Vector3d vel = Body.getRFrmVel(pos); CelestialBody shipBody = Shared.Vessel.orbit.referenceBody; if (shipBody == null) return new OrbitableVelocity(new Vector(vel), new Vector(vel)); Vector3d srfVel = vel - shipBody.getRFrmVel(Shared.Vessel.CoMD); return new OrbitableVelocity(new Vector(vel), new Vector(srfVel)); }
public static ScalarValue Min(ScalarValue val1, ScalarValue val2) { return(Create(Math.Min(val1.GetDoubleValue(), val2.GetDoubleValue()))); }
public ScalarValue GetIspAtAtm(ScalarValue atmPressure) { return engine.IspAtAtm(atmPressure); }
public static ScalarValue Abs(ScalarValue val) { return(Create(Math.Abs(val.GetDoubleValue()))); }
public static ScalarValue Abs(ScalarValue val) { return Create(Math.Abs(val.GetDoubleValue())); }
public string Substring(ScalarValue start, ScalarValue count) { return(internalString.Substring(start, count)); }
public static ScalarValue Divide(ScalarValue val1, ScalarValue val2) { return Create(val1.GetDoubleValue() / val2.GetDoubleValue()); }
// IndexOf with a start position. // This was named FindAt because IndexOfAt made little sense. public ScalarValue FindAt(string s, ScalarValue start) { return(internalString.IndexOf(s, start, StringComparison.OrdinalIgnoreCase)); }
public static bool LessThan(ScalarValue val1, ScalarValue val2) { return val1.GetDoubleValue() < val2.GetDoubleValue(); }
public string Insert(ScalarValue location, string s) { return(internalString.Insert(location, s)); }
public static ScalarValue Modulus(ScalarValue val1, ScalarValue val2) { if (val1.IsInt && val2.IsInt) { return Create(val1.GetIntValue() % val2.GetIntValue()); } return Create(val1.GetDoubleValue() % val2.GetDoubleValue()); }
// Set the rate to the nearest rate to the value given that the user interface // normally allows. (i.e. if you tell it to set the rate to 90x, it will round // to 100x) Note that the underlying API allows any in-between warp value, but // in keeping with the philosophy that kOS should only allow the user to do things // they could have done manually, we'll clamp it to the user interface's allowed // rates: public void SetRate(ScalarValue desiredRate) { float wantRate = desiredRate; float[] rateArray = GetRateArrayForMode(TimeWarp.WarpMode); // Walk the list of possible rates, settling on the one // that is closest to the desired rate (has smallest error // difference): float error = float.MaxValue; int index; for (index = 0; index < rateArray.Length; ++index) { float nextError = Mathf.Abs(wantRate - rateArray[index]); if (nextError > error) break; error = nextError; } SetWarpRate(index - 1, rateArray.Length - 1); }
public static ScalarValue Power(ScalarValue val1, ScalarValue val2) { return Create(Math.Pow(val1.GetDoubleValue(), val2.GetDoubleValue())); }
public void WarpTo(ScalarValue timeStamp) { TimeWarp.fetch.WarpTo(timeStamp.GetDoubleValue()); }
public static bool TryParse(string str, out ScalarValue result) { result = null; // default the out value to null bool needsDoubleParse = str.IndexOfAny(doubleCharacters) >= 0; if (needsDoubleParse) { return TryParseDouble(str, out result); } else { return TryParseInt(str, out result); } }
private PartModuleFields GetModuleIndex(ScalarValue moduleIndex) { if (moduleIndex < Part.Modules.Count) { return PartModuleFieldsFactory.Construct(Part.Modules.GetModule(moduleIndex), Shared); } throw new KOSLookupFailException("module", string.Format("MODULEINDEX[{0}]", moduleIndex), this); }
public static bool TryParseInt(string str, out ScalarValue result) { result = null; // default the out value to null int val; if (int.TryParse(str, out val)) { result = new ScalarIntValue(val); return true; } return false; }
public void MoveTo(ScalarValue position, ScalarValue speed) { partValue.ThrowIfNotCPUVessel(); servo.MoveTo(position, speed); }
/// <summary> /// The point above or below the surface of this LAT/LONG from where /// the current CPU vessel is now. /// </summary> /// <param name="altitude">The (sea level) altitude to get a position for</param>> /// <returns>position vector</returns> public Vector GetAltitudePosition(ScalarValue altitude) { Vector3d latLongCoords = Body.GetWorldSurfacePosition(Latitude, Longitude, altitude); Vector3d hereCoords = Shared.Vessel.CoMD; return new Vector(latLongCoords - hereCoords); }
public ScalarValue GetAvailableThrustAtAtm(ScalarValue atmPressure) { return engine.AvailableThrustAtAtm(atmPressure); }
public ScalarValue Update(ScalarValue sampleTime, ScalarValue input) { double error = Setpoint - input; double pTerm = error * Kp; double iTerm = 0; double dTerm = 0; if (LastSampleTime < sampleTime) { double dt = sampleTime - LastSampleTime; if (Ki != 0) { if (ExtraUnwind) { if (Math.Sign(error) != Math.Sign(ErrorSum)) { if (!unWinding) { Ki *= 2; unWinding = true; } } else if (unWinding) { Ki /= 2; unWinding = false; } } iTerm = ITerm + error * dt * Ki; } ChangeRate = (input - Input) / dt; if (Kd != 0) { dTerm = -ChangeRate * Kd; } } else { dTerm = DTerm; iTerm = ITerm; } Output = pTerm + iTerm + dTerm; if (Output > MaxOutput) { Output = MaxOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Min(pTerm + dTerm, MaxOutput); } } if (Output < MinOutput) { Output = MinOutput; if (Ki != 0 && LastSampleTime < sampleTime) { iTerm = Output - Math.Max(pTerm + dTerm, MinOutput); } } LastSampleTime = sampleTime; Input = input; Error = error; PTerm = pTerm; ITerm = iTerm; DTerm = dTerm; if (Ki != 0) ErrorSum = iTerm / Ki; else ErrorSum = 0; return Output; }
private void CannotSetWidth(ScalarValue newWidth) { throw new kOS.Safe.Exceptions.KOSTermWidthObsoletionException("1.1"); }