%Set target position
%
%This sets the target position for all motors on the bus.
%
%Use command 0..0x7F to address multiple motors.

function setPosAll(H,pos)

globalVar;
servoReturn1 = 0;
servoReturn2 = 0;

if((pos<ANGLE_MIN) || (pos>ANGLE_MAX))
    error('Gama de posições válidas: [-90;90]º');
end

pos=((pos+ANGLE_MAX)*(VAL_ANGLE_MAX-VAL_ANGLE_MIN)/(ANGLE_MAX-ANGLE_MIN))+VAL_ANGLE_MIN;

command = SET_POS_ALL;
param1 = bitand(pos,MASK_HIGH)/256;
param2 = bitand(pos,MASK_LOW);
checksum = 256 - mod((STARTBYTE+command+param1+param2),256);

sendMessage(H,command,param1,param2,checksum);
%[return1,return2]=readMessage(H)
return1=0;
return2=0;
if((servoReturn1 ~= return1) || (servoReturn2 ~= return2))
    err = ERR_SET_POS_ALL;
    errfcn(H,err);
end