示例#1
0
    private MagnetWindowState CaptureMagnetWindow()
    {
        MagnetWindowState newState = new MagnetWindowState();
        int middle = magnetWindow.Count / 2;
        List <MagnetMoment> firstHalf = magnetWindow.GetRange(0, middle);
        List <MagnetMoment> lastHalf  = magnetWindow.GetRange(middle, magnetWindow.Count - middle);

        newState.ratio = Average(firstHalf) / Average(lastHalf);
        newState.delta = Mathf.Abs(magnetWindow[magnetWindow.Count - 1].yMagnitude - magnetWindow[0].yMagnitude);
        return(newState);
    }
  public void Update() {
    TrimMagnetWindow();
    AddToMagnetWindow();
    currentMagnetWindow = CaptureMagnetWindow();

    TriggerState newTriggerState = CheckTriggerState();
    isStable = CheckStability();
    if (!isStable) ResetState();

    if (isStable && newTriggerState != TriggerState.Neutral && triggerState != newTriggerState) {
      isDown = !isDown;
      triggerState = newTriggerState;
    }
  }
        // -- private methods --

        /// <summary>
        /// Captures current magnet state by checking the magnet window.
        /// Note that the tail of the window is always updated by AddToMagnetWindow().
        /// The ratio of Current State = AverageYMagnitude(firstHalf) / AverageYMagnitude(lastHalf).
        /// </summary>
        /// <returns>The current magnet window.</returns>
        private MagnetWindowState CaptureMagnetWindow()
        {
            MagnetWindowState newState = new MagnetWindowState();
            int midIndex = magnetWindow.Count / 2;
            List <MagnetMoment> firstHalf = magnetWindow.GetRange(0, midIndex);
            // lastHalf has at least one member and its yMagnitude should be > 0!
            List <MagnetMoment> lastHalf = magnetWindow.GetRange(midIndex, magnetWindow.Count - midIndex);

            newState.ratio = AverageYMagnitude(firstHalf) / AverageYMagnitude(lastHalf);
            newState.delta = Mathf.Abs(magnetWindow[magnetWindow.Count - 1].yMagnitude
                                       - magnetWindow[0].yMagnitude);

            return(newState);
        }
示例#4
0
    public void Update()
    {
        TrimMagnetWindow();
        AddToMagnetWindow();
        currentMagnetWindow = CaptureMagnetWindow();

        TriggerState newTriggerState = CheckTriggerState();

        isStable = CheckStability();
        if (!isStable)
        {
            ResetState();
        }

        if (isStable && newTriggerState != TriggerState.Neutral && triggerState != newTriggerState)
        {
            isDown       = !isDown;
            triggerState = newTriggerState;
        }
    }
 private MagnetWindowState CaptureMagnetWindow() {
   MagnetWindowState newState = new MagnetWindowState();
   int middle = magnetWindow.Count / 2;
   List<MagnetMoment> firstHalf = magnetWindow.GetRange(0, middle);
   List<MagnetMoment> lastHalf = magnetWindow.GetRange(middle, magnetWindow.Count - middle);
   newState.ratio = Average(firstHalf) / Average(lastHalf);
   newState.delta = Mathf.Abs(magnetWindow[magnetWindow.Count-1].yMagnitude - magnetWindow[0].yMagnitude);
   return newState;
 }
        // -- private methods --
        /// <summary>
        /// Captures current magnet state by checking the magnet window.
        /// Note that the tail of the window is always updated by AddToMagnetWindow().
        /// The ratio of Current State = AverageYMagnitude(firstHalf) / AverageYMagnitude(lastHalf).
        /// </summary>
        /// <returns>The current magnet window.</returns>
        private MagnetWindowState CaptureMagnetWindow()
        {
            MagnetWindowState newState = new MagnetWindowState();
            int midIndex = magnetWindow.Count / 2;
            List<MagnetMoment> firstHalf = magnetWindow.GetRange(0, midIndex);
            // lastHalf has at least one member and its yMagnitude should be > 0!
            List<MagnetMoment> lastHalf = magnetWindow.GetRange(midIndex, magnetWindow.Count - midIndex);
            newState.ratio = AverageYMagnitude(firstHalf) / AverageYMagnitude(lastHalf);
            newState.delta = Mathf.Abs(magnetWindow[magnetWindow.Count-1].yMagnitude
                                       - magnetWindow[0].yMagnitude);

            return newState;
        }