@@ -165,14 +165,14 @@ void ErgMode::computeErg() {
165165 rtConfig->watts .setTarget (userConfig->getMinWatts ());
166166 }
167167
168- // check for new torque value or new set point, if watts < 0 treat as faulty
168+ // check for new watt value or new set point, if watts < 0 treat as faulty
169169 if ((this ->prevWatts .getTimestamp () == rtConfig->watts .getTimestamp () && this ->prevWatts .getTarget () == rtConfig->watts .getTarget ()) || rtConfig->watts .getValue () < 0 ) {
170170 SS2K_LOG (ERG_MODE_LOG_TAG, " Watts previously processed." );
171171 return ;
172172 }
173173
174174#ifdef ERG_MODE_USE_POWER_TABLE
175- if (abs (this ->prevWatts .getTarget () - rtConfig->watts .getTarget ()) > POWERTABLE_CAD_INCREMENT && rtConfig->getHomed ()) {
175+ if (abs (this ->prevWatts .getTarget () - rtConfig->watts .getTarget ()) > POWERTABLE_WATT_INCREMENT && rtConfig->getHomed ()) {
176176 result = _setPointChangeState ();
177177 }
178178#endif
@@ -188,7 +188,7 @@ void ErgMode::computeErg() {
188188int32_t ErgMode::_setPointChangeState () {
189189 mode = (rtConfig->watts .getTarget () > rtConfig->watts .getValue ()) ? Mode::INCREASING : Mode::DECREASING;
190190 // It's better to undershoot increasing watts and overshoot decreasing watts, so lets set the lookup target to the nearest side of POWERTABLE_WATT_INCREMENT
191- int adjustedWattTarget = (mode == Mode::INCREASING) ? rtConfig->watts .getTarget () - POWERTABLE_WATT_INCREMENT : rtConfig->watts .getTarget () + POWERTABLE_WATT_INCREMENT ;
191+ int adjustedWattTarget = (mode == Mode::INCREASING) ? rtConfig->watts .getTarget () - ERG_MODE_PID_WINDOW : rtConfig->watts .getTarget () + ERG_MODE_PID_WINDOW ;
192192 int32_t tableResult = powerTable->lookup (adjustedWattTarget,
193193 (mode == Mode::INCREASING) ? rtConfig->cad .getValue () + POWERTABLE_CAD_INCREMENT : rtConfig->cad .getValue () - POWERTABLE_CAD_INCREMENT);
194194
@@ -200,11 +200,11 @@ int32_t ErgMode::_setPointChangeState() {
200200
201201 // Test current watts against the table result. If We're already lower or higher than target, flag the result as a return error.
202202 if (tableResult != RETURN_ERROR) {
203- if (adjustedWattTarget > rtConfig-> watts . getValue () && tableResult < ss2k->getCurrentPosition ()) {
203+ if (mode == Mode::INCREASING && tableResult < ss2k->getCurrentPosition ()) {
204204 SS2K_LOG (ERG_MODE_LOG_TAG, " Table Result Failed increasing Test: %d" , tableResult);
205205 tableResult = RETURN_ERROR;
206206 }
207- if ((adjustedWattTarget < rtConfig-> watts . getValue ()) && tableResult > ss2k->getCurrentPosition ()) {
207+ if (mode == Mode::DECREASING && tableResult > ss2k->getCurrentPosition ()) {
208208 SS2K_LOG (ERG_MODE_LOG_TAG, " Table Result Failed decreasing Test: %d" , tableResult);
209209 tableResult = RETURN_ERROR;
210210 }
@@ -303,6 +303,7 @@ void ErgMode::_updateValues(float newIncline) {
303303bool ErgMode::_userIsSpinning (int cadence, float incline) {
304304 if (cadence <= MIN_ERG_CADENCE) {
305305 rtConfig->setFTMSMode (FitnessMachineControlPointProcedure::SetIndoorBikeSimulationParameters);
306+ rtConfig->setTargetIncline (1 .0f );
306307 return false ; // Cadence too low, nothing to do here
307308 }
308309 this ->engineStopped = false ;
0 commit comments