function Mov_joystick(hObject, eventdata, handles)
%%%%%%Experimentar colocar y_joy_anterior e Z_jo.. com parametros da funcao
global flag_joy d2 d3 teta1 teta4 teta5 teta6 T06 y_joy_anteriord2 z_joy_anteriord3
global y_joy_anteriorteta1 y_joy_anteriorteta4 y_joy_anteriorteta5 y_joy_anteriorteta6
warning off;
%ai=analoginput('joy',1); % the number is an ID number of installed joystick (see Controller IDs in Control panel/Gaming options
% k=0.2:0.2:1;
% i=5;
%addchannel(ai,[1 2 3 4 5 6]);
%channels
% 1 - X axis
% 2 - Y axis
% 3 - Z axis
% 4 - R axis
% 5 - buttons pressed (quasy binary data - see below)
% 6 - no of buttons pressed at the time
% Set up the display
% d2inicialstr=get(handles.textd2,'String');
% d2inicial=str2num(d2inicialstr);
% d3inicialstr=get(handles.textd3,'String');
% d3inicial=str2num(d3inicialstr);
%k=1; %absoluto
flag_joy=1;
while flag_joy==1
pause(0.05);
samples = jst;
samples(1) = -samples(1)*100; %Y data
samples(2) = samples(2)*100; %X data
samples(3) = -samples(3)*100; %Z data
% decoding the data from dll. You may play with the dll. Please see
% JoyIn.cpp
ButtonsPressed = samples(5);
BP = ButtonsPressed;
if BP==32 %BP==32 =>R1 com y_joy varia d2 altura e z_joy d3
% pause(0.01);
y_joy=samples(1);
y_joy=y_joy+y_joy_anteriord2;
y_joy_anteriord2=y_joy;
d2=((y_joy*180)/200)+90; %90 d2inicial
if(y_joy>100)
d2=180;
end
if(y_joy<-100)
d2=0;
end
z_joy=-samples(3); %%- pq estava invertido
z_joy=z_joy+z_joy_anteriord3;
z_joy_anteriord3=z_joy;
d3=((z_joy*250)/200)+125; %d3 inicial
if(z_joy>100)
d3=250;
end
if(z_joy<-100)
d3=0;
end
d2str=num2str(d2);
d3str=num2str(d3);
set(handles.textd2,'String',d2str);
set(handles.textd3,'String',d3str);
SimuladorCs('Desenha_robo',hObject, eventdata,handles); %tem q estar dentro senao o cpu est a 100%
%% Determinar PX,Py e Pz
Px=T06(1,4);
Py=T06(2,4);
Pz=T06(3,4);
tetaf=teta6+teta4;
tetafdeg=tetaf*180/pi;
tetap=teta5;
tetapdeg=tetap*180/pi;
set(handles.textpx,'String',num2str(Px));
set(handles.textpy,'String',num2str(Py));
set(handles.textpz,'String',num2str(Pz));
set(handles.texttetaf,'String',num2str(tetafdeg));
set(handles.texttetap,'String',num2str(tetapdeg));
end
if BP==4 %%Boto X controla teta1
y_joy=samples(1);
y_joy=y_joy+y_joy_anteriorteta1;
y_joy_anteriorteta1=y_joy;
teta1=y_joy*pi/100;
if(y_joy>100)
teta1=pi;
end
if(y_joy<-100)
teta1=-1*pi;
end
teta1deg=teta1*180/pi;
teta1str=num2str(teta1deg);
set(handles.textteta1,'String',teta1str);
SimuladorCs('Desenha_robo',hObject, eventdata,handles);
%% Determinar PX,Py e Pz
Px=T06(1,4);
Py=T06(2,4);
Pz=T06(3,4);
tetaf=teta6+teta4;
tetafdeg=tetaf*180/pi;
tetap=teta5;
tetapdeg=tetap*180/pi;
set(handles.textpx,'String',num2str(Px));
set(handles.textpy,'String',num2str(Py));
set(handles.textpz,'String',num2str(Pz));
set(handles.texttetaf,'String',num2str(tetafdeg));
set(handles.texttetap,'String',num2str(tetapdeg));
end
if BP==1 %%Boto delta controla teta4
y_joy=samples(1);
y_joy=y_joy+y_joy_anteriorteta4;
y_joy_anteriorteta4=y_joy;
teta4=(y_joy*pi/200)+(pi/2) ;
if(y_joy>100)
teta4=pi;
end
if(y_joy<-100)
teta4=-1*pi;
end
teta4deg=teta4*180/pi;
teta4str=num2str(teta4deg);
set(handles.textteta4,'String',teta4str);
SimuladorCs('Desenha_robo',hObject, eventdata,handles);
%% Determinar PX,Py e Pz
Px=T06(1,4);
Py=T06(2,4);
Pz=T06(3,4);
tetaf=teta6+teta4;
tetafdeg=tetaf*180/pi;
tetap=teta5;
tetapdeg=tetap*180/pi;
set(handles.textpx,'String',num2str(Px));
set(handles.textpy,'String',num2str(Py));
set(handles.textpz,'String',num2str(Pz));
set(handles.texttetaf,'String',num2str(tetafdeg));
set(handles.texttetap,'String',num2str(tetapdeg));
end
if BP==2 %%Boto O cotrola teta5
y_joy=samples(1);
y_joy=y_joy+y_joy_anteriorteta5;
y_joy_anteriorteta5=y_joy;
teta5=y_joy*pi/200;
if(y_joy>100)
teta5=pi/2;
end
if(y_joy<-100)
teta5=-1*pi/2;
end
teta5deg=teta5*180/pi;
teta5str=num2str(teta5deg);
set(handles.textteta5,'String',teta5str);
SimuladorCs('Desenha_robo',hObject, eventdata,handles);
%% Determinar PX,Py e Pz
Px=T06(1,4);
Py=T06(2,4);
Pz=T06(3,4);
tetaf=teta6+teta4;
tetafdeg=tetaf*180/pi;
tetap=teta5;
tetapdeg=tetap*180/pi;
set(handles.textpx,'String',num2str(Px));
set(handles.textpy,'String',num2str(Py));
set(handles.textpz,'String',num2str(Pz));
set(handles.texttetaf,'String',num2str(tetafdeg));
set(handles.texttetap,'String',num2str(tetapdeg));
end
if BP==8 %%Boto rectangulo cotrola teta6
y_joy=samples(1);
y_joy=y_joy+y_joy_anteriorteta6;
y_joy_anteriorteta6=y_joy;
teta6=y_joy*pi/100;
if(y_joy>100)
teta6=pi;
end
if(y_joy<-100)
teta6=-1*pi;
end
teta6deg=teta6*180/pi;
teta6str=num2str(teta6deg);
set(handles.textteta6,'String',teta6str);
SimuladorCs('Desenha_robo',hObject, eventdata,handles);
%% Determinar PX,Py e Pz
Px=T06(1,4);
Py=T06(2,4);
Pz=T06(3,4);
tetaf=teta6+teta4;
tetafdeg=tetaf*180/pi;
tetap=teta5;
tetapdeg=tetap*180/pi;
set(handles.textpx,'String',num2str(Px));
set(handles.textpy,'String',num2str(Py));
set(handles.textpz,'String',num2str(Pz));
set(handles.texttetaf,'String',num2str(tetafdeg));
set(handles.texttetap,'String',num2str(tetapdeg));
end
end