当前位置:   article > 正文

MATLAB机器人简单正逆运动学GUI演示_matlab机器人运动演示

matlab机器人运动演示

1、前言:机器人正逆运动学可以直接查看机器人工具箱的函数ikine和fkine,以及直接用teach()函数演示正逆运动学。

如下:

  1. L_1=20;
  2. L_2=50;
  3. L_3=40;
  4. L(1)=Link([0 L_1 0 pi/2]);
  5. L(2)=Link([0 0 L_2 0]);
  6. L(3)=Link([0 0 L_3 0 ]);
  7. Robot=SerialLink(L);
teach(Robot)

2、当在GUI中主要是数据输入求解的演示:(下面直接贴出代码),主要看

  1. btn_Forward和btn_Inverse %GUI的fig文件可以按照下图自己建立,也可直接下载我的资源:
  2.                            <利用MATLAB和Robot toolbox 做的一个简单的三轴机器人GUI>
btn_Inverse %GUI的fig文件可以按照下图自己建立,也可直接下载我的资源:                            <利用MATLAB和Robot toolbox 做的一个简单的三轴机器人GUI>
  1. function varargout = SimpleRobotGui(varargin)
  2. % SIMPLEROBOTGUI MATLAB code for SimpleRobotGui.fig
  3. % SIMPLEROBOTGUI, by itself, creates a new SIMPLEROBOTGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = SIMPLEROBOTGUI returns the handle to a new SIMPLEROBOTGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % SIMPLEROBOTGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in SIMPLEROBOTGUI.M with the given input arguments.
  11. %
  12. % SIMPLEROBOTGUI('Property','Value',...) creates a new SIMPLEROBOTGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before SimpleRobotGui_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to SimpleRobotGui_OpeningFcn via varargin.
  17. %
  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  19. % instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help SimpleRobotGui
  23. % Last Modified by GUIDE v2.5 19-Jun-2018 16:36:17
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @SimpleRobotGui_OpeningFcn, ...
  29. 'gui_OutputFcn', @SimpleRobotGui_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before SimpleRobotGui is made visible.
  42. function SimpleRobotGui_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to SimpleRobotGui (see VARARGIN)
  48. % Choose default command line output for SimpleRobotGui
  49. handles.output = hObject;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % UIWAIT makes SimpleRobotGui wait for user response (see UIRESUME)
  53. % uiwait(handles.figure1);
  54. % --- Outputs from this function are returned to the command line.
  55. function varargout = SimpleRobotGui_OutputFcn(hObject, eventdata, handles)
  56. % varargout cell array for returning output args (see VARARGOUT);
  57. % hObject handle to figure
  58. % eventdata reserved - to be defined in a future version of MATLAB
  59. % handles structure with handles and user data (see GUIDATA)
  60. % Get default command line output from handles structure
  61. varargout{1} = handles.output;
  62. function Theta_1_Callback(hObject, eventdata, handles)
  63. % hObject handle to Theta_1 (see GCBO)
  64. % eventdata reserved - to be defined in a future version of MATLAB
  65. % handles structure with handles and user data (see GUIDATA)
  66. % Hints: get(hObject,'String') returns contents of Theta_1 as text
  67. % str2double(get(hObject,'String')) returns contents of Theta_1 as a double
  68. % --- Executes during object creation, after setting all properties.
  69. function Theta_1_CreateFcn(hObject, eventdata, handles)
  70. % hObject handle to Theta_1 (see GCBO)
  71. % eventdata reserved - to be defined in a future version of MATLAB
  72. % handles empty - handles not created until after all CreateFcns called
  73. % Hint: edit controls usually have a white background on Windows.
  74. % See ISPC and COMPUTER.
  75. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  76. set(hObject,'BackgroundColor','white');
  77. end
  78. function Theta_2_Callback(hObject, eventdata, handles)
  79. % hObject handle to Theta_2 (see GCBO)
  80. % eventdata reserved - to be defined in a future version of MATLAB
  81. % handles structure with handles and user data (see GUIDATA)
  82. % Hints: get(hObject,'String') returns contents of Theta_2 as text
  83. % str2double(get(hObject,'String')) returns contents of Theta_2 as a double
  84. % --- Executes during object creation, after setting all properties.
  85. function Theta_2_CreateFcn(hObject, eventdata, handles)
  86. % hObject handle to Theta_2 (see GCBO)
  87. % eventdata reserved - to be defined in a future version of MATLAB
  88. % handles empty - handles not created until after all CreateFcns called
  89. % Hint: edit controls usually have a white background on Windows.
  90. % See ISPC and COMPUTER.
  91. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  92. set(hObject,'BackgroundColor','white');
  93. end
  94. function Theta_3_Callback(hObject, eventdata, handles)
  95. % hObject handle to Theta_3 (see GCBO)
  96. % eventdata reserved - to be defined in a future version of MATLAB
  97. % handles structure with handles and user data (see GUIDATA)
  98. % Hints: get(hObject,'String') returns contents of Theta_3 as text
  99. % str2double(get(hObject,'String')) returns contents of Theta_3 as a double
  100. % --- Executes during object creation, after setting all properties.
  101. function Theta_3_CreateFcn(hObject, eventdata, handles)
  102. % hObject handle to Theta_3 (see GCBO)
  103. % eventdata reserved - to be defined in a future version of MATLAB
  104. % handles empty - handles not created until after all CreateFcns called
  105. % Hint: edit controls usually have a white background on Windows.
  106. % See ISPC and COMPUTER.
  107. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  108. set(hObject,'BackgroundColor','white');
  109. end
  110. function Pos_X_Callback(hObject, eventdata, handles)
  111. % hObject handle to Pos_X (see GCBO)
  112. % eventdata reserved - to be defined in a future version of MATLAB
  113. % handles structure with handles and user data (see GUIDATA)
  114. % Hints: get(hObject,'String') returns contents of Pos_X as text
  115. % str2double(get(hObject,'String')) returns contents of Pos_X as a double
  116. % --- Executes during object creation, after setting all properties.
  117. function Pos_X_CreateFcn(hObject, eventdata, handles)
  118. % hObject handle to Pos_X (see GCBO)
  119. % eventdata reserved - to be defined in a future version of MATLAB
  120. % handles empty - handles not created until after all CreateFcns called
  121. % Hint: edit controls usually have a white background on Windows.
  122. % See ISPC and COMPUTER.
  123. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  124. set(hObject,'BackgroundColor','white');
  125. end
  126. function Pos_Y_Callback(hObject, eventdata, handles)
  127. % hObject handle to Pos_Y (see GCBO)
  128. % eventdata reserved - to be defined in a future version of MATLAB
  129. % handles structure with handles and user data (see GUIDATA)
  130. % Hints: get(hObject,'String') returns contents of Pos_Y as text
  131. % str2double(get(hObject,'String')) returns contents of Pos_Y as a double
  132. % --- Executes during object creation, after setting all properties.
  133. function Pos_Y_CreateFcn(hObject, eventdata, handles)
  134. % hObject handle to Pos_Y (see GCBO)
  135. % eventdata reserved - to be defined in a future version of MATLAB
  136. % handles empty - handles not created until after all CreateFcns called
  137. % Hint: edit controls usually have a white background on Windows.
  138. % See ISPC and COMPUTER.
  139. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  140. set(hObject,'BackgroundColor','white');
  141. end
  142. function Pos_Z_Callback(hObject, eventdata, handles)
  143. % hObject handle to Pos_Z (see GCBO)
  144. % eventdata reserved - to be defined in a future version of MATLAB
  145. % handles structure with handles and user data (see GUIDATA)
  146. % Hints: get(hObject,'String') returns contents of Pos_Z as text
  147. % str2double(get(hObject,'String')) returns contents of Pos_Z as a double
  148. % --- Executes during object creation, after setting all properties.
  149. function Pos_Z_CreateFcn(hObject, eventdata, handles)
  150. % hObject handle to Pos_Z (see GCBO)
  151. % eventdata reserved - to be defined in a future version of MATLAB
  152. % handles empty - handles not created until after all CreateFcns called
  153. % Hint: edit controls usually have a white background on Windows.
  154. % See ISPC and COMPUTER.
  155. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  156. set(hObject,'BackgroundColor','white');
  157. end
  158. % --- Executes on button press in btn_Forward.
  159. function btn_Forward_Callback(hObject, eventdata, handles)
  160. % hObject handle to btn_Forward (see GCBO)
  161. % eventdata reserved - to be defined in a future version of MATLAB
  162. % handles structure with handles and user data (see GUIDATA)
  163. Th_1=str2double(handles.Theta_1.String)*pi/180;
  164. Th_2=str2double(handles.Theta_2.String)*pi/180;
  165. Th_3=str2double(handles.Theta_3.String)*pi/180;
  166. L_1=20;
  167. L_2=50;
  168. L_3=40;
  169. L(1)=Link([0 L_1 0 pi/2]);
  170. L(2)=Link([0 0 L_2 0]);
  171. L(3)=Link([0 0 L_3 0 ]);
  172. Robot=SerialLink(L);
  173. Robot.name='RRR_Robot';
  174. Robot.plot([Th_1 Th_2 Th_3]);
  175. T=Robot.fkine([Th_1 Th_2 Th_3]);
  176. handles.Pos_X.String=num2str(floor(T(1,4)));
  177. handles.Pos_Y.String=num2str(floor(T(2,4)));
  178. handles.Pos_Z.String=num2str(floor(T(3,4)));
  179. % --- Executes on button press in btn_Inverse.
  180. function btn_Inverse_Callback(hObject, eventdata, handles)
  181. % hObject handle to btn_Inverse (see GCBO)
  182. % eventdata reserved - to be defined in a future version of MATLAB
  183. % handles structure with handles and user data (see GUIDATA)
  184. PX=str2double(handles.Pos_X.String);
  185. PY=str2double(handles.Pos_Y.String);
  186. PZ=str2double(handles.Pos_Z.String);
  187. L_1=20;
  188. L_2=50;
  189. L_3=40;
  190. L(1)=Link([0 L_1 0 pi/2]);
  191. L(2)=Link([0 0 L_2 0]);
  192. L(3)=Link([0 0 L_3 0 ]);
  193. Robot=SerialLink(L);
  194. Robot.name='RRR_Robot';
  195. T=[1 0 0 PX;
  196. 0 1 0 PY;
  197. 0 0 1 PZ;
  198. 0 0 0 1;]
  199. J=Robot.ikine(T,'mask',[1 1 1 0 0 0])*180/pi;%J=Robot.ikine(T,[0 0 0],[1 1 1 0 0 0])*180/pi;原来的逆解出错,改下格式对少于6自由度的机器人求逆解
  200. handles.Theta_1.String=num2str(floor(J(1)));
  201. handles.Theta_2.String=num2str(floor(J(2)));
  202. handles.Theta_3.String=num2str(floor(J(3)));
  203. Robot.plot(J*pi/180);

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/1008083
推荐阅读
相关标签
  

闽ICP备14008679号