CSharpRoboticsLib.ControlSystems.SetPointProfile.Get C# (CSharp) Метод

Get() публичный Метод

Get the value of the path at the current point
public Get ( double currentPoint ) : double
currentPoint double point along the profile to measure
Результат double
        public double Get(double currentPoint)
        {
            //be warned: here be lots of math
            Setpoint next = NearestGreater(currentPoint);
            Setpoint prev = NearestLess(currentPoint);

            double direction = Math.Sign(SetPoint - currentPoint);

            if (next.Point == prev.Point) //If they are the EXACT same point
            {
                return next.Value * direction;
            }

            double setpointSlope = (prev.Value - next.Value)/(prev.Point - next.Point);
            setpointSlope = double.IsNaN(setpointSlope) ? 0 : setpointSlope; //Handle division by zero

            double ratioComplete = (currentPoint - prev.Point)/(next.Point - prev.Point);
            ratioComplete = double.IsNaN(ratioComplete) ? 0 : ratioComplete; //Handle division by zero

            double delta = ratioComplete*setpointSlope;
            return (delta + prev.Value) * direction;
        }

Usage Example

        public static void SetpointProfileTest()
        {
            SetPointProfile p = new SetPointProfile();
            p.Add(0, 0);
            p.Add(1, 1);
            p.SetPoint = 100;

            //Assert.AreEqual(0, p.Get(-0.1));
            Assert.AreEqual(0.1, p.Get(0.1));
            Assert.AreEqual(0.9, p.Get(0.9));
            Assert.AreEqual(0.5, p.Get(0.5));
            Assert.AreEqual(1, p.Get(1.5));

            //Reverse
            p.SetPoint = -100;

            Assert.AreEqual(0, p.Get(0));
            Assert.AreEqual(-1, p.Get(1));
            Assert.AreEqual(-0.5, p.Get(0.5));
        }