Example #1
0
 /// <summary>
 /// Creates a <see cref="DoubleSchmittTriggerInput"/> object which maps a target <see cref="IDoubleInput"/> to a
 /// boolean using a threshold.
 /// </summary>
 /// <param name="source">The source input to be mapped from double to boolean.</param>
 /// <param name="threshold">The threshold above which <see cref="Value"/> shall return true, and below which
 /// it shall return false. This can by any number.</param>
 /// <param name="hysteresis">The range that the source value must be above/below the last value in order to
 /// change the resulting value. This must not be negative.</param>
 /// <returns>The mapped boolean input.</returns>
 /// <remarks>Example: Use 0.5 as <paramref name="threshold"/> and 0.1 as <paramref name="hysteresis"/>. The
 /// following sequence of source input values, in the given order, will then result in the following resulting
 /// values: 0.0 -> false, 1.0 -> true, 0.6 -> true, 0.5 -> true, 0.4 -> true, 0.3 -> false, 0.4 -> false,
 /// 0.5 -> false, 0.6 -> false, 0.7 -> true.</remarks>
 public static DoubleSchmittTriggerInput SchmittTrigger(
     this IDoubleInput source,
     double threshold,
     double hysteresis)
 {
     return(new DoubleSchmittTriggerInput(source, threshold, hysteresis));
 }
Example #2
0
 /// <summary>
 /// Creates a <see cref="DoubleScaleToRangeInput"/> object scaling the values of this input to a specific numeric
 /// range.
 /// </summary>
 /// <param name="source">The source input to be scaled.</param>
 /// <param name="smallestValueMappedTo">The value that the smallest source input value will be mapped to.
 /// </param>
 /// <param name="largestValueMappedTo">The value that the largest source input value will be mapped to.</param>
 /// <remarks><paramref name="smallestValueMappedTo"/> may well be larger than
 /// <paramref name="largestValueMappedTo"/>. In this case the mapping will output a larger value for smaller
 /// source values, and you can, vor example, turn the sign of an input ranging from -1.0 to +1.0 into the
 /// resulting range +1.0 to -1.0. However, <paramref name="smallestValueMappedTo"/> must not be equal to
 /// <paramref name="largestValueMappedTo"/>.</remarks>
 /// <returns>The scaled input.</returns>
 public static DoubleScaleToRangeInput ScaleToRange(
     this IDoubleInput source,
     double smallestValueMappedTo,
     double largestValueMappedTo)
 {
     return(new DoubleScaleToRangeInput(source, smallestValueMappedTo, largestValueMappedTo));
 }
Example #3
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="sourceInput">The input whose analog value shall be mapped to a boolean value.</param>
        /// <param name="threshold">The threshold above which <see cref="Value"/> shall return true, and below which
        /// it shall return false. This can by any number.</param>
        /// <param name="hysteresis">The range that the source value must be above/below the last value in order to
        /// change the resulting value. This must not be negative.</param>
        /// <remarks>Example: Use 0.5 as <paramref name="threshold"/> and 0.1 as <paramref name="hysteresis"/>. The
        /// following sequence of source input values, in the given order, will then result in the following resulting
        /// values: 0.0 -> false, 1.0 -> true, 0.6 -> true, 0.5 -> true, 0.4 -> true, 0.3 -> false, 0.4 -> false,
        /// 0.5 -> false, 0.6 -> false, 0.7 -> true.</remarks>
        public DoubleSchmittTriggerInput(IDoubleInput sourceInput, double threshold, double hysteresis)
        {
            _sourceInput = sourceInput ?? throw new ArgumentNullException(nameof(sourceInput));
            if (hysteresis < 0.0)
            {
                throw new ArgumentOutOfRangeException(nameof(hysteresis));
            }

            hysteresis     = hysteresis / 2.0;
            _lowThreshold  = threshold - hysteresis;
            _highThreshold = threshold + hysteresis;
        }
Example #4
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="source">The input whose value shall be mapped.</param>
        /// <param name="smallestValueMappedTo">The value that the smallest source input value will be mapped to.
        /// </param>
        /// <param name="largestValueMappedTo">The value that the largest source input value will be mapped to.</param>
        /// <remarks><paramref name="smallestValueMappedTo"/> may well be larger than
        /// <paramref name="largestValueMappedTo"/>. In this case the mapping will output a larger value for smaller
        /// source values, and you can, vor example, turn the sign of an input ranging from -1.0 to +1.0 into the
        /// resulting range +1.0 to -1.0. However, <paramref name="smallestValueMappedTo"/> must not be equal to
        /// <paramref name="largestValueMappedTo"/>.</remarks>
        public DoubleScaleToRangeInput(IDoubleInput source, double smallestValueMappedTo, double largestValueMappedTo)
        {
            _source = source ?? throw new ArgumentNullException(nameof(source));

            if (smallestValueMappedTo == largestValueMappedTo)
            {
                throw new ArgumentException(
                          nameof(smallestValueMappedTo) + " must not be equal to " + nameof(largestValueMappedTo) + ".");
            }

            _smallestValueMappedTo = smallestValueMappedTo;
            _largestValueMappedTo  = largestValueMappedTo;
            _sourceMinimum         = double.MaxValue;
            _sourceMaximum         = double.MinValue;
        }