Closed firkowski closed 11 months ago
Hi @firkowski,
Cool to see someone using Servo 2040 for the primary purpose I designed it for!
The issue you are experiencing is expected, due to the RP2040 *only having 16 PWM channels. As such when you create the 17th and 18th servo classes, even though they are independent classes, the same hardware registers will be controlled, resulting in what you describe.
The way around this is to switch from using the Servo
class to using the ServoCluster
class. This is a PIO implementation of PWM that supports 1 to 30 of RP2040's pins. It also offers phase control, so that servos don't all receive their commands at the same time, spreading out the peak current draw.
You can find the code for ServoCluster
at: https://github.com/pimoroni/pimoroni-pico/blob/main/drivers/servo/servo_cluster.hpp
It seems I never got to writing documentation for the C implementation of this class, but the Micropython documentation should help you. https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/servo#servocluster There is also this example: https://github.com/pimoroni/pimoroni-pico/blob/main/examples/servo2040/servo2040_servo_cluster.cpp
This should be a relatively painless transition for your code, as the APIs for the two classes were written concurrently (they both use the same ServoState
object internally). So for your code, the main change would be to swap std::array<std::unique_ptr<Servo>, NUM_SERVOS> servos;
over to a single ServoCluster
instance.
Hope that helps. Let me know if you have any specific questions
Closing this. If there are any bugs with getting it working, please reopen this or raise a new issue.
It works great now, thank you! One thing is that I can't figure out how to apply calibration to the servos in ServoCluster. There does not seem to be a calibration(servo, calibration) function in the c++ code, or at least i can't find it
edit: in the code, some parts are not used to simplify debugging. the #define servo constants are not used
hello, I am working on a hexapod project and i am using Servo2040 board with micro-ROS. I noticed strange behavior when running my C++ code. servos 1 and 17 would shake uncontrollably and change directions rapidly. it took me a while to realize that servos 1 and 17 and 2 and 18 were moving in the same way. I may have an issue with the I2C causing them to receive the same signals (i think the reason for the shaking was that servos 1 and 17 were receiving two signals at once). I would like to be able to control them independently. My full code (modified for testing) is below but I've highlighted the part that causes problems.
problematic part:
whole code: