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

crun said:
You might want to start by doing a torque sensor calibration. Make some hooks (or cable tie to the crank) so a wooden arm hangs off one pedal crank horizontally facing forward.
Hang a gym weight off the end. (This is a 2 person job)

You can zero by either unhooking the arm, or (if cable tied) , rotate until the arm is vertical so exerting no torque.

Torque= 9.8*N/kg * (GymWeight.kg** distance-from-axis.m + Wood-weight*WoodLength/2)

5kg at 1m + 2kg wood ~=60N.m

Power (W) = Torque (N.m) x Speed (RPM) 1000/ 9.5488

Not sure how me calibrating my torque sensor equates to seeing different watt calculations using "theoretical values".
 
linklemming said:
Not sure how me calibrating my torque sensor equates to seeing different watt calculations using "theoretical values".
From what you wrote it's not clear where the torque sensor value "50" came from.
I interpreted what you wrote as you assuming a calibration coefficient (from the source comments) for the torque sensor, leading to an assumed torque.

Personally (having not calibrated one yet) I don't see any particular reason to believe it has anything other than very rough calibration - it has no real need for it to be calibrated in any meaningful sense, in the manufacturers use case.

BTW, an alternative power measurement method is to climb a steep straight hill of known height at constant power/effort.

E(J)=mgh
P.pedal=E(J)/T(secs) / efficiency.

0.85 overall efficiency seems a reasonable guess for rolling resistance+powertrain loss+low speed wind resistance

So for my ride up the hills which is 514m climb, taking 60min = 198W overall. (and 680cals food @25% efficency)

Made some measurements during todays ride: 31m climb at the start = 361W. 183m climb at the end=254W.
 
On LCD3 you can see the calculated force value in Nm and the Power of the pedals. That values are calculated on the motor controller firmware.

Each ADC step equals to 0.33kg as per my tests, you can see the ADC value also on LCD3 so you can validate the calculations just looking on LCD3.

I considered the cranks to be 170mm.
 
I used this information:

https://www.engineeringtoolbox.com/torque-wrench-luggage-scale-d_1909.html

Improvised torque wrench with luggage scale

scale_wrench_torque.png


If you don't have a torque wrench available - or if you want to check the readings of the one you have - it is easy to improvise by using a standard wrench and a scale as indicated in the figure above.

The moment - or torque - can be calculated

T = F a (1)

where

T = moment or torque (Nm, ft lbf )

F = applied force (N, lbf)

a = length of the wrench (m, ft)

Note! - Most scales in the SI unit system measures weight - force due to the acceleration of gravity - in kg.

the difference between mass and weight.
The reading from the scale can be converted to N by using

F = m g

where

m = reading of the scale (kg, lbf)

g = acceleration of gravity (9.81 m/s2, 32.17 ft/s2)

Example - Measuring Torque with a standard Wrench and a Luggage Scale - readings in kg
The reading of the scale at the end of the wrench is 10 kg. The length of the wrench is 0.3 m. The moment exerted can be calculated

T = (10 kg) (9.81 m/s2) (0.3 m)

= 29.4 Nm

Example - Measuring Torque with a standard Wrench and a Luggage Scale - readings in lb
The reading of the scale at the end of the wrench is 20 lbf. The length of the wrench is 6 in. The moment exerted can be calculated

T = (20 lbf) (6 in)

= 120 lbf in

= 10 lbf ft


----

Once you are familiar with the torque at different revolutions per minute (rpm’s) the power is easy to calculate. The formula for power calculation is:

P = τ x n x 2 x pi

τ = Torque
n = roations/ second
pi = 3,14
 
I read through the thread and it seems like there was a lot of chaos but things have settled down a bit. One thing that worried me reading through the thread is that it sounds like the only real testing that's being done is with people on bikes. It's important that this code work right since a mistake could hurt or kill someone (i.e., the guy who had an unexpected power boost while turned sideways pointing off the edge of a drop-off getting started on a steep hill).

Are there any plans to write some unit tests? I'd like to start experimenting with this project but I'm extremely reluctant to try to make any functional changes until we have that. I'm picturing a small project in two parts:

* Refactor the control loop code to make it easier to test (similar to what vscope has proposed a few times).
* Write a test harness where we can supply time-series data of inputs (hall sensors, torque sensor, wheel speed sensor, throttle, brake cutoff, display-controlled settings, etc), and assert the resulting value of the motor currents. There's a good example of how the kind of time-series data we need can be supplied in a useful shorthand in some yaml here.

Then we can start building a collection of tests. First, basic and easy safety things, like asserting the e-brake cutoffs work, or the blocked wheel cutoff, max power limit, etc. This will also let developers iterate a lot more quickly. You can tell when your thing doesn't work in seconds instead of flashing, getting on the bike, and possibly risking injury.

I had a different idea for the project I wanted to work on (sensorless mode), but I don't think that I can in good conscious try to make any functional changes to this code until we have some tests. It's one thing if we have a bug that results in needing to reboot, or burning some mosfets. It's another if we send someone off the side of a cliff or into a busy intersection.

Thoughts?
 
Ron Paul's Blimp said:
Are there any plans to write some unit tests?
Do you have experience doing such tests on this firmwares for 8 bits microcontrollers and on this type of hardware projects? -- I don't and for me would be nixe to see others doing that and so I can learn... :)
 
casainho said:
Do you have experience doing such tests on this firmwares for 8 bits microcontrollers and on this type of hardware projects? -- I don't and for me would be nixe to see others doing that and so I can learn... :)

I have very little experience working with microcontrollers. My hope is that we can abstract away the hardware and unit test the functional code.
 
casainho said:
I used this information:

https://www.engineeringtoolbox.com/torque-wrench-luggage-scale-d_1909.html

Thanks for providing the link. I had a feeling my calculation wasnt correct using Force instead of torque but all the units cancelled out.
 
So I played around with this today using a workout stand. Also spent a few hours looking at the code and am convinced myself power calculations are correct(minus a few small errors like using 9.18 for conversion kg->n instead of 9.81). Not sure why I seem to see higher values on the road than I expect, perhaps I push harder when I look down :eek:

I think what I am seeing (correct motor output corresponding to assist levels and human power, diminishing at higher human power levels) is that I am running into the motor rpm limits (48V motor and 48V battery). I get my power from spinning and couldnt seem to easily get to 90rpm (from the advanced technical data submenu), The harder I pushed against this limit the more the expected motor output didnt match my input+assist). Basically with assist at 3, at 150 watts of my power was about 450watts from the motor. When I went as hard as I could(same gear and asist level) this changed to about 400W human power and about 200W motor power.

i guess with this setup I have to just go to a higher gear and push harder instead of spinning faster.

This also explains the fact that even with no speed limit I was unable to get much over 23mph with 26 inch 2.1mtb tires and 42x11 gearing. At 80rpm (where the motor seems to start holding me back), the speed is right about 23mph. Just verified this on the workout stand with hardly any resistance.

I was hoping for more like 30mph but Im ok with this limit now that I understand it.

Again, thanks to all for making this software available :bigthumb:
 
Hello All,

I have been searching and searching but haven't been able to find any instructions for setting up a Linux build environment for this project. I'm unsure of what the dependencies for this project are - I have pulled the repo and have openocd installed but that is about as far as I was able to get. Any help would be appreciated!

I am just working on the mechanical assembly at the moment but wanted to get the build environment set up so that I can soon start contributing to this project.

Many thanks,
Sid
 
Ron Paul's Blimp said:
It's important that this code work right since a mistake could hurt or kill someone (i.e., the guy who had an

Many years ago I read an article about ensuring software reliability, that went through various methodologies. One was that used when a Dutch institute wanted to write software to calculate the braking chains used to control the launching of a large ship down a slipway. Get it wrong and the ship rockets down the slipway, shoots across the canal into the otherside, rolls over or worse.

To ensure software reliability they seated the programming team in the front row of seats at the edge of the canal, directly across from the slipway.
It performed flawlessly.
 
sidmodi said:
but haven't been able to find any instructions for setting up a Linux build environment for this project.

The stm8 eforth project is developed on linux by Thomas. He uses SDCC compiler.

https://github.com/TG9541/stm8ef/wiki/STM8S-Programming
 
linklemming said:
So I played around with this today using a workout stand. Also spent a few hours looking at the code and am convinced myself power calculations are correct(minus a few small errors like using 9.18 for conversion kg->n instead of 9.81). Not sure why I seem to see higher values on the road than I expect, perhaps I push harder when I look down :eek:

I think what I am seeing (correct motor output corresponding to assist levels and human power, diminishing at higher human power levels) is that I am running into the motor rpm limits (48V motor and 48V battery). I get my power from spinning and couldnt seem to easily get to 90rpm (from the advanced technical data submenu), The harder I pushed against this limit the more the expected motor output didnt match my input+assist). Basically with assist at 3, at 150 watts of my power was about 450watts from the motor. When I went as hard as I could(same gear and asist level) this changed to about 400W human power and about 200W motor power.

i guess with this setup I have to just go to a higher gear and push harder instead of spinning faster.

This also explains the fact that even with no speed limit I was unable to get much over 23mph with 26 inch 2.1mtb tires and 42x11 gearing. At 80rpm (where the motor seems to start holding me back), the speed is right about 23mph. Just verified this on the workout stand with hardly any resistance.

I was hoping for more like 30mph but Im ok with this limit now that I understand it.

Again, thanks to all for making this software available :bigthumb:

I have absolutely no idea whether this addresses your issue or not,, but a couple of releases ago a “high cadence mode“ was introduced on an experimental basis. I never knew what this was supposed to be, but maybe this is exactly the answer to your observation? Maybe someone who knows can say something....
 
andyme said:
I have absolutely no idea whether this addresses your issue or not,, but a couple of releases ago a “high cadence mode“ was introduced on an experimental basis. I never knew what this was supposed to be, but maybe this is exactly the answer to your observation? Maybe someone who knows can say something....

Yeah, Im looking at that now. I was aware of it but saw the notes on probably being for 36V and the other warnings and didnt pursue it further.

Need to get build environment working today so I can start playing with this.

I would be happy if I could get cadence up to 100 which would be 30mph.
 
linklemming said:
andyme said:
I have absolutely no idea whether this addresses your issue or not,, but a couple of releases ago a “high cadence mode“ was introduced on an experimental basis. I never knew what this was supposed to be, but maybe this is exactly the answer to your observation? Maybe someone who knows can say something....

Yeah, Im looking at that now. I was aware of it but saw the notes on probably being for 36V and the other warnings and didnt pursue it further.

Need to get build environment working today so I can start playing with this.

I would be happy if I could get cadence up to 100 which would be 30mph.

i hope you will get some support...i cannot tell you wether your findings re. cadence are confirmed by others or not. i myself do not enter these cadence regions therefore i have no clue..i am happy with 20 mph and have reached 40 km/h with no problem but i do not remember at what cadence and i have 60T but with a 20" wheel.

as far as power in general is concerned: i am on 48 V and i can get readings of 750W with no problem. i set the limit to 18A

I have complained here that max power is reached too easily so that the various levels seem to be very similar and therefore suggested to be able to limit power output by level, but i got hardly any (positive, confirming) reaction...it is only after you mentioned your observation, that jbalat proposed his settings that differ very much from default...and then i used settings along these lines and suddenly the motor performs the way it makes sense to me....( i trusted the default settings, because in past versions they did work well and i was advised to use them...how could i know that suddenly it was not the case anymore?....)

there is alot of knowledge here, but it is not always being shared as much as it could be, which is a pity.

one thing is for sure though: although there are still several features missing/ issues to be solved, this firmware now really makes my bike much more fun to use than before.

I wish i was able to understand and write code...i would love to get into this...but i have absolutely no idea how to....
 
Assuming in firmware 16 that the next reading selected after battery volts is human power then there must either be something wrong with the calculation or not all torque sensors are created equal.


I can with reasonable effort and very fast cadence get that display up to about 600 in the first assist level which is set at the default level of 0.5 human power and that makes sense as the displayed motor watts is 300w. When just pootling along enjoying the scenery, motor watts is usually around 150w while the ODO field display of what I believe is human power hovers around 300 so that makes sense too.


Except no way am I supposed to generate that sort of human power, a brief google says the average cyclist can with effort maintain 150 watts so I am getting at least double the expected reading. Unfortunately the documentation has not caught up with 16.0 firmware so I am not 100% certain I am looking at is the calculated human power but I think it must be.


I also had a strange problem this afternoon which may help others, as it was cold and wearing thick gloves I inadvertently went into max power set up and raised it from the disable value 0 up to 25 and did not realise. When I set off again the bike accelerated away and then the motor suddenly cut out until I stopped and then set off again when the cycle repeated. The reason being I had power boost enabled but as soon as power boost was timed out the 25 watt limit kicked in and disabled the motor.
 
Rafe said:
The reason being I had power boost enabled but as soon as power boost was timed out the 25 watt limit kicked in and disabled the motor.

I am hundert percent positive that boost is not working in this version. On the contrary it only makes strange things. I had several incidents and issues when boost was on, and i have absolutely no issue now that boost is off. But then i would want boost to work correctly as i can feel that it would help...i have reported this as an issue on github, but i don't know if anyone will take care of this or not...
 
Rafe said:
The boost works fine for me, except there is still a bit of a lag

Have you had a chance to test it uphill like you get on the bike and you have to start pedalling already in an inclination going up?

What happens to me: i am riding home which is uphill. on the way up i have to stop and then i need to restart again. I can hardly get the bike going while it works ok when boost is off, except that it would be easier with a boost that would do what it used to do in the past or in the original firmware...
 
linklemming said:
I would be happy if I could get cadence up to 100 which would be 30mph.

It would be great to see cadence/torque/power graphs if you do play with it.
I am not sure if you have tried it with a 1/3 full battery yet? But the max cadence on stock firmware is pretty low once the battery gets down.

At some point, changing to the 36V motor becomes the correct solution. The ratio is only 36/48V i.e. if your cadence is 33% higher than "design", then the 36V will be better. At a given winding current, torque is only 25% less

It could very easily be that low battery+high natural cadence makes the 36V motor the correct choice for you.

(pswpower has replacement motors at $65)
 
crun said:
It would be great to see cadence/torque/power graphs if you do play with it.
I am not sure if you have tried it with a 1/3 full battery yet? But the max cadence on stock firmware is pretty low once the battery gets down.

At some point, changing to the 36V motor becomes the correct solution. The ratio is only 36/48V i.e. if your cadence is 33% higher than "design", then the 36V will be better. At a given winding current, torque is only 25% less

It could very easily be that low battery+high natural cadence makes the 36V motor the correct choice for you.

(pswpower has replacement motors at $65)

Thanks for the link to the 36V motor, good price too.

Im ok with the 48V motor for now, now that I understand all the limitations. It was my impression from jbalats opensource video review that there was not cadence limit anymore (within reason). I guess without this software, it was just lower still.

I did try the 'high cadence' mode for less than a minute and it didnt seem to make a difference, still seems to top out at 80-90rpm.

Its been awhile since i have ridden my brose bike(in the shop) but I recall it topping out around 90. I currently have a shimano esteps 8000 MTB loaner and I can spin it much higher
 
Rafe said:
Except no way am I supposed to generate that sort of human power, a brief google says the average cyclist can with effort maintain 150 watts so I am getting at least double the expected reading. Unfortunately the documentation has not caught up with 16.0 firmware so I am not 100% certain I am looking at is the calculated human power but I think it must be.

Most of these quotes on power are for some time frame like 1 hour. I have no doubt you can do 400W or higher for a brief period.

I was convinced there was an error in the human power calculation and went down the path of trying to prove it wrong and havnt succeeded. On my workout stand at lowish human power levels(i.e. 100) it seems close enough when I also look at the torque sensor values on the 'advanced technical data' submenu. The only real way to be sure would be to get some power measuring pedals but that is $$$.

As others have mentioned, perhaps I need to see if my torque sensor matches what the code is using for what each unit corresponds to (i.e. 1 unit = .52nm). Another possible thing is the torque sensor not being linear. It 'seems' (and I stress 'seems') that the caculated power gets artificially high as I start reaching the cadence limits but I am at that point spinning as fast as I can which requires more power from me to overcome the motor trying to hold me back. I know I couldnt do that for very long.
 
linklemming said:
Most of these quotes on power are for some time frame like 1 hour. I have no doubt you can do 400W or higher for a brief period.

The only real way to be sure would be to get some power measuring pedals but that is $$$.

The hill climb seems a good way to measure power without needing anything to be calibrated. (as long as you live somewhere with hills, or a multi-storey carpark with tight ramps).

I made measurements today and got 254W on a 15min, 180m climb, after 45mins cycling. (Yeah, I'm old and fat).

If you do it with the TSDZ2 at zero, you have to allow for the final gear friction loss when the motor is not running. (but really it couldn't be much more than 10-20W could it?)

Here is the start of a wiki pagehttps://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Calibrating-Torque-and-Power

BTW, most power measuring pedals are utterly inaccurate toys - much like Fitbit step counting - psychological not measurement tools.
 
Back
Top