Author Topic: Problem working with Phidget+Matlab  (Read 602 times)

0 Members and 1 Guest are viewing this topic.

Offline pamecool2Topic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Problem working with Phidget+Matlab
« on: September 08, 2011, 07:04:17 AM »

Hi!

I'm new in the forum, I have the following problem:

I'm working with a Phidget (0/0/3) sensor, I’m obtaining the data (acceleration in x, y, z) trough Mat lab, currently I’m plotting a vector where the position sensor is pointing, also an Cartesian coordinate system  right in the middle of the plot.

My problem is that I want to stick the axis z direction to the movement of the sensor (position vector)

I hope I explain myself; I’m attaching the code and some images.

Thanks in advance  ;)



_____________


close all
t=(0:0.5:50);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Eje de Coordenadas%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TA=[0 1 0 0;
    1 0 0 0;
    0 0 1 0;
    0 0 0 1];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Cosenos Directores%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mod=sqrt(ax^2+ay^2+az^2);

ang1=acos(ax/mod);
ang2=acos(ay/mod);
ang3=acos(az/mod);

for i=1:length(t)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%Aceleración%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

error=calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 0,Acceleration);
ax=(Acceleration.Value);
 
error=calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 1,Acceleration);
ay=(Acceleration.Value);

error=calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 2,Acceleration);
az=(Acceleration.Value);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Vector de Posición%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x=(ax*t)/mod;
y=(ay*t)/mod;
z=(az*t)/mod;

pause(.01) % Rate de toma de muestras

col=hsv(150);
plot3(x,y,z,'color',col(i,:));
axis([-2 2 -2 2 -2 2]);
frame(TA,'w',1.5); %Eje de coordenadas
view(128,26);
grid on
title('Vector dirección Phidghet');
drawnow

end

 


Get Your Ad Here