Skip to content

Commit fbc9ef9

Browse files
committed
added shifting in ERG and resistance modes
1 parent 452c48c commit fbc9ef9

File tree

9 files changed

+134
-72
lines changed

9 files changed

+134
-72
lines changed

.vscode/settings.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@
6262
},
6363
"C_Cpp.errorSquiggles": "Disabled",
6464
"cSpell.words": [
65-
"endianness"
65+
"Appender",
66+
"Baranick",
67+
"BINFILE",
68+
"Doud",
69+
"endianness",
70+
"IRAM",
71+
"LOGW",
72+
"MDNS",
73+
"millis",
74+
"Peloton",
75+
"POWERTABLE",
76+
"PWCFILENAME",
77+
"RUNTIMECONFIG",
78+
"ssid",
79+
"STEALTHCHOP",
80+
"UPDATEURL",
81+
"Upgrader",
82+
"userconfig",
83+
"VERSIONFILE",
84+
"WEBSERVER"
6685
]
6786
}

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Added Resistance Capture to Peloton.
1919
- Added Resistance capture to FTMS.
2020
- Added scanning when devices are not connected.
21+
- Added ability to set travel limits based on resistance feedback from a bike.
22+
- Added shifting in ERG mode (changes watt target).
23+
- Added shifting in resistance mode (changes resistance target.)
2124

2225
### Changed
2326
- PowerTable values are now adjusted to 90 RPM cad on input.
@@ -30,6 +33,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3033
- Moved post connect handling to the ble communication loop. (improves startup stability)
3134
- Fixed bug submitted by @flo100 where MIN_WATTS in ERG should have been userConfig.getMinWatts();
3235
- FTMS resistance mode now changes the attached bike resistance with feedback. (i.e. setting resistance to 50 with a Peloton attached will set 50 on the Peloton)
36+
- Refactored rtConfig to use more measurement class.
37+
- Increased stepper speed when a Peloton is connected. (very light resistance)
38+
- Updated libraries to latest
3339

3440
### Hardware
3541
- removed duplicate directory in direct mount folder
@@ -119,7 +125,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
119125
- Added WebSockets for logging [see #173](https://github.com/doudar/SmartSpin2k/issues/173)
120126
- Reworked logging to run log-appender outside the worker task (task no longer blocked by logger traffic).
121127
- WebsocketsAppender can handle multiple (up to 4) clients. Status.html will reconnect if connection to websockets server is disconnected.
122-
- Added ability to set travel limits based on resistance feedback from a bike.
123128

124129
### Changed
125130
- Refactored ERG.
@@ -143,9 +148,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
143148
- Increased JSON size for userConfig (hopefully fix config saving issues).
144149
- Changed LOGE messages in spiffs logging to regular LOG messages so they will display via network logging.
145150
- Complete BLE Client connection code rebase.
146-
- Refactored rtConfig to use more measurement class.
147-
- Increased stepper speed when a Peloton is connected. (very light resistance)
148-
- Updated libraries to latest
149151

150152
### Fixed
151153
- bluetoothscanner.html now lists fitness machine services in the PM list.

include/Main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class SS2K {
5252
void motorStop(bool releaseTension = false);
5353
void checkSerial();
5454
void checkBLEReconnect();
55+
void FTMSModeShiftModifier();
5556

5657
SS2K() {
5758
targetPosition = 0;
@@ -81,7 +82,7 @@ class AuxSerialBuffer {
8182
}
8283
};
8384

84-
// Users Physical Working Capacity Calculation Parameters (heartrate to Power
85+
// Users Physical Working Capacity Calculation Parameters (heart rate to Power
8586
// calculation)
8687
extern physicalWorkingCapacity userPWC;
8788
extern SS2K ss2k;

include/SmartSpin_parameters.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class RuntimeParameters {
6060
int shifterPosition = 0;
6161
int minStep = -DEFAULT_STEPPER_TRAVEL;
6262
int maxStep = DEFAULT_STEPPER_TRAVEL;
63-
int minResistance = -1;
64-
int maxResistance = -1;
63+
int minResistance = -DEFAULT_RESISTANCE_RANGE;
64+
int maxResistance = DEFAULT_RESISTANCE_RANGE;
6565
bool simTargetWatts = false;
6666

6767
public:
@@ -129,7 +129,7 @@ class userParameters {
129129
void setFirmwareUpdateURL(String fURL) { firmwareUpdateURL = fURL; }
130130
const char* getFirmwareUpdateURL() { return firmwareUpdateURL.c_str(); }
131131

132-
void setDeviceName(String dvcn) { deviceName = dvcn; }
132+
void setDeviceName(String dvn) { deviceName = dvn; }
133133
const char* getDeviceName() { return deviceName.c_str(); }
134134

135135
void setShiftStep(int ss) { shiftStep = ss; }
@@ -147,7 +147,7 @@ class userParameters {
147147
float getERGSensitivity() { return ERGSensitivity; }
148148
void setERGSensitivity(float ergS) { ERGSensitivity = ergS; }
149149

150-
void setAutoUpdate(bool atupd) { autoUpdate = atupd; }
150+
void setAutoUpdate(bool atd) { autoUpdate = atd; }
151151
bool getAutoUpdate() { return autoUpdate; }
152152

153153
void setSsid(String sid) { ssid = sid; }
@@ -180,7 +180,7 @@ class userParameters {
180180
void setUdpLogEnabled(bool enabled) { udpLogEnabled = enabled; }
181181
bool getUdpLogEnabled() { return udpLogEnabled; }
182182

183-
void setFoundDevices(String fdev) { foundDevices = fdev; }
183+
void setFoundDevices(String fdv) { foundDevices = fdv; }
184184
const char* getFoundDevices() { return foundDevices.c_str(); }
185185

186186
void setDefaults();

include/boards.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class Boards {
4444
rev1.enablePin = r1_ENABLE_PIN;
4545
rev1.stepPin = r1_STEP_PIN;
4646
rev1.dirPin = r1_DIR_PIN;
47-
rev1.stepperSerialTxPin = r1_STEPPERSERIAL_TX;
48-
rev1.stepperSerialRxPin = r1_STEPPERSERIAL_RX;
47+
rev1.stepperSerialTxPin = r1_STEPPER_SERIAL_TX;
48+
rev1.stepperSerialRxPin = r1_STEPPER_SERIAL_RX;
4949
rev1.auxSerialTxPin = 0;
5050
rev1.auxSerialRxPin = 0;
5151
rev1.pwrScaler = r1_PWR_SCALER;
@@ -57,8 +57,8 @@ class Boards {
5757
rev2.enablePin = r2_ENABLE_PIN;
5858
rev2.stepPin = r2_STEP_PIN;
5959
rev2.dirPin = r2_DIR_PIN;
60-
rev2.stepperSerialTxPin = r2_STEPPERSERIAL_TX;
61-
rev2.stepperSerialRxPin = r2_STEPPERSERIAL_RX;
60+
rev2.stepperSerialTxPin = r2_STEPPER_SERIAL_TX;
61+
rev2.stepperSerialRxPin = r2_STEPPER_SERIAL_RX;
6262
rev2.auxSerialTxPin = r2_AUX_SERIAL_TX;
6363
rev2.auxSerialRxPin = r2_AUX_SERIAL_RX;
6464
rev2.pwrScaler = r2_PWR_SCALER;

include/settings.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,33 @@
7676
// is obtained as closely as possible during each shift.
7777
#define WATTS_PER_SHIFT 30
7878

79+
// Amount to change watt target per shift in ERG mode.
80+
#define ERG_PER_SHIFT 10
81+
7982
// Default Min Watts to stop stepper.
80-
//This is used to set the lower travel limit for the motor.
83+
// This is used to set the lower travel limit for the motor.
8184
#define DEFAULT_MIN_WATTS 50
8285

8386
// Default Max Watts that the brake on the spin bike can absorb from the user.
84-
//This is used to set the upper travel limit for the motor.
87+
// This is used to set the upper travel limit for the motor.
8588
#define DEFAULT_MAX_WATTS 800
8689

8790
// Minimum resistance on a Peloton Bike.
88-
//This is used to set the lower travel limit for the motor.
91+
// This is used to set the lower travel limit for the motor.
8992
#define MIN_PELOTON_RESISTANCE 5
9093

9194
// Maximum resistance on a Peloton Bike.
92-
//This is used to set the upper travel limit for the motor.
95+
// This is used to set the upper travel limit for the motor.
9396
#define MAX_PELOTON_RESISTANCE 99
9497

98+
// Resistance range when no bike with resistance is connected.
99+
#define DEFAULT_RESISTANCE_RANGE 2000
100+
95101
// Stepper Max Speed in ERG Mode steps/s
96102
#define STEPPER_PELOTON_SPEED 2500
97103

98104
// Default +- Stepper Travel Limit
99-
//This is used until the PowerTable has enough data to compute travel limits
105+
// This is used until the PowerTable has enough data to compute travel limits
100106
#define DEFAULT_STEPPER_TRAVEL 200000000
101107

102108
// Default debounce delay for shifters. Increase if you have false shifts. Decrease if shifting takes too long.
@@ -129,10 +135,10 @@
129135
#define r1_DIR_PIN 33
130136

131137
// TMC2208/TMC2224 SoftwareSerial receive pin
132-
#define r1_STEPPERSERIAL_RX 14
138+
#define r1_STEPPER_SERIAL_RX 14
133139

134140
// TMC2208/TMC2224 SoftwareSerial transmit pin
135-
#define r1_STEPPERSERIAL_TX 12
141+
#define r1_STEPPER_SERIAL_TX 12
136142

137143
// Reduce current setting by this divisor (0-31)
138144
#define r1_PWR_SCALER 31
@@ -161,10 +167,10 @@
161167
#define r2_DIR_PIN 33
162168

163169
// TMC2209 SoftwareSerial receive pin
164-
#define r2_STEPPERSERIAL_RX 18
170+
#define r2_STEPPER_SERIAL_RX 18
165171

166172
// TMC2209 SoftwareSerial transmit pin
167-
#define r2_STEPPERSERIAL_TX 19
173+
#define r2_STEPPER_SERIAL_TX 19
168174

169175
// TMC2209 SoftwareSerial receive pin
170176
#define r2_AUX_SERIAL_RX 22
@@ -253,27 +259,27 @@
253259
// Interrogate Peloton bike for data?
254260
#define PELOTON_TX true
255261

256-
// If not receiving Peleton Messages, how long to wait before next TX attempt is
262+
// If not receiving Peloton Messages, how long to wait before next TX attempt is
257263
#define TX_CHECK_INTERVAL 20
258264

259-
// If ble devices are both setup, how often to attempt a reconnect.
265+
// If ble devices are both setup, how often to attempt a reconnect.
260266
#define BLE_RECONNECT_INTERVAL 15
261267

262-
// Initial and web scan duration.
268+
// Initial and web scan duration.
263269
#define DEFAULT_SCAN_DURATION 10
264270

265-
// BLE automatic reconnect duration. Set this low to avoid interruption.
271+
// BLE automatic reconnect duration. Set this low to avoid interruption.
266272
#define BLE_RECONNECT_SCAN_DURATION 3
267273

268274
// Uncomment to enable sending Telegram debug messages back to the chat
269275
// specified in telegram_token.h
270276
// #define USE_TELEGRAM
271277

272278
// Uncomment to enable stack size debugging info
273-
//#define DEBUG_STACK
279+
// #define DEBUG_STACK
274280

275281
// Uncomment to enable HR->PWR debugging info. Always displays HR->PWR
276-
// Calculation. Never sets userConfig.setSimulatedPower();
282+
// Calculation. Never sets userConfig.setSimulatedPower();
277283
// #define DEBUG_HR_TO_PWR
278284

279285
// Uncomment to enable HR->PWR enhanced powertable debugging.

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ build_flags =
3030
-D CONFIG_MDNS_STRICT_MODE=1
3131
-D CORE_DEBUG_LEVEL=2
3232
lib_deps =
33-
https://github.com/h2zero/NimBLE-Arduino/archive/refs/tags/1.4.1.zip
33+
https://github.com/h2zero/NimBLE-Arduino/archive/refs/tags/1.3.8.zip
3434
https://github.com/teemuatlut/TMCStepper/archive/refs/tags/v0.7.3.zip
3535
https://github.com/bblanchon/ArduinoJson/archive/refs/tags/v6.20.0.zip
3636
https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/archive/refs/tags/V1.3.0.zip

src/ERG_Mode.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void ergTaskLoop(void* pvParameters) {
5757
}
5858

5959
// resistance mode
60-
if ((rtConfig.getFTMSMode() == FitnessMachineControlPointProcedure::SetTargetResistanceLevel) && (rtConfig.getMaxResistance()>0)) {
60+
if ((rtConfig.getFTMSMode() == FitnessMachineControlPointProcedure::SetTargetResistanceLevel) && (rtConfig.getMaxResistance() != DEFAULT_RESISTANCE_RANGE)) {
6161
ergMode.computeResistance();
6262
}
6363

@@ -119,10 +119,10 @@ void PowerTable::setStepperMinMax() {
119119
int _return = RETURN_ERROR;
120120

121121
// if the FTMS device reports resistance feedback, skip estimating min_max
122-
if (rtConfig.resistance.getValue()>0) {
122+
if (rtConfig.resistance.getValue() > 0) {
123123
rtConfig.setMinStep(-DEFAULT_STEPPER_TRAVEL);
124124
rtConfig.setMaxStep(DEFAULT_STEPPER_TRAVEL);
125-
SS2K_LOG(ERG_MODE_LOG_TAG, "Set FTMS Resistance Mode Travel Limits");
125+
SS2K_LOG(ERG_MODE_LOG_TAG, "Using Resistance Travel Limits");
126126
return;
127127
}
128128

@@ -266,7 +266,7 @@ int32_t PowerTable::lookup(int watts, int cad) {
266266
}
267267
}
268268
if ((i - x <= 0) && (i + x >= POWERTABLE_SIZE)) {
269-
SS2K_LOG(ERG_MODE_LOG_TAG, "No data found in powertable.");
269+
SS2K_LOG(ERG_MODE_LOG_TAG, "No data found in Power Table.");
270270
return RETURN_ERROR;
271271
}
272272
}
@@ -320,7 +320,7 @@ int32_t PowerTable::lookup(int watts, int cad) {
320320
above.cad = this->powerEntry[indexPair].cad;
321321
}
322322
if (below.targetPosition >= above.targetPosition) {
323-
SS2K_LOG(ERG_MODE_LOG_TAG, "Reverse/No Delta in PowerTable");
323+
SS2K_LOG(ERG_MODE_LOG_TAG, "Reverse/No Delta in Power Table");
324324
return (RETURN_ERROR);
325325
}
326326
} else { // Not enough data
@@ -350,12 +350,12 @@ int PowerTable::_adjustWattsForCadence(int watts, float cad) {
350350
}
351351

352352
bool PowerTable::load() {
353-
// load power table from littlefs
353+
// load power table from littleFs
354354
return false; // return unsuccessful
355355
}
356356

357357
bool PowerTable::save() {
358-
// save powertable from littlefs
358+
// save power table from littleFs
359359
return false; // return unsuccessful
360360
}
361361

@@ -410,18 +410,18 @@ void ErgMode::computeResistance() {
410410
// SS2K_LOG(ERG_MODE_LOG_TAG, "StepChange %d TargetDelta %d ActualDelta %d OldSetPoint %d NewSetPoint %d", stepChangePerResistance, targetDelta, actualDelta, oldSetPoint,
411411
// newSetPoint);
412412

413-
if (rtConfig.getCurrentIncline() == rtConfig.getTargetIncline()) {
414-
if (actualDelta > 0) {
415-
rtConfig.setTargetIncline(rtConfig.getTargetIncline() + (100 * actualDelta));
416-
// SS2K_LOG(ERG_MODE_LOG_TAG, "adjusting target up");
417-
// SS2K_LOG(ERG_MODE_LOG_TAG, "First run shift up");
418-
}
419-
if (actualDelta < 0) {
420-
rtConfig.setTargetIncline(rtConfig.getTargetIncline() + (100 * actualDelta));
421-
// SS2K_LOG(ERG_MODE_LOG_TAG, "adjusting target down");
422-
// SS2K_LOG(ERG_MODE_LOG_TAG, "First run shift down");
423-
}
424-
}
413+
// if (rtConfig.getCurrentIncline() == rtConfig.getTargetIncline()) {
414+
// if (actualDelta > 0) {
415+
// rtConfig.setTargetIncline(rtConfig.getTargetIncline() + (100 * actualDelta));
416+
// SS2K_LOG(ERG_MODE_LOG_TAG, "adjusting target up");
417+
// SS2K_LOG(ERG_MODE_LOG_TAG, "First run shift up");
418+
//}
419+
// if (actualDelta < 0) {
420+
rtConfig.setTargetIncline(rtConfig.getTargetIncline() + (100 * actualDelta));
421+
// SS2K_LOG(ERG_MODE_LOG_TAG, "adjusting target down");
422+
// SS2K_LOG(ERG_MODE_LOG_TAG, "First run shift down");
423+
// }
424+
//}
425425
if (actualDelta = 0) {
426426
rtConfig.setTargetIncline(rtConfig.getCurrentIncline());
427427
// SS2K_LOG(ERG_MODE_LOG_TAG, "Set point Reached - stopping");

0 commit comments

Comments
 (0)