function setServoPosition(index, position)
%SETSERVOPOSITION  Set the position of a servo motor.
%   setServoPosition(index, position) sets the servo motor at the specified 
%   index to the specified position.
%
%   If the servo motor at index is currently engaged then the controller
%   will attempt to move the servo motor to the commanded position.
%
%   If the servo motor at index is currently not engaged then the motor
%   will not move; however, engaging the motor after setting the position
%   will cause the servo motor to move to the commanded position.

global ADVSERVO;

if index < 0 || index > 7
    error('index must be in the range 0 to 7');
end

code = calllib('phidget21', 'CPhidgetAdvancedServo_setPosition', ADVSERVO, index, position);
if code ~= 0
    disp('setServoPosition error: is the servo engaged?');
end
