Energiz3r / robodog

4 stars 2 forks source link

create Servo Controller in NodeJS #4

Closed Energiz3r closed 1 month ago

Energiz3r commented 1 month ago

Create servo controller code in NodeJS

Energiz3r commented 1 month ago

As the 16x channel servo / PWM controller uses i2c for communication, this was a fairly simple implementation using a lib I found on npmjs. I created a servo controller class to implement an initializer and a setAngle function which maps angle to pulse widths to write to the channels of the controller.

This quickly crashed the OrangePi with memory overflow, and I realised the i2c driver is quite slow to resolve a write. Promises are returned from a write request, so I solved this by having the servo controller class ignore additional setAngle requests for that channel if the previous has not yet completed. This works well and there does not appear to be any side effect - I was concerned that this meant the driver was slower than my update rate of ~20ms but this does not appear to be the case as the responsiveness of the robot is visibly increased changing the update rate to as fast as 5ms. As it's working, and I don't want to edit the driver, I won't investigate further