pan&tilt with Phidget AdvancedServo

Legacy support with Phidget21

pan&tilt with Phidget AdvancedServo

Postby ogi » Mon Feb 22, 2010 5:47 am

Hi Patrick
For a project at university,I need to interface Phidget with Matlab (Or SIMULINK even better) .
I use the Phidgt1061 - PhidgetAdvancedServo..
and i got it runing with small functions that move a pan&tilt
mechanism (2 servos motors- one for pan and one for tilt)
for camera Dynamic tracking.. so i have one part that calculte the next x,y of the target and i'm sending those x,y to anther function to move the far so good...

1. should i go thru the open library, handle, ...set motor on,ext...
every time the function in called? or can she be on standby just wanting for new x,y?? (like OnInputChange_Handler !?)
when i call the function with new x.y it works once and then don't react anymore!!
* what should i do to make it work on func call or in the backround(if posibble- on input change)
2. can i interface Phidget controller with SIMULINK directly??

thanks a lot for any help!!
my code:
function AdvancedServo_testing(pos_x,pos_y)

if ~libisloaded('phidget21')
loadlibrary('phidget21', 'phidget21Matlab.h');
ptr = libpointer('int32Ptr', 0);
valPtr = libpointer('doublePtr', 0);
val_pos_x = libpointer('doublePtr', 0);
val_pos_y = libpointer('doublePtr', 1);

calllib('phidget21', 'CPhidgetAdvancedServo_create', ptr);
handle = get(ptr, 'Value');

calllib('phidget21', 'CPhidget_open', handle, -1);
if calllib('phidget21', 'CPhidget_waitForAttachment', handle, 2500) == 0
disp('Opened Advanced Servo')
t = timer('TimerFcn','disp(''moving servo...'')', 'StartDelay', 1.0);
calllib('phidget21', 'CPhidgetAdvancedServo_getVelocityMax', handle, 0, valPtr);
maxVelocity = get(valPtr, 'Value');

calllib('phidget21', 'CPhidgetAdvancedServo_getAccelerationMax', handle, 0, valPtr);
maxAccel = get(valPtr, 'Value');

calllib('phidget21', 'CPhidgetAdvancedServo_setAcceleration', handle, 0, maxAccel);
calllib('phidget21', 'CPhidgetAdvancedServo_setVelocityLimit', handle, 0, maxVelocity);

calllib('phidget21', 'CPhidgetAdvancedServo_setEngaged', handle, 0, 1);

% motor 1 - pan
calllib('phidget21', 'CPhidgetAdvancedServo_setPosition', handle, 0, pos_x);
% motor 2 - tilt
calllib('phidget21', 'CPhidgetAdvancedServo_setPosition', handle, 1, pos_y);
% get current pos
calllib('phidget21', 'CPhidgetAdvancedServo_getPosition', handle, 0, val_pos_x);
disp(get(val_pos_x, 'Value'));%% try to get the motor position
calllib('phidget21', 'CPhidgetAdvancedServo_getPosition', handle, 1, val_pos_y);
disp(get(val_pos_y, 'Value'));%% try to get the motor position
disp('Could not open advanced servo')
disp('Finished Servo Cycle')

calllib('phidget21', 'CPhidget_close', handle);
calllib('phidget21', 'CPhidget_delete', handle);


Re: pan&tilt with Phidget AdvancedServo

Postby devon_v » Tue Mar 30, 2010 1:17 pm

I'm not entirely sure what you mean for your first question, but I'll try to answer what I think you mean.

From my understanding so far, if you're calling that function repeatedly, you would need to do the create/open every time, as you are also closing/deleting the servo object at the end of the function call. What would be worth trying is to create/open the servo in the calling function just once, and then when you call this function, pass it the handle to the servo, and then you would get rid of the create/open and the close/delete.

As for doing it directly through simulink, I'm not at all familiar with the workings of simulink, but if you can use/call functions then I see no reason why you wouldn't.

Return to “Matlab”

Who is online

Users browsing this forum: No registered users and 2 guests