// using this fixture test case macro resets the fixture BOOST_FIXTURE_TEST_CASE(just_proportional_cooling, PidTest) { pid->setConstants(10.0, 0, 0); pid->setActuatorIsNegative(true); sp->write(19.0); sensor->setTemp(20.0); pid->update(); BOOST_CHECK_EQUAL(act->getValue(), temp_t(10.0)); // now try changing the temperature input sensor->setTemp(22.0); pid->update(); // inputs are filtered, so output should still be close to the old value BOOST_CHECK_CLOSE(double(act->getValue()), 10.0, 1); for(int i = 0; i<100; i++){ pid->update(); act->update(); } // after a enough updates, filters have settled and new PID value is Kp*error BOOST_CHECK_CLOSE(double(act->getValue()), 30.0, 1); }
BOOST_FIXTURE_TEST_CASE(proportional_plus_derivative_cooling, PidTest) { pid->setConstants(10.0, 0, 60); pid->setActuatorIsNegative(true); sp->write(5.0); // update for 10 minutes for(int i = 0; i <= 600; i++){ sensor->setTemp(temp_t(20.0) - temp_t(i*0.015625)); pid->update(); act->update(); } BOOST_CHECK_EQUAL(sensor->read(), temp_t(10.625)); // sensor value should have gone up 9.375 degrees BOOST_CHECK_CLOSE(double(act->getValue()), 10.0*(10.625-5.0) - 10*0.015625*60, 5); }
BOOST_FIXTURE_TEST_CASE(proportional_plus_derivative, PidTest) { pid->setConstants(10.0, 0, 60); sp->write(35.0); pid->setInputFilter(0); pid->setDerivativeFilter(4); // update for 10 minutes for(int i = 0; i <= 600; i++){ sensor->setTemp(temp_t(20.0) + temp_t(i*0.015625)); pid->update(); act->update(); } BOOST_CHECK_EQUAL(sensor->read(), temp_t(29.375)); // sensor value should have gone up 9.375 degrees // derivative part is -9.375 (-10*60*0.015625) // proportional part is 10.0*(35 - 29.375) = 56.25 BOOST_CHECK_CLOSE(double(act->getValue()), 10.0*(35 - 29.375) - 10*60*0.015625, 5); }
temp_t randomIntervalTest(ActuatorPwm* act, ActuatorDigital * target, temp_t duty, int delayMax) { act->setValue(duty); ticks_millis_t lowToHighTime = ticks.millis(); ticks_millis_t highToLowTime = ticks.millis(); ticks_millis_t totalHighTime = 0; ticks_millis_t totalLowTime = 0; output << format("\n\n*** Results running 100 periods and random 0-%d ms update intervals," "with duty cycle %u and period %u ***\n") % delayMax % duty % act->getPeriod(); #if PRINT_TOGGLE_TIMES output << "\n\nl->h timestamp h->l timestamp high time low time\n"; #endif // run for 100 periods for (int i = 0; i < 100; i++) { do { highToLowTime = random_delay(delayMax); act->update(); } while (target->isActive()); ticks_millis_t highTime = highToLowTime - lowToHighTime; if (i > 0) { // skip first cycle in totals, it can be incomplete totalHighTime += highTime; } #if PRINT_TOGGLE_TIMES output << format("_/ %10u \t \\_ %10u \t") % lowToHighTime % highToLowTime; output << format(" %10u ms \t") % highTime; #endif do { lowToHighTime = random_delay(delayMax); act->update(); } while (!target->isActive()); ticks_millis_t lowTime = lowToHighTime - highToLowTime; if (i > 0) { // skip first cycle in totals, it can have old duty cycle totalLowTime += lowTime; #if PRINT_TOGGLE_TIMES output << format("%10u ms \n") % lowTime; #endif } else{ #if PRINT_TOGGLE_TIMES output << format("%10u ms (ignored)\n") % lowTime; #endif } } double avgDuty = double(totalHighTime) / (totalHighTime + totalLowTime); temp_t avgDutyTemp = temp_t(round(avgDuty * double(act->max()))); output << "total high time: " << totalHighTime << "\n" << "total low time: " << totalLowTime << "\n" << "avg duty: " << avgDutyTemp << "/" << act->max() << "\n"; return avgDutyTemp; }
void PiLink::setBeerSetting(const char* val) { const char* source = NULL; temp_t newTemp; if(!newTemp.fromTempString(val, tempControl.cc.tempFormat, true)){ return; // could not parse value } if(tempControl.cs.mode == 'p'){ if((newTemp-tempControl.cs.beerSetting) > temp_t(0.2) || (tempControl.cs.beerSetting - newTemp) > temp_t(0.2)){ // this excludes gradual updates under 0.2 degrees source = STR_TEMPERATURE_PROFILE; } } else { source = STR_WEB_INTERFACE; } if (source){ printBeerAnnotation(STR_FMT_SET_TO, STR_BEER_TEMP, val, source); } tempControl.setBeerTemp(newTemp, true); }
void FuseProb::readProbTime(vector<Mat> P, vector<Mat> T) { cout<<"Size of P is "<<P.size()<<endl; cout<<"rows and cols are "<<P[0].rows<<" "<<P[0].cols<<endl; for(int id=0; id<orient; id++) { cout<<"At id"<<id<<endl; Mat temp_p(m_rows, m_cols, CV_64F); Mat temp_t(m_rows, m_cols, CV_64F); for(int i=0; i<m_rows; i++) for(int j=0; j<m_cols; j++) { // cout<<"At i="<<i<<" j="<<j<<endl; temp_p.at<double>(i, j) = P[id].at<double>(i, j); temp_t.at<double>(i, j) = T[id].at<double>(i, j); } Prob.push_back(temp_p); Time.push_back(temp_t); } }