Admin, .... as well as a code problem.......
Well its not really a bug. The released code copes with a 'certain' number of servos. Hassan pushed this limit and got practical problems. My new code (unreleased as of yet) just increases this 'certain' number to make his problem 'go away'ish. But if anyone believes than they could drive 40, 60 etc servos - then they will get the same problem. There's only so much liquid that goes into a pint glass!!
So I haven't 'fixed' the code - I've just 'improved' it to cope with more.
Webbot, I'm curious to hear how you changed your servo drivers. Care to explain?
Ok - but its a bit complex. Maybe needs timing diagrams but I dont have time!
Version 1 (prior to release of WebbotLib - but just for the history)
Set the pin for the first servo in the bank.
Set timer callback for 'end of pulse'.
When called it cleared the pin.
Repeat for all servos in the bank.
Add a callback to be (20ms - (sum of all pulses)) - so that it repeats every 20ms.
This fried servos!
Heres why. Think of a bank of 8 servos and thing only about servo#6.
In the 20ms frame then its start time is effected by the length of the pulses for servos #1- #5
So if servos #1 to #5 now have a smaller pulse then the pulse for #6 will start sooner. Compare this to the start time for #6 on the previous frame then it can be less than 20ms.
This technique guarantees servo #1 getting a pulse every 20ms but the further down the bank you go then the pause between frames is effected more and more by the earlier servos.
Hence the later servos could 'fry' - as they may get pulses every 12ms say.
Version 2 - for first release and up until current release
Uses the same technique except that at the end of a bank it would pause for (20ms - the duration of the last servo pulse).
This guarantees a min delay of 20ms for all servos - so no frying!!
But it also means that the length of a frame is no longer '20ms' but is 'sum of all pulses + 20ms - last pulse'.
So as you add more servos then the frame time changes from 20ms upwards.
Hence Hassans problem of servos going floppy.
Version 3 - for next release and what Hassan is using.
For each servo in a bank we know the max pulse time (the center parameter + the range parameter for each servo MAKE) as well as the currently required pulse time.
So we will overcome the problem of Version 1 by making sure that each servo gets the start of its pulse every 20ms.
I do this by using one Timer Compare to start each pulse at which time it adds two callbacks: one clears the pulse after the required duration, and the other is called after the max pulse time to repeat for the next servo.
Once all servos are done then we pause for the rest of the 20ms (if any) since we did the first servo.
So the pulse start for ANY servo always happens every 20ms since it is always made up of a HIGH and a LOW phase where HIGH+LOW is constant.
The number of servos is constant and so the time for one pass is also constant
So the pause (if any) before repeating is always constant.
So I am now using 2 compare units for each servo bank rather than one.
I hope that makes sense (but it's not for newbs!).
And if you are just a user of WebbotLib then 'dont worry' - its just techno garb.