Inheritance: PrimitiveStructure, IConvertible
Example #1
0
 public static ScalarValue Multiply(ScalarValue val1, ScalarValue val2)
 {
     return Create(val1.GetDoubleValue() * val2.GetDoubleValue());
 }
Example #2
0
 public static bool GreaterThan(ScalarValue val1, ScalarValue val2)
 {
     return val1.GetDoubleValue() > val2.GetDoubleValue();
 }
Example #3
0
 public static ScalarValue Min(ScalarValue val1, ScalarValue val2)
 {
     return Create(Math.Min(val1.GetDoubleValue(), val2.GetDoubleValue()));
 }
Example #4
0
 public ScalarValue GetMaxThrustAtAtm(ScalarValue atmPressure)
 {
     return engine.MaxThrustAtAtm(atmPressure);
 }
Example #5
0
 public static ScalarValue Add(ScalarValue val1, ScalarValue val2)
 {
     return Create(val1.GetDoubleValue() + val2.GetDoubleValue());
 }
Example #6
0
 public ScalarValue GetMaxThrustAt(ScalarValue atmPressure)
 {
     return VesselUtils.GetMaxThrust(Vessel, atmPressure);
 }
Example #7
0
 public void MoveTo(ScalarValue position, ScalarValue speed)
 {
     servo.MoveTo(position, speed);
 }
Example #8
0
 public static ScalarValue Divide(ScalarValue val1, ScalarValue val2)
 {
     return(Create(val1.GetDoubleValue() / val2.GetDoubleValue()));
 }
Example #9
0
 public static ScalarValue Power(ScalarValue val1, ScalarValue val2)
 {
     return(Create(Math.Pow(val1.GetDoubleValue(), val2.GetDoubleValue())));
 }
Example #10
0
 public static ScalarValue Subtract(ScalarValue val1, ScalarValue val2)
 {
     return(Create(val1.GetDoubleValue() - val2.GetDoubleValue()));
 }
Example #11
0
 public static ScalarValue Multiply(ScalarValue val1, ScalarValue val2)
 {
     return(Create(val1.GetDoubleValue() * val2.GetDoubleValue()));
 }
Example #12
0
 public static ScalarValue Add(ScalarValue val1, ScalarValue val2)
 {
     return(Create(val1.GetDoubleValue() + val2.GetDoubleValue()));
 }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
 public static ScalarValue Subtract(ScalarValue val1, ScalarValue val2)
 {
     return Create(val1.GetDoubleValue() - val2.GetDoubleValue());
 }
Example #16
0
 public static bool GreaterThan(ScalarValue val1, ScalarValue val2)
 {
     return(val1.GetDoubleValue() > val2.GetDoubleValue());
 }
Example #17
0
 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;
 }
Example #18
0
 public static bool LessThan(ScalarValue val1, ScalarValue val2)
 {
     return(val1.GetDoubleValue() < val2.GetDoubleValue());
 }
Example #19
0
 /// <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));
 }
Example #20
0
 public static ScalarValue Min(ScalarValue val1, ScalarValue val2)
 {
     return(Create(Math.Min(val1.GetDoubleValue(), val2.GetDoubleValue())));
 }
Example #21
0
 public ScalarValue GetIspAtAtm(ScalarValue atmPressure)
 {
     return engine.IspAtAtm(atmPressure);
 }
Example #22
0
 public static ScalarValue Abs(ScalarValue val)
 {
     return(Create(Math.Abs(val.GetDoubleValue())));
 }
Example #23
0
 public static ScalarValue Abs(ScalarValue val)
 {
     return Create(Math.Abs(val.GetDoubleValue()));
 }
Example #24
0
 public string Substring(ScalarValue start, ScalarValue count)
 {
     return(internalString.Substring(start, count));
 }
Example #25
0
 public static ScalarValue Divide(ScalarValue val1, ScalarValue val2)
 {
     return Create(val1.GetDoubleValue() / val2.GetDoubleValue());
 }
Example #26
0
 // 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));
 }
Example #27
0
 public static bool LessThan(ScalarValue val1, ScalarValue val2)
 {
     return val1.GetDoubleValue() < val2.GetDoubleValue();
 }
Example #28
0
 public string Insert(ScalarValue location, string s)
 {
     return(internalString.Insert(location, s));
 }
Example #29
0
 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());
 }
Example #30
0
        // 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);
        }
Example #31
0
 public static ScalarValue Power(ScalarValue val1, ScalarValue val2)
 {
     return Create(Math.Pow(val1.GetDoubleValue(), val2.GetDoubleValue()));
 }
Example #32
0
 public void WarpTo(ScalarValue timeStamp)
 {
     TimeWarp.fetch.WarpTo(timeStamp.GetDoubleValue());
 }
Example #33
0
        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);
            }
        }
Example #34
0
 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);
 }
Example #35
0
 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;
 }
Example #36
0
 public void MoveTo(ScalarValue position, ScalarValue speed)
 {
     partValue.ThrowIfNotCPUVessel();
     servo.MoveTo(position, speed);
 }
Example #37
0
 /// <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);
 }
Example #38
0
 public ScalarValue GetAvailableThrustAtAtm(ScalarValue atmPressure)
 {
     return engine.AvailableThrustAtAtm(atmPressure);
 }
Example #39
0
 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;
 }
Example #40
0
 private void CannotSetWidth(ScalarValue newWidth)
 {
     throw new kOS.Safe.Exceptions.KOSTermWidthObsoletionException("1.1");
 }