protected override bool StopLoop() { float average; if (setAverage) { movingAverage.FillWindow(currentError); setAverage = false; } else { movingAverage.Update(currentError); } average = movingAverage.GetAverage(); if (average <= 1.0f && average >= -1.0f) { if (brake) { motor.Brake(); } else { motor.SetPower(0); } setAverage = true; return(true); } bool errorOk = currentError == 0; bool outputOk = currentOutput == 0; return(errorOk && outputOk); }
protected override bool StopLoop() { //Console.WriteLine("CurrentError: " + currentError); //Console.WriteLine("CurrentOutput: " + currentOutput); float average; if (setAverage) { movingAverage.FillWindow(currentError); setAverage = false; LcdConsole.WriteLine("Current error:" + currentError.ToString()); LcdConsole.WriteLine("Set average:" + setAverage); //Console.WriteLine("Set average"); } else { movingAverage.Update(currentError); } average = movingAverage.GetAverage(); //Console.WriteLine("Average: " + average); if (average <= 5.0f && average >= -5.0f) { //Console.WriteLine("Within limits"); //Console.WriteLine("Average " + average); if (brake) { motor.Brake(); } else { motor.SetPower(0); } setAverage = true; return(true); } return(false); /*bool errorOk = currentError == 0; * //Console.WriteLine("Error ok:" + errorOk); * bool outputOk = currentOutput == 0; * //Console.WriteLine("output ok:" + outputOk); * return errorOk && outputOk;*/ }