/// <summary> /// Attempt to perform the next stride in the list /// </summary> /// <param name="cycleTime">The current cycle time</param> /// <returns>True if the next stride has started, false otherwise</returns> public bool AttemptNextStride(float cycleTime) { bool strideStarted = false; if (!IsStriding && _nextStrideIndex < _strides.Count) { if (_strides[_nextStrideIndex].Within(cycleTime)) { float startTime = 0.0f; //May do something with this in the future float availableStrideTime = _strides[_nextStrideIndex].End - cycleTime; if (availableStrideTime >= _strides[_nextStrideIndex].StrideLength * MIN_STRIDE_PERCENT) { int next = (_nextStrideIndex + 1) % _strides.Count; _nextStanceDuration = GaitStride.StanceLength(_strides[_nextStrideIndex], _strides[next]); float stanceOffsetScale = _nextStanceDuration / LongestStance; //Trigger Stride BeginStride(0.0f, Height + PeakHeight, MAX_DISPLACEMENT * stanceOffsetScale, availableStrideTime + startTime, startTime); _nextStrideIndex += 1; strideStarted = true; } else { _nextStrideIndex += 1; Debug.Log("Stride Skipped"); } } } return(strideStarted); }
/// <summary> /// Calculates the duration of the longest stance any leg in this gait will experience /// </summary> /// <returns>The maximum stance</returns> public float MaxStance() { float maxStance = 0.0f; foreach (List <GaitStride> strides in _strideSets) { for (int i = 0; i < strides.Count; i++) { int next = (i + 1) % strides.Count; maxStance = Mathf.Max(GaitStride.StanceLength(strides[i], strides[next]), maxStance); } } return(maxStance); }
//-------------------------------------------------- // Methods //-------------------------------------------------- /// <summary> /// Assign a new list of strides to this channel /// </summary> /// <param name="newStrides">The strides to assign, replacing the current list of strides</param> /// <param name="cycleTime">The current cycle time</param> public void AssignStrides(List <GaitStride> newStrides, float cycleTime) { _strides = new List <GaitStride>(newStrides); _nextStrideIndex = 0; //Depending on the cycle time, the first stride may not be the best one to start with do { //Check if the stride start has already been passed GaitStride nextStride = _strides[_nextStrideIndex % _strides.Count]; _nextStanceDuration = nextStride.Start - cycleTime; if (_nextStanceDuration < 0.0f) { //If the stride isn't one cycle ahead if (_nextStrideIndex < _strides.Count) { //See if there's enough time to do a worthwhile stride float availableStrideTime = nextStride.End - cycleTime; if (availableStrideTime >= nextStride.StrideLength * MIN_STRIDE_PERCENT) { _nextStanceDuration = 0.0f; //There is so zero the stance duration } else { _nextStrideIndex++; //There isn't so move on to the next stride } } else { //We're back to the first stride so add a whole cycle to the stance preceding it _nextStanceDuration += 1.0f; } } } while (_nextStanceDuration < 0.0f); LongestStance = 0.0f; for (int i = 0; i < _strides.Count; i++) { int next = (i + 1) % _strides.Count; LongestStance = Mathf.Max(GaitStride.StanceLength(_strides[i], _strides[next]), LongestStance); } NextAvailableStancePercent = _nextStanceDuration / (Displacement + MAX_DISPLACEMENT); }