OttoDIY / OttoDIYLib

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

Limit servo speed for smooth move and preventing potential crash #24

Closed takujikawata-pr closed 3 years ago

takujikawata-pr commented 3 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 is 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 default is 6 which means, for each command to servo, the servo speed is limited to 6 degrees to the previous angle. This library typically sends commands to servo in 10msec / 30msec intervals and setting 5 or 6 was the reasonable limit at my test. Following is the example to set the limit to 3.

screenshot2

Following is the motion (video) when the limit is set to 3. 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.