I'm using 2 x Hiwonder LX-16A servos to move a shelf backwards and forwards continuously. However I'm having some trouble getting them to move. If I only control one of them, it rocks backwards and forwards quite happily but the two together just seem to stall or not move at all. The code I'm using is:
void loop() {
// Loop from 0 to 1000 in steps of 4
// This is 0 to 270 degrees in roughly 1 degree increments
for (int loop = 0; loop <= 1000; loop += 4)
{
// Move servo 1 by 4 position points in 4ms
// This gives full range of movement in 1 second
LobotSerialServoMove(Serial, ID1, loop, 4);
// Pause 4ms for the move to occur
delay(4);
// Repeat for servo 2 but in the opposite direction
LobotSerialServoMove(Serial, ID2, 1000 - loop, 4);
delay(4);
}
// As above but in the opposite direction
for (int loop = 1000; loop >= 0; loop -= 4)
{
LobotSerialServoMove(Serial, ID1, loop, 4);
delay(4);
LobotSerialServoMove(Serial, ID2, 1000 - loop, 4);
delay(4);
}
}
LobotSerialServoMove(Serial, ID1, loop, 4) means:
On the Serial interface, for servo identified by ID1, move to position "loop" and take 4ms to do it.
I'm guessing that I'm misunderstanding the way in which writes to the Serial interface work and sending the commands too quickly - and confusing the receiving interface board? But that's purely speculation based on the fact that one servo in isolation seems quite happy. I *thought *that the commands to the Serial interface wouldn't wait for move to occur and once the send has finished, processing would move on - hence the delay. If the servo is asked to move to the new position in 4ms the waiting 4ms will ensure that it has moved. I did try extending the time but both servos appeared to get to the "500" position and then judder in an indecisive way!
Has anyone experience in using these servos who can advise where I'm going wrong?
What I'm trying to achieve is:
- Servo 1 rotates clockwise from 0 to 1000
- Servo 2 rotates anticlockwise from 1000 to 0
- Servos keep aligned - they're at either end of a shelf so I want to stay level
- About 2 seconds to cycle from 0 to 0 through 1000
Thanks.