CSharpRoboticsLib.Utility.Derivative.Get C# (CSharp) Method

Get() public method

Gets dx/dt
public Get ( double x ) : double
x double
return double
        public double Get(double x)
        {
            double toReturn = (x - m_xPrev) / m_dt.Value;

            //Handle division by zero errors, ignoring the input if there is no change in time.
            if (double.IsNaN(toReturn))
            {
                toReturn = 0;
            }
            else
            {
                m_xPrev = x;
            }

            return toReturn;
        }

Usage Example

 public void DerivativePositiveTest10Hz()
 {
     Derivative d = new Derivative(0);
     d.Dt = 0.1;
     Assert.AreEqual(0, d.Get(0), double.Epsilon);
     for (int i = 0; i < TestRepeats; i++)
     {
         //Utility.AccurateWaitSeconds(0.1);
         Assert.AreEqual(1, d.Get(0.1 * (i + 1)), AcceptibleError);
     }
 }