cagnulein / qdomyos-zwift

Zwift bridge for smart treadmills and bike/cyclette
https://www.qzfitness.com/
GNU General Public License v3.0
431 stars 117 forks source link

QZ and SS2K lose sync during ride #1228

Open marklogan17 opened 1 year ago

marklogan17 commented 1 year ago

I did a ride this morning and I had a problem where about 10 minutes in QZ target resistance change but the actual bike resistance didn't change with the SS2K. I turned off auto resistance, manually changed the resistance to match the target and then turned auto-resistance back on which 'should' have caused QZ and SS2K to sync again but it actually turned the resistance down. Can't remember exact numbers but say I was at approx 24 resistance, target was 27. Manually changed to 27, turned auto resistance back on and it went down to approx 21-22 resistance. I tried a few more times, playing with gears and such and eventually got it working. 10 or so minutes later it happened again. I couldn't get it synced this time so I unplugged the SS2K to reset it. I did that and QZ crashed.

Debug log attached... debug-Mon_Jan_30_07_14_56_2023.log

cagnulein commented 1 year ago

ok first thing that I noticed, there is No disconnection from SS2k, and this is a good thing. Let me check this in the details

Mon. Jan. 30 07:27:44 2023 1675081664307 Debug: ../src/smartspin2k.cpp void smartspin2k::autoResistanceChanged(bool) ehi mark, i'm doing your stuff :) resetting everything for SS2K
Mon. Jan. 30 07:28:24 2023 1675081704645 Debug: ../src/smartspin2k.cpp void smartspin2k::autoResistanceChanged(bool) ehi mark, i'm doing your stuff :) resetting everything for SS2K
Mon. Jan. 30 07:35:49 2023 1675082149450 Debug: ../src/smartspin2k.cpp void smartspin2k::autoResistanceChanged(bool) ehi mark, i'm doing your stuff :) resetting everything for SS2K
Mon. Jan. 30 07:37:15 2023 1675082235146 Debug: ../src/smartspin2k.cpp void smartspin2k::autoResistanceChanged(bool) ehi mark, i'm doing your stuff :) resetting everything for SS2K

here @marklogan17 is when you toggled the auto resistance

@doudar

cagnulein commented 1 year ago

@marklogan17 is it possible that the motor of the SS2K gets stucked? did you try to press its own buttons?

marklogan17 commented 1 year ago

@marklogan17 is it possible that the motor of the SS2K gets stucked? did you try to press its own buttons?

First - I love the logging where you mention me :)

Its possible that the motor had a problem. I definitely use the gear buttons to get the actual resistance closer to the target resistance and then manually turned it to get it equal before toggling auto-resistance to try and force a re-sync. I basically played with a combination of turning on/off auto-resistance, changing gears and manually turning resistance to try and get it back in sync. Definitely could be a hardware problem that started it though.

Is the re-sync working? When I toggled auto-resistance I thought it would tell SS2K the new 'current' resistance so the two were in sync again and then auto move to the target resistance - but for some reason it went down.

doudar commented 1 year ago

@marklogan17 , are you using the newest firmware?

If so, I see you're using an Echelon! I just implemented resistance feedback for Peloton users but we didn't find an Echelon&QZ user for testing yet so it's only partially implemented there.

If you want to provide some debugging feedback of the SS2K logs (preferably with https://github.com/couchcoding/Logbert) it would be nice to polish this functionality with Echelon. You can just copy the logs into pastebin.com and post the link here or on the SmartSpin2k Github. It's working pretty amazing with Peloton according to @Emadman .

marklogan17 commented 1 year ago

@marklogan17 , are you using the newest firmware?

If so, I see you're using an Echelon! I just implemented resistance feedback for Peloton users but we didn't find an Echelon user for testing yet so it's only partially implemented there.

If you want to provide some debugging feedback of the SS2K logs (preferably with https://github.com/couchcoding/Logbert) it would be nice to polish this functionality with Echelon. You can just copy the logs into pastebin.com and post the link here or on the SmartSpin2k Github. It's working pretty amazing with Peloton according to @eMadman .

I'm a little gun shy to upgrade - had a firmware upgrade that seemed to break things, ended up swapping devices. In the end I think it was coincidence with some wiring coming lose but once I got it working I was nervous to upgrade again :) That being said, you only live once right?

So you want me to upgrade the firmware to the latest release version and do a ride. Can I now extract the logs from the web UI or do I need to do something different? What should I be looking out for functionally? @cagnulein any difference in the connection/setup/etc?

cagnulein commented 1 year ago

@cagnulein any difference in the connection/setup/etc?

@doudar on my point of view, he has to enable the new peloton setting or not?

doudar commented 1 year ago

@marklogan17 , are you using the newest firmware? If so, I see you're using an Echelon! I just implemented resistance feedback for Peloton users but we didn't find an Echelon user for testing yet so it's only partially implemented there. If you want to provide some debugging feedback of the SS2K logs (preferably with https://github.com/couchcoding/Logbert) it would be nice to polish this functionality with Echelon. You can just copy the logs into pastebin.com and post the link here or on the SmartSpin2k Github. It's working pretty amazing with Peloton according to @eMadman .

I'm a little gun shy to upgrade - had a firmware upgrade that seemed to break things, ended up swapping devices. In the end I think it was coincidence with some wiring coming lose but once I got it working I was nervous to upgrade again :) That being said, you only live once right?

So you want me to upgrade the firmware to the latest release version and do a ride. Can I now extract the logs from the web UI or do I need to do something different? What should I be looking out for functionally? @cagnulein any difference in the connection/setup/etc?

The logs from the browser window are fine as well. I'm not really sure of the setup for QZ. Roberto, this would work exactly like for the Peloton. Actual bike resistance would be reported by the SS2K over FTMS if it's (SS2K) connected to the Echelon via BLE. Then the SS2K would handle seeking resistance targets over FTMS.

cagnulein commented 1 year ago

ok so @marklogan17 you need the latest beta for QZ and also enabling the peloton setting in the ss2k section

cagnulein commented 1 year ago

but warning @marklogan17 you will be the first trying this :)

marklogan17 commented 1 year ago

@cagnulein & @doudar is this going to be the recommended integration going forward? If so, I'll definitely get it going!

doudar commented 1 year ago

@cagnulein & @doudar is this going to be the recommended integration going forward? If so, I'll definitely get it going!

As long as we can get it working well :)

My guess on this first try, is that it either won't work at all, or if it does (hopefully!!) you're going to see oscillation as SS2K over and under shoots the resistance targets, but we can tune that.

doudar commented 1 year ago

@emad just informed me of another issue with reporting everything over FTMS - currently you're expecting the Peloton resistance range of 0-100. Echelon resistance range is ~0-32. I will probably need to implement resetting this characteristic to the range of whatever bike is connected and QZ will need to periodically read it: #define FITNESSMACHINERESISTANCELEVELRANGE_UUID NimBLEUUID((uint16_t)0x2AD6)

cagnulein commented 1 year ago

ok so @marklogan17 don't test it yet :) In these days guys i'm very busy so I guess I will do this next week :(

doudar commented 1 year ago

ok so @marklogan17 don't test it yet :) In these days guys i'm very busy so I guess I will do this next week :(

Thanks I've got a busy week as well and work would be getting neglected if we did this this week :)

If we do this this way, are you able to just apply a scaler ((MAX_FITNESSMACHINERESISTANCELEVELRANGE/MAX_PELOTON_RESISTANCE)*Peloton Target)) to the resistance range reported in 0x2AD6 and send that as a target or is your Peloton conversion non-linear?

I.e. a Peloton target of 88 would be: (32/100)*88 = 28.16 for a ftms resistance range reported of 0-32

cagnulein commented 1 year ago

why simple don't use the target resistance value instead of the peloton target resistance? it will simplify everything since i'm alraedy thinking in 32 levels for the echelon :)

yes i have this conversion already, it's the one displayed in the target resistance tile :)

doudar commented 1 year ago

why simple don't use the target resistance value instead of the peloton target resistance? it will simplify everything since i'm alraedy thinking in 32 levels for the echelon :)

yes i have this conversion already, it's the one displayed in the target resistance tile :)

Only because if Echelon is connected to SS2K, QZ will not know it's using an Echelon, only a SS2K. Unless you automatically detect it by the FTMSResistanceLevelRange

cagnulein commented 1 year ago

mmm I don't see the real benefit of all of this :D i mean we're reinventing the wheel i guess :) i mean qz is already aware of the real resistance of the bike since it's connected. why an user should use ss2k as a master instead?

doudar commented 1 year ago

It is reinventing the wheel I'll give you that.

It's probably the way we should have been doing it all along as a lot of what the custom characteristic is doing is duplicated in the actual FTMS spec. The only need for the change is if the custom characteristic continues to be problematic.

cagnulein commented 1 year ago

yes but it could be complicated to the FTMS thing for all the bikes, unless you don't want to add all the bike profile of QZ to SS2k too :)

doudar commented 1 year ago

yes but it could be complicated to the FTMS thing for all the bikes, unless you don't want to add all the bike profile of QZ to SS2k too :)

That's a great point - the original purpose of the custom characteristic was so that QZ could handle the heavy lifting.

doudar commented 1 year ago

Okay - so @marklogan17 , I'd like you to still upgrade firmware if you can and then lets get this stuff sorted out with the custom characteristic. It may not need much for QZ changes.

marklogan17 commented 1 year ago

Sorry guys, I was doing someone's review :) So I can upgrade the firmware and test the current config. I'm not testing the new peloton setting for now?

doudar commented 1 year ago

Sorry guys, I was doing someone's review :) So I can upgrade the firmware and test the current config. I'm not testing the new peloton setting for now?

Not for now. I agree that for Echelon, custom characteristic is the best way to do this. If there's an issue with it working on the latest firmware, let's get it stable! 😃

Btw, that should have been an interesting review with the constant notifications 🤣

marklogan17 commented 1 year ago

I upgraded to the latest firmware and latest QZ and did a Peloton ride yesterday. It all worked well. What do you need me to test on the latest firmware for the custom characteristic? I'm out of town until Saturday but should be able to make some time on the weekend or next week.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

cagnulein commented 1 year ago

any news on this @marklogan17 ? it was just a one time issue?

marklogan17 commented 1 year ago

any news on this @marklogan17 ? it was just a one time issue?

Its actually been pretty good - until today :) Only one small issue today where it was meant to change 3 resistance levels and just didn't. It would be great if we could figure out a way to 'fix' the resistance. Minor tweaks - like it was 25 going to 26 but didn't 'quite' go far enough so its going back and forth between 25 and 26 so send a request to increase resistance like 25% of a single level. Or a re-sync button that says "target is currently 27, I'm at 24, increase resistance a level at a time until I hit 27 and then stop". Basically I think you're always going to get issues from motors or not quite linear amount of turn needed for each level or a bunch of other reasons so 'fixing' it may be more important than identifying all the issues and trying to fix those.

marklogan17 commented 1 year ago

But also I know this is a small percentage of your user base so not sure how much time its worth to add those types of tweaks.

cagnulein commented 1 year ago

mmm do you have a debug log from this?

marklogan17 commented 1 year ago

Attached a log from today. Its a 30 minute ride. At about 18:45 left in the ride (don't know if you log Peloton remaining time but that would be a good indicator) the resistance was meant to drop. I think from 27 maybe down to 13? However it didn't change at all. The gear buttons didn't do anything. I manually turned it down to match the target resistance. Then I hit the stop auto resistance button and then hit it again to turn on the auto resistance again. I hit a manual gear button to get the resistance up a level and immediately the resistance dropped all the way to zero. Almost like changing the gear made it do the operation that hadn't happened when it should have gone from 27 to 13.

This happened again with a couple of minutes left in the ride. A smaller change this time. I manually turned it to match, turn off sync, turn on sync, hit the gear button and it went down like 3. Next time rather than manually changing it I may just hit unsync->sync->gear and see if that make sit go to the right place.

Zipped log file attached. I would say the first time was between 18:45 to 16:30 remaining in the ride which would be 11:15 to 13:30 from the start of the ride if that's easier to find. I feel like the second time was maybe around 2 minutes left - I really should take notes right after the ride so I don't forget.

One other thing completely unrelated... You'll see when I 'started' the Peloton ride the timing was pretty close. I adjusted peloton offset by 1 second I think. Less than a minute later it was off by 10 seconds so you'll see in there that I adjusted it again, this time by 8 or 9 seconds. I have the Peloton time sync setting on and I'm using Samsung Dex - I had turned off auto-start but forgot to turn off the time sync one. My guess is that this is just part of the problem with Samsung Dex so don't want to open an issue unless you want me to. I've turned off the time sync for now and will see if that fixes it.

debug-Mon_Mar_6_07_15_02_2023.zip

cagnulein commented 1 year ago

One other thing completely unrelated... You'll see when I 'started' the Peloton ride the timing was pretty close. I adjusted peloton offset by 1 second I think. Less than a minute later it was off by 10 seconds so you'll see in there that I adjusted it again, this time by 8 or 9 seconds. I have the Peloton time sync setting on and I'm using Samsung Dex - I had turned off auto-start but forgot to turn off the time sync one. My guess is that this is just part of the problem with Samsung Dex so don't want to open an issue unless you want me to. I've turned off the time sync for now and will see if that fixes it.

thanks for the log @marklogan17 I will check it later. About the DEX issue is still pending #1307 . DEX is not a standard android thing and is not supported by OCR natively

marklogan17 commented 1 year ago

Yeah I had no real expectation that the DEX stuff would work and certainly don't spend time on it for me. Only mentioned it in case its not related to DEX.

cagnulein commented 1 year ago

ok let's try to check it

I started checking the ehi mark, i'm doing your stuff :) resetting everything for SS2K thing and i found the first one here

Mon. Mar. 6 07:29:40 2023 1678105780435 Debug: ../src/smartspin2k.cpp void smartspin2k::autoResistanceChanged(bool) ehi mark, i'm doing your stuff :) resetting everything for SS2K

so i went back in order to check the last resistance change and i found this

Mon. Mar. 6 07:29:23 2023 1678105763867 Debug: ../src/smartspin2k.cpp void smartspin2k::characteristicChanged(const QLowEnergyCharacteristic &, const QByteArray &) Resistance received from SS2k: 15 Mon. Mar. 6 07:29:24 2023 1678105764004 Debug: ../src/trainprogram.cpp void trainprogram::scheduler() "trainprogram change requested peloton resistance 35"

so qz sends a 17

Mon. Mar. 6 07:29:24 2023 1678105764005 Debug: ../src/bluetooth.cpp void bluetooth::debug(const QString &) "writing resistance 17"

and the SS2K answered me back with a

Mon. Mar. 6 07:29:24 2023 1678105764319 Debug: ../src/smartspin2k.cpp void smartspin2k::characteristicChanged(const QLowEnergyCharacteristic &, const QByteArray &) Resistance received from SS2k: 17

BUT i tried also to check this

I hit a manual gear button to get the resistance up a level and immediately the resistance dropped all the way to zero.

and I find it, it's very clear that SS2K desyncs from the real resistance of the bike starting from here

Mon. Mar. 6 07:27:56 2023 1678105676768 Debug: ../src/echelonconnectsport.cpp void echelonconnectsport::characteristicChanged(const QLowEnergyCharacteristic &, const QByteArray &) "Current resistance: 27"

From this point and on, the echelon resistance started to decrease to 1 while SS2K thought to be at a completely different value.

I don't see any command from QZ to SS2K before this that justify this behaviour.

@doudar any idea?

doudar commented 1 year ago

It's difficult to say without a SS2K log but possibly since QZ is syncing cad and watts to SS2K, the power table function may be limiting the stepper travel. @marklogan17 , you could try disabling those by setting min brake watts and max brake watts to 0.

marklogan17 commented 1 year ago

It's difficult to say without a SS2K log but possibly since QZ is syncing cad and watts to SS2K, the power table function may be limiting the stepper travel. @marklogan17 , you could try disabling those by setting min brake watts and max brake watts to 0.

I'll try that. Would that happen only on occasion or would it be consistent? This only happens reasonably rarely and seemingly only when there's multiple levels of resistance change. Never seen it below say 3 or 4 levels of resistance change and normally more like 7 to 10.

doudar commented 1 year ago

It would probably be when there are large changes in resistance (where SS2K calculates that it might be over the max brake watts). The limits are continuously recalculated so smaller changes are less likely to hit the soft limit. Limits should be disabled whenever the SS2K is under QZ control, regardless of weather this is your specific problem or not. I'll create an issue.

marklogan17 commented 1 year ago

It would probably be when there are large changes in resistance (where SS2K calculates that it might be over the max brake watts). The limits are continuously recalculated so smaller changes are less likely to hit the soft limit. Limits should be disabled whenever the SS2K is under QZ control, regardless of weather this is your specific problem or not. I'll create an issue.

I've set min brake watts and max brake watts to zero and turned off HR->PWR. Will be doing a ride tomorrow morning (hopefully) so will report back after that. Thanks for the help.

marklogan17 commented 1 year ago

Did a ride today and it happened again 4 times. Around 20:45 left, 12:30 left, 5:30 left and around 2 minutes left. The last two times there was another resistance change before I could do anything and it actually fixed itself, so that was good, although I did 'un-sync/sync' unnecessarily on the 5:30 one. The first two I didn't do any manual resistance changes this time. Just stop auto resistance, start auto resistance, change gear - that forced a resistance change and off we went. Hmm, maybe next time I'll just change gear, could be I'm doing even more unnecessary steps :)

Anyway, as mentioned in the last message, I had the brake watts at zero, HR->PWR off. It really just looked like SS2K didn't change the resistance.

debug-Fri_Mar_10_07_17_44_2023.zip

marklogan17 commented 1 year ago

So a couple more details... Happened again this morning a couple of times. First time was only from 27 to 25 resistance so not that big. I think the second time was bigger but honestly as I was trying to sync it back up I accidentally closed the app so, well, the various numbers weren't my focus at that point.

Anyway, when it happened I used the un-sync/sync and hit the gear button. Didn't work perfectly this time but near enough that I could manually change the resistance one level. The second time it happened I remembered I just wanted to hit the gear button to try and fix it. It didn't work - i.e. it didn't change the gear. It changed the resistance one level. That says to me that there's more going on here. Somehow I think the SS2K doesn't think its being controlled by QZ in the same way anymore. Hitting the un-sync and then sync brings it 'back' to the right status and hitting the gear button then controls the gears.

Log attached. The issues should be near the end of the log because it was just as I was fixing it that I hit 'close' on QZ :)

debug-Mon_Mar_13_07_15_10_2023.log

cagnulein commented 1 year ago

@doudar it's possible that these issues are releated to the watt/cadence/hr sync frames that I'm sending? I know that sometimes ago you told me that it could create some issues to the stack or similar. Since it's not a PZ ride, for @marklogan17 case we can try to remove them, what do you think?

doudar commented 1 year ago

@doudar it's possible that these issues are releated to the watt/cadence/hr sync frames that I'm sending? I know that sometimes ago you told me that it could create some issues to the stack or similar. Since it's not a PZ ride, for @marklogan17 case we can try to remove them, what do you think?

It could be because of a pretty high interrogation frequency. If you can lower it, that might help.

rp8082 commented 1 year ago

@marklogan17 Are you riding with FulGaz or another app for this issue? Thx…

marklogan17 commented 1 year ago

This is all SS2K on my Echelon Sport. QZ as.main controller. Peloton classes setting the resistance requests. So specific resistance levels, not based on power or anything like that.

cagnulein commented 1 year ago

@doudar it's possible that these issues are releated to the watt/cadence/hr sync frames that I'm sending? I know that sometimes ago you told me that it could create some issues to the stack or similar. Since it's not a PZ ride, for @marklogan17 case we can try to remove them, what do you think?

It could be because of a pretty high interrogation frequency. If you can lower it, that might help.

Ok I will turn them off with a setting, just to experiment with this. Thanks

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

marklogan17 commented 1 year ago

@doudar @cagnulein I built a V3 of the SS2K (thanks to @eMadman for selling me the board and answering some questions). Its much better compared to my V1 with no PCB - so congrats on the engineering for that @doudar. Anyway I did a ride this morning and while I will continue to tweak my shift step settings, with the Echelon sport it seems that there always ends up a case where you don't quite get it to the right spot so it either doesn't change resistance level or it goes far enough that its almost one level high or low. Plus occasionally I get the out of sync problem mentioned in the issue above.

So, I'm wondering if the best solution may be to stop using the physical buttons to control the QZ gear selector because once out of sync, they're pretty useless. I was thinking maybe the best thing for them would be a configurable amount of turn - i.e. a configurable number of shift steps for a button push. Where I started was maybe 1/4 of the shift steps for a full resistance level - just so you're tweaking it to get back in sync. But then I thought maybe you just let people specify a number of shift steps. Maybe on my bike the tweak I need is 1/2 of a full resistance level. Maybe I want it 10% so I can hit it a couple of times to get exactly the level I want.

I don't know if that's possible in the current interface. Maybe you can only change a full resistance level at a time. Really I'm just looking for a way to get back in sync when it gets out without having to reach down and try and fight the motor and manually turn the knob.

Now that I'm thinking about it, maybe the way to do it is set the shift steps in SS2K config to the value I want the physical buttons to use and then in QZ there's the shift step setting for the full resistance level change. Then the physical buttons operate on the SS2K config and the QZ/SS2K interface for resistance changes stays as is. Just have QZ ignore the physical buttons.

Thoughts? Am I over complicating everything?

cagnulein commented 1 year ago

@marklogan17 just to understand: if you don't use the hardware buttons of the SS2K, and maybe you use only the gear tile of QZ, you don't have this kind of issue?

marklogan17 commented 1 year ago

@marklogan17 just to understand: if you don't use the hardware buttons of the SS2K, and maybe you use only the gear tile of QZ, you don't have this kind of issue?

No the physical buttons and the gear tile work the same right now. They aren't the problem. The problem is that QZ and SS2K get out of sync for a couple of reasons: First, the shift steps aren't perfect and I don't think the resistance change is linear so eventually during the ride you're off by 1/2 a resistance level - just needs a small manual turn to get it right. Second I occasionally get the situation where the SS2K just doesn't move for the larger resistance changes - so QZ thinks its at 29, the target is 29 and the current resistance is 24 - again, I need to manually turn it to get it back at the right spot.

The manual turning is really what I'm trying to eliminate. Its especially not good on the V3 version of the SS2K. So I was thinking that instead of having the physical buttons and the gear tile do the same thing, we could have the gear tile keep doing what it does and the buttons manually move the resistance without changing target. I'm just trying to get things back in sync.

cagnulein commented 1 year ago

hah got it. So if i'm understanding it well, the only way to do so, is with a mod in the SS2K firmware? or do you see any other way to do so in QZ?