TSDZ2 mid drive with 860C, 850C or SW102 displays only -- Flexible OpenSource firmware (Casainho code only)

The New Cadence Sensor Code

As many of you know I have been trying to figure out how to best increase the feeling and response of the entire system. The cadence sensor is one small part of the development but is very important part nonetheless. Especially at startups, when shifting gears and also when you stop pedaling and the motor is supposed to disengage. The time delay in the latter situation is often called the power-off-lag. In short, a good cadence sensor implementation provides a safe and responsive system.

Startups: We need to confirm that the user is rotating the pedals to enable assistance. So we do this by increasing the minimum cadence measured by the system and thus get a more responsive startup. But in doing so we also introduce a time delay as the system needs to wait for the transitions. We partly solve this by optimizing the code overall. But, in some situations, there might still be a considerable delay between the moment the user stops pedaling to the moment the motor stops giving assistance. This is the power-off-lag.

Power-off lag: To solve the power-off-lag we change the resolution and therefore the response time depending on wheel speed. No point in measuring down to 5 RPM and waiting for transitions when going fast. For instance, if we are going at a speed of 20 kph, or almost 13 mph, with a gear ratio of 52 to 11 teeth, the crank cadence is around 30 RPM.

So now, the resolution will automatically adjust appropriately and we get a much faster response.

What more can we do?

This is a very, very, simplified model of a cadence sensor disc with 6 magnets and the transition states for a complete revolution. Note that the TSDZ2 has 20 magnets in its cadence sensor disc but we are keeping it simple with only 6 magnets:

Simplified Cadence Sensor Model with 6 Magnets (100).png

The blue fields represent the magnetic fields strong enough to measure as HIGH in the system. The grey fields represent the opposite and is measured LOW in the system. There is a magnet in the center of all the blue fields.

Usually, when calculating the rotational speed of the crank you measure the time between two transitions and take in to account the number of transitions there are in the cadence sensor disc. The transitions that are measured are often of the same kind. One example of transitions of the same kind is when the cadence sensor pin state is going from LOW to HIGH. In our example this means we only count the transitions that go from GREY to BLUE. We discard the transitions that go from BLUE to GREY.

I was curious of using all the transitions but knew that if the spacing between the different transitions was not the same it could be problematic. So I tested for every transition and got this, which I also posted previously in the thread:

fedd.jpg

It looked like we had a nice distribution of transitions and it seemed the spacing was the same between all transitions. So this made me very happy as we could just make one very small change and immediately half the response time. But this was not the case.

Following is an exaggerated version of the reality where I want to make it very clear what problem we must solve. Firstly, here we have strong magnets in the cadence sensor disc. So the spacing between LOW to HIGH -> HIGH to LOW is longer than the spacing between the HIGH to LOW -> LOW to HIGH.

Simplified Cadence Sensor Model with 6 Magnets (Over 100).png

Secondly, here we have weak magnets in the cadence sensor disc. So the spacing between the LOW to HIGH -> HIGH to LOW is shorter than the spacing between HIGH to LOW -> LOW to HIGH.

Simplified Cadence Sensor Model with 6 Magnets (Less than 100).png

So let us call this discrepancy a difference in magnet pulse width. Sadly, this value is different for every cadence sensor. Meaning calibration is needed for every user that wants to have the more responsive cadence sensor. I had the opportunity to test on two different TSDZ2 units, one very old and one completely new. One unit got 67 % HIGH and 43 % LOW and the other 40 % HIGH and 60 % LOW.

With clever code we can make this all work very nicely and have the equivalent of 40 magnets. Making the cadence sensor react faster, with less rotation to engagement and make the overall system more responsive.

What I wish to do today is an automatic calibration process. The user will be able to choose between the standard or extra cadence sensor mode. If the user chooses the extra cadence sensor mode a small calibration process is needed but the TSDZ2 will manage everything. The user only needs to hold one button and it is all configured automatically.

So if no one minds I will try to add this automatic calibration process and save a lot of time writing a tutorial with tips and tricks. As it will all be done automatically. So in the long term this will probably be more time efficient and will result in an even better experience for users.

Another reason this is especially important to do is that it can greatly help users that use the coaster brake version. Where it is very important with a fast response. So I hope everyone understands why I want to implement the automatic calibration process instead of the manual calibration. Do note that I will continue to work several hours per day with the development until the beta is out!
 
casainho said:
Hmm, I got a different of 30kgs between left and right pedal: 100 kgs on right and 70 kgs on left so I think it should not be ignored.

Hm, it would be interesting, if other users have this difference, too. Especially the fact, that there is the difference of 168 vs. 184 ADC value from left to right pedal in horizontal position with no load at all is very strange. So you must have an oszillating signal if you turn the cranks without load. Are you sure, that your sensor is mounted properly, all little springs of the coils in place?!

The more I learn about the torque sensor, the more I think that it's not a masterpiece of engineering arts. :mrgreen:

What is the frequency for the power supply of the coils? With stock firmware it's about 150 kHz.
https://www.pedelecforum.de/forum/index.php?threads/funktionsprinzip-drehmomentsensor-im-mittelmotor-sfm-du-250-p-tsdz2.45029/

regards
stancecoke
 
buba said:
Just merged my local eMTB branch so if you want to take a look at it

OK, so the current target is just calculated by torque ^ exponent, where the exponent can be between 1.3 and 2.0
To avoid the exponential (power) math function, you have defined several lookup tables.

Hm. In the very first beginning, I experimented with
current = factor*torque^a*cadence^b
but I found it is not very sensitive. I even played around with exponents smaller than 1.
It's very important for me, to be able to keep any speed just with the control of my legs without adjusting assistance levels at the display (as I have no display :D) especially when riding in a group of several riders.


I ended up with
current=factor*torque*cadence*(1+speed/max_speed)
This works perfect for me. But as i mentioned before, I don't ride in the mountains, so I can't judge, if it works satisfying there, too.

regards
stancecoke
 
stancecoke said:
buba said:
Just merged my local eMTB branch so if you want to take a look at it

OK, so the current target is just calculated by torque ^ exponent, where the exponent can be between 1.3 and 2.0
To avoid the exponential (power) math function, you have defined several lookup tables.

Yes and yes. Basically the harder you push on the pedals the more power you get and it is not linear. This enables maximum power when pushing hard but normal power in normal situations. All without changing assist levels as is usually done in other riding modes.

I forgot to mention I removed the wheel speed power offset to make it more natural but I think you noticed that.



stancecoke said:
Hm. In the very first beginning, I experimented with
current = factor*torque^a*cadence^b
but I found it is not very sensitive. I even played around with exponents smaller than 1.

Good that you shared that. Was thinking on a lot of different implementations... But settled on this one as it can be configured easily.



stancecoke said:
I ended up with
current=factor*torque*cadence*(1+speed/max_speed)
This works perfect for me. But as i mentioned before, I don't ride in the mountains, so I can't judge, if it works satisfying there, too.

regards
stancecoke

Will you consider testing my code and comparing it to yours? Should be possible very soon with the coming beta. I would like to hear what you feel is more natural as you have something to compare to. From what I have heard, eMTB should be the most natural riding mode. Or at least a mode where users do not feel they need to change assist levels.

I can implement your code as well just to try it out but that will be later as I need to finish some work.

---------------------------------

Really look forward to everyone testing out all the riding modes!
 
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you
 
chri27.5 said:
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you

Good morning,

Hmm... As a developer I have several times forced the motor to run and have created several private versions that do continuously run for testing. But have never had a motor-run-away problem on a stable release with my personal settings. But I think there are certain cases and situations where it maybe is possible to force a motor-run-away on a stable release. Not sure though. Have nonetheless actively worked to eliminate all possible safety problems in the next version.

Have you experienced any problems? If so, please let me know! Also include your settings when it happened and the overall situation that caused it. I will try to help!
 
chri27.5 said:
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you
Yes, recently with 0.19.0. Even the brake sensors didn't stop the motor, luckily for me the motor was imwas not pushing strong forward...
 
I read that the motor won't start if out of voltage range, for example using a fully charged 52v battery with 48v configuration. But in that case, will the display still power up and be usable? And only the motor will refuse to drive?

I am just pondering the possibility of having multiple battery configurations stored and being able to change between them using the display. So if you have two batteries with different voltages, you could swap them without needing to flash the firmware each time.
 
casainho said:
chri27.5 said:
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you
Yes, recently with 0.19.0. Even the brake sensors didn't stop the motor, luckily for me the motor was imwas not pushing strong forward...

Yes, I have seen that with a bad torque sensor. A bad torque sensor will do exactly what you describe. Also, if the torque sensor initializes with backward force on the pedals it can do that. The backward force is usually only possible with a coaster brake motor.
 
Rydon said:
casainho said:
chri27.5 said:
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you
Yes, recently with 0.19.0. Even the brake sensors didn't stop the motor, luckily for me the motor was imwas not pushing strong forward...

Yes, I have seen that with a bad torque sensor. A bad torque sensor will do exactly what you describe. Also, if the torque sensor initializes with backward force on the pedals it can do that. The backward force is usually only possible with a coaster brake motor.
For me was not a bad torque sensor, it was for sure a problem/bug with the firmware, because I verified that brakes were not cutting the motor power, basically, it was like if the system were stuck and the main loop that read the sensors and then setup a specific motor current, was not running. I had to turn off the motor on the LCD and just after I did turn on again and everything were working perfectly again. And this was the first time happening to me.
 
famichiki said:
I read that the motor won't start if out of voltage range, for example using a fully charged 52v battery with 48v configuration. But in that case, will the display still power up and be usable? And only the motor will refuse to drive?

I am just pondering the possibility of having multiple battery configurations stored and being able to change between them using the display. So if you have two batteries with different voltages, you could swap them without needing to flash the firmware each time.
Go and read the wiki of our firmware to clarify your question.
 
Has anyone had a difficult time finding working LM35s for the temperature sensor? I've bought 2 lots of 10 from different vendors and I can't get it to work on the open source software. The bike just doesn't register any change from the sensor. I guess part of the problem is that they're from ebay and chinese knockoffs, but you would think that 1 in 20 would be ok. I've tested the bike with TMP36 and a 10k potentiometer and they both report values that change with input so I don't think its my soldering job.
 
casainho said:
famichiki said:
I read that the motor won't start if out of voltage range, for example using a fully charged 52v battery with 48v configuration. But in that case, will the display still power up and be usable? And only the motor will refuse to drive?

I am just pondering the possibility of having multiple battery configurations stored and being able to change between them using the display. So if you have two batteries with different voltages, you could swap them without needing to flash the firmware each time.
Go and read the wiki of our firmware to clarify your question.

It says you can change the individual settings for the battery through the display, but I couldn't find anything about making multiple preset profiles.

So, if I have it set up for 48V and swap in a fully charged 52V battery will the controller and display still power up and allow me to change those settings? Or do I need to change the settings before swapping the batteries?
 
famichiki said:
casainho said:
famichiki said:
I read that the motor won't start if out of voltage range, for example using a fully charged 52v battery with 48v configuration. But in that case, will the display still power up and be usable? And only the motor will refuse to drive?

I am just pondering the possibility of having multiple battery configurations stored and being able to change between them using the display. So if you have two batteries with different voltages, you could swap them without needing to flash the firmware each time.
Go and read the wiki of our firmware to clarify your question.

It says you can change the individual settings for the battery through the display, but I couldn't find anything about making multiple preset profiles.

So, if I have it set up for 48V and swap in a fully charged 52V battery will the controller and display still power up and allow me to change those settings? Or do I need to change the settings before swapping the batteries?
Will always let you change the configurations.
 
hydrinium.h2 said:
Has anyone had a difficult time finding working LM35s for the temperature sensor? I've bought 2 lots of 10 from different vendors and I can't get it to work on the open source software. The bike just doesn't register any change from the sensor. I guess part of the problem is that they're from ebay and chinese knockoffs, but you would think that 1 in 20 would be ok. I've tested the bike with TMP36 and a 10k potentiometer and they both report values that change with input so I don't think its my soldering job.

Yes,
after several attempts from different sellers, I bought them on Amazon choosing the product based on feedback
 
vadda said:
hydrinium.h2 said:
Has anyone had a difficult time finding working LM35s for the temperature sensor? I've bought 2 lots of 10 from different vendors and I can't get it to work on the open source software. The bike just doesn't register any change from the sensor. I guess part of the problem is that they're from ebay and chinese knockoffs, but you would think that 1 in 20 would be ok. I've tested the bike with TMP36 and a 10k potentiometer and they both report values that change with input so I don't think its my soldering job.

Yes,
after several attempts from different sellers, I bought them on Amazon choosing the product based on feedback
You guys should report negatively that sellers on eBay.
 
Hello everyone,

I have been reading the last few pages and I can't wait to test the new sensor calibration. Thank you dev team for making this possible!
I know that there is a memory issue with KT3 lcd and new features cannot be added, but the motor functionality features are the most important to any rider and they should be included if possible. Like stancecoke said 95% of configuration is done initially and then we just change the assist levels and enjoy the ride :). Also the big majority of users has KT3 lcd setup already installed.
My ideas on the matter are:
- prioritize the list of existing features so the most important are preset
- use Marcoq's idea and use a simple UI to make the bike specific configuration, or even a simple property file that is configured before installation and then a script that sets constants in the motor code.
Keep in mind that sensor calibration does not need to be configurable, just set once for each motor. I could modify constants like MAX_ERPS, rebuild and that's it.

Regards!
 
casainho said:
vadda said:
hydrinium.h2 said:
Has anyone had a difficult time finding working LM35s for the temperature sensor? I've bought 2 lots of 10 from different vendors and I can't get it to work on the open source software. The bike just doesn't register any change from the sensor. I guess part of the problem is that they're from ebay and chinese knockoffs, but you would think that 1 in 20 would be ok. I've tested the bike with TMP36 and a 10k potentiometer and they both report values that change with input so I don't think its my soldering job.

Yes,
after several attempts from different sellers, I bought them on Amazon choosing the product based on feedback
You guys should report negatively that sellers on eBay.
Right
In my specific case the sellers were physical stores
 
casainho said:
Rydon said:
casainho said:
chri27.5 said:
good morning,
a question for buba & casainho,
Has it ever happened to you that the motor suddenly remains on while you are pedaling and continues to turn without ever stopping?
Thank you for your wonderful job that with patience and dedication you carry on.
Excuse my English
Thank you
Yes, recently with 0.19.0. Even the brake sensors didn't stop the motor, luckily for me the motor was imwas not pushing strong forward...

Yes, I have seen that with a bad torque sensor. A bad torque sensor will do exactly what you describe. Also, if the torque sensor initializes with backward force on the pedals it can do that. The backward force is usually only possible with a coaster brake motor.
For me was not a bad torque sensor, it was for sure a problem/bug with the firmware, because I verified that brakes were not cutting the motor power, basically, it was like if the system were stuck and the main loop that read the sensors and then setup a specific motor current, was not running. I had to turn off the motor on the LCD and just after I did turn on again and everything were working perfectly again. And this was the first time happening to me.

Do not know what LCD you were running and system settings but regardless, this is exactly why the 0.20.0 is developed so heavily. It will be that much better and safer.
 
Hi all,
I am new to this opensource firmware and I am very interested in the possibility to use it with a smartphone app.
I've seen there is development in this direction with the SW102. But I was wondering if the required logic cannot be implemented directly in a smartphone app. Has anyone looked into this? I remember seeing a video of someone that had installed a bluetooth command to start their throttle using a smartphone, but I can no longer find it.
I would be interested in doing at least some of the devel myself, if I am not the only interested person ;).
 
csbike said:
Hi all,
I am new to this opensource firmware and I am very interested in the possibility to use it with a smartphone app.
I've seen there is development in this direction with the SW102. But I was wondering if the required logic cannot be implemented directly in a smartphone app. Has anyone looked into this? I remember seeing a video of someone that had installed a bluetooth command to start their throttle using a smartphone, but I can no longer find it.
I would be interested in doing at least some of the devel myself, if I am not the only interested person ;).
Then please follow the github SW102 issues as current active developers are getting coordinated there. And since I know, no one is developing the mobile app and a working beta/alpha version of SW102 is expected on the end of this week.
 
I will,
thanks.
Is there actually a simulator/emulator with which I can do development and testing without flashing the thing each time?
 
csbike said:
I will,
thanks.
Is there actually a simulator/emulator with which I can do development and testing without flashing the thing each time?
Not that I am aware. Please ask on GitHub as the developers there seem to no follow much this thread.
 
buba said:
Startups: We need to confirm that the user is rotating the pedals to enable assistance.
I don't agree on this, otherwise the throttle alone could not be used. We can provide motor assistance as soon user makes a specified minimum amount of force on the pedals, even before they start rotating.

buba said:
So we do this by increasing the minimum cadence measured by the system and thus get a more responsive startup.
Again, a more responsive startup is using the torque sensor. Or why do we have a torque sensor on this motor?
 
Back
Top