OttoDIY / OttoDIYLib

Latest and official Libraries for Arduino Otto DIY robots
http://www..ottodiy.com/
GNU General Public License v3.0
111 stars 73 forks source link

Limit the speed of servo motors for smoother and stable movements #25

Closed takujikawata-pr closed 2 years ago

takujikawata-pr commented 2 years ago

About this change

Servo motors sometimes move too aggressively typically when a motion moves to another and it sometimes makes the arduino crash because of the high current drained into the motors. This change limits the speed of the servo motors by having the previous position and checking the differences. For backward compatibility, this feature is disabled by default. This feature is enabled by adding the following code into the Otto Blockly / Arduino projects.

     Otto.enableServoLimit();

Following is the example to apply the feature into a Otto blockly project.

screenshot1

Following video demonstrate the effect (videos):

No limit https://drive.google.com/file/d/1ind8VeGXa1izIdFk42XV6do8Ohr1Dj4j/view?usp=sharing

Apply the limiter https://drive.google.com/file/d/1TL_hsLVUXM647yDn95L8NPz5rY-kRKCl/view?usp=sharing

You also can adjust the limit by putting a parameter when you call enableServoLimit() function. The parameter can be given as degree / sec for the maximum rotation speed. The default value is 240. If you want to limit 120 degree / sec instead of 240 degree / sec, you can call the function as follow;

     Otto.enableServoLimit(120);

Following is the motion (video) when the limit is set to 120. You can see the movement become more conservative https://drive.google.com/file/d/10tdl7VoxpnufJ3F-akJPz1v52Ke-LKhh/view?usp=sharing

Note

I propose this as an optional feature of this library this time but I feel this could be the feature turned on by default for make the Otto's move safer and stable side. Advanced developer can disable for their aggressive moves.

cparrapa commented 2 years ago

@takujikawata-pr thanks a lot this contribution looks amazing, i will give a try.