Hi everyone
I want to synchronize the movement of a pair of servos but having trouble figuring this out, i know you can only execute 1 command at a time but i figured if you do a loop and move the pair in turn by a small increment it should be pretty close to synchronized (atleast to the naked eye). But i’ve tried this and the result is a very rough synchronization, more like a sequence of actions.
Does anyone have any suggestions as to how to go about doing this? I’ve attached my MATLAB script for viewing. Oh, and I’m using the USB16 servo controller.
Thanks in advance,
John L
% first pair, channel 0 and 1
pair = [0 1];
% set servo movements
move = 5000;
% set movement stepsize
step = 100;
% step counter
i=0;
%movement increment
dif=(move-3000)/step;
while i<step
i=i+1;
x1=round(3000+i*dif);
moveServo(pair(1),x1);
moveServo(pair(2),x1);
end
function moveServo(s,x)
%moveServo(s,x) for Pololu serial servo controllers, using Pololu mode
%(remember to remove the blue mode-selection jumper!) absolute position
%command #4. You may need to edit the port variable in this file to match
%your com port.
%
%s=servo number
%x=absolute position, 500<=x<=5500
port = ‘COM3’;%Edit to your com port number
ser1 = serial(port);
set(ser1, ‘InputBufferSize’, 2048);
set(ser1, ‘BaudRate’, 9600);
set(ser1, ‘DataBits’, 8);
set(ser1, ‘Parity’, ‘none’);
set(ser1, ‘StopBits’, 1);
fopen(ser1);
fwrite(ser1, [128, 1, 4, s, binvec2dec(bitget(x,8:13)), binvec2dec(bitget(x,1:7))]);
fclose(ser1);
delete(ser1);