Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for bike power functions #2174

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
678facc
#2174 Added tests for bike power functions
drmason789 Mar 1, 2024
15d2753
#2174 restrict the samples when exploring the boundaries of the power…
drmason789 Mar 1, 2024
bf4bf1e
Merge remote-tracking branch 'remotes/origin/master' into bike_power_…
drmason789 Mar 7, 2024
c74fe53
#2174 moved erg test functionality into the new Erg folder from other PR
drmason789 Mar 7, 2024
6fc5022
Merge remote-tracking branch 'remotes/origin/master' into bike_power_…
drmason789 Mar 19, 2024
d9c9f29
Merge remote-tracking branch 'remotes/origin/master' into bike_power_…
drmason789 Mar 25, 2024
e335ac2
#2174 added minmax type and introduced minimum and maximum resistance…
drmason789 Mar 25, 2024
2ab31e8
#2174 avoid template in cpp
drmason789 Mar 26, 2024
6d76f98
#2174 added bike cadence limits.
drmason789 Mar 26, 2024
26d2aac
#2174
drmason789 Mar 26, 2024
439570b
#2174
drmason789 Mar 27, 2024
d2be67c
#2174 removed typo
drmason789 Mar 27, 2024
ce54799
#2174 consistent interface for bike::wattsFromResistance
drmason789 Mar 27, 2024
6e018a1
#2174 added tests for conversion to and from resistance and Peloton r…
drmason789 Mar 27, 2024
55cb801
#2174 increase use of minmax<T> in test code. Some work to make Pelot…
drmason789 Mar 29, 2024
30dfa77
Merge branch 'cagnulein:master' into bike_power_tests
drmason789 Mar 29, 2024
a561444
Merge branch 'cagnulein:master' into bike_power_tests
drmason789 Apr 2, 2024
2ca3644
#2174 replaced powerFromResistanceRequest with wattsFromResistance
drmason789 Apr 2, 2024
da9ebd8
Merge branch 'bike_power_tests' of https://github.com/drmason789/qdom…
drmason789 Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- adjusted power conversion test to force no watt gain
- adjusted bike::resistanceFromPowerRequest to make it easier to see what it's comparing and to cache calculations
- many power conversion tests now passing, but some strange values remain in the failing tests
  • Loading branch information
drmason789 committed Mar 26, 2024
commit 26d2aac0e714464057e8f16ae8a3c590739f479e
29 changes: 18 additions & 11 deletions src/devices/bike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,27 @@ resistance_t bike::resistanceFromPowerRequest(uint16_t power) {

auto minMaxR = this->resistanceLimits();

for (resistance_t i = minMaxR.min(); i < minMaxR.max(); i++) {
if (((wattsFromResistance(i) * watt_gain) + watt_offset) <= power &&
((wattsFromResistance(i + 1) * watt_gain) + watt_offset) >= power) {
qDebug() << QStringLiteral("resistanceFromPowerRequest")
<< ((wattsFromResistance(i) * watt_gain) + watt_offset)
<< ((wattsFromResistance(i + 1) * watt_gain) + watt_offset) << power;
uint16_t power0 = (wattsFromResistance(minMaxR.min()) * watt_gain) + watt_offset;

// Is the requested power at or below the power of the minimum resistance the device provides?
if (power <= power0)
return minMaxR.min();

// Search from the 1st resistance level above minimum to the maximum
for (resistance_t i = 1 + minMaxR.min(); i < minMaxR.max(); i++) {
uint16_t power1 = wattsFromResistance(i)*watt_gain + watt_offset;

if(power0 <= power && power1>=power) {
qDebug() << QStringLiteral("resistanceFromPowerRequest") << power0 << power1 << power;
return i;
}

power0 = power1;
}
if (power < ((wattsFromResistance(minMaxR.min()) * watt_gain) + watt_offset))
return minMaxR.min();
else
return minMaxR.max();
} // in order to have something

// requested power requires resistance beyond the maximum
return minMaxR.max();
}
void bike::cadenceSensor(uint8_t cadence) { Cadence.setValue(cadence); }
void bike::powerSensor(uint16_t power) { m_watt.setValue(power, false); }

Expand Down
16 changes: 10 additions & 6 deletions tst/Devices/biketestsuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void BikeTestSuite<T>::test_powerFunctions_maxCadence() {
GTEST_SKIP() << "No maximum cadence defined";
}

ASSERT_TRUE(this->testSettings.get_active()) << "TestSettings object should be active.";
this->testSettings.qsettings.setValue(QZSettings::watt_gain, 1.0);
this->testSettings.qsettings.setValue(QZSettings::watt_offset, 0.0);

// traverse the resistance edge checking the power is clipped to the values for the max and min cadence

QString powerBeyondCadenceLimit = QStringLiteral("Power at R:%1 not bounded at %6 cadence (C:%2 RPM, P:%3W), (C:%4 RPM, P:%5W)");
Expand Down Expand Up @@ -159,20 +163,20 @@ void BikeTestSuite<T>::test_powerFunctions_resistancePowerConversion() {
for(uint16_t cadenceRPM : this->getCadenceSamples())
{
uint16_t lastPower=0xFFFF;
for(resistance_t r=minResistance; r<=maxResistance; r++)
for(resistance_t resistanceToPower=minResistance; resistanceToPower<=maxResistance; resistanceToPower++)
{
uint16_t power = erg->getPower(cadenceRPM, r);
uint16_t power = erg->getPower(cadenceRPM, resistanceToPower);

// if this resistance reaches a new power level, check the inverse
if(power!=lastPower)
{
lastPower = power;
resistance_t resistance = erg->getResistance(cadenceRPM, power);
resistance_t resistanceFromPower = erg->getResistance(cadenceRPM, power);

if(r!=resistance) {
uint16_t newPower = erg->getPower(cadenceRPM, resistance);
if(resistanceToPower!=resistanceFromPower) {
uint16_t newPower = erg->getPower(cadenceRPM, resistanceFromPower);

errors.append(unexpectedResistance.arg(r).arg(power).arg(cadenceRPM).arg(resistance).arg(newPower));
errors.append(unexpectedResistance.arg(resistanceToPower).arg(power).arg(cadenceRPM).arg(resistanceFromPower).arg(newPower));
}

}
Expand Down
Loading