📄 joy_inverso.asv
字号:
function Joy_Inverso(hObject, eventdata, handles)
global flag_joy Px Py Pz
global teta1 teta4 teta5 teta6 tetap tetaf d2 d3 l1 d4 x_joyantesPx
warning off;
ai=analoginput('joy',1); % the number is an ID number of installed joystick (see Controller IDs in Control panel/Gaming options
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
flag_joy=1;
while flag_joy==1
pause(0.01);
samples = getsample(ai);
samples(2) = -samples(2); samples(3) = -samples(3);
% decoding the data from dll. You may play with the dll. Please see
% JoyIn.cpp
ButtonsPressed = round((10+samples(5))*32768/10);
BP = ButtonsPressed;
NoOfButtonsPressed = round((10+samples(6))*32768/10);
nBP = NoOfButtonsPressed;
if BP==32 %BP==32 =>R1 controlar eixos dos XX
% pause(0.01);
x_joy=samples(1)*10; %%varia entre -100 e 100
x_joy=y_joy+x_joyantesPx;
x_joyantesPx=x_joy;
Pxmax=sqrt((282^2)-(Py^2));
Pxmin=sqrt((112.75^2)-(Py^2));
if(x_joy>=0)
Px=((x_joy*(Pxmax-Pxmin)/100)+Pxmin);
else
Px=((x_joy*(Pxmax-Pxmin)/100)-Pxmin);
end
if(x_joy>100)
Px=Pxmax;
end
if(x_joy>-100)
Px=Pxmin
teta1=atan2(Py,Px)+atan2(sqrt(Px^2+Py^2-l1^2),l1);
d2=Pz;
d3=sin(teta1)*Px-cos(teta1)*Py-d4;
teta4=atan2(1,0);
teta5=(tetap*pi)/180;
tetaf=(tetaf*pi)/180;
teta6=tetaf-teta4;
Pxstr=num2str(Px);
Pystr=num2str(Py);
Pzstr=num2str(Pz);
set(handles.textpz,'String',Pzstr);
set(handles.textpx,'String',Pxstr);
set(handles.textpy,'String',Pystr);
SimuladorCs('Desenha_robo',hObject, eventdata,handles); %tem q estar dentro senao o cpu est
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -