0001 function varargout = teach(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 global configuration robot
0045 global controls program
0046
0047
0048 if ~isfield(robot,'q')
0049 warndlg('No robot variable found, please load a robot with: robot=load_robot','!! Warning !!')
0050 return;
0051 end
0052
0053
0054 gui_Singleton = 1;
0055 gui_State = struct('gui_Name', mfilename, ...
0056 'gui_Singleton', gui_Singleton, ...
0057 'gui_OpeningFcn', @teach_OpeningFcn, ...
0058 'gui_OutputFcn', @teach_OutputFcn, ...
0059 'gui_LayoutFcn', [] , ...
0060 'gui_Callback', []);
0061 if nargin && ischar(varargin{1})
0062 gui_State.gui_Callback = str2func(varargin{1});
0063 end
0064
0065 if nargout
0066 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0067 else
0068 gui_mainfcn(gui_State, varargin{:});
0069 end
0070
0071
0072
0073
0074
0075 function teach_OpeningFcn(hObject, eventdata, handles, varargin)
0076
0077
0078
0079
0080
0081
0082
0083 handles.output = hObject;
0084
0085
0086 guidata(hObject, handles);
0087
0088
0089
0090
0091
0092 global robot configuration controls targets program
0093
0094
0095 program=[];
0096 program.program_counter=0;
0097 program.n_lines=0;
0098
0099 program.rapid_lines=[];
0100 program.matlab_lines=[];
0101
0102
0103 targets=[];
0104
0105 controls.num_target_points=0;
0106 controls.global_gui_handle=hObject;
0107
0108
0109 robot.q=zeros(1,robot.DOF)';
0110
0111
0112 robot.q_vector=[];
0113 robot.qd_vector=[];
0114 robot.qdd_vector=[];
0115 robot.time=[];
0116
0117
0118
0119 update_T_Q()
0120 update_sliders();
0121
0122 figure(configuration.figure.robot);
0123
0124 disp('Select the desired view for your robot')
0125 drawrobot3d(robot, robot.q);
0126
0127
0128 function varargout = teach_OutputFcn(hObject, eventdata, handles)
0129
0130
0131
0132
0133
0134
0135 varargout{1} = handles.output;
0136
0137
0138
0139 function popupmenu_instruction_Callback(hObject, eventdata, handles)
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 function popupmenu_instruction_CreateFcn(hObject, eventdata, handles)
0150
0151
0152
0153 global controls
0154
0155 controls.popupmenu_instruction=hObject;
0156
0157
0158
0159
0160 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0161 set(hObject,'BackgroundColor','white');
0162 end
0163
0164
0165
0166 function listbox1_Callback(hObject, eventdata, handles)
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 function listbox1_CreateFcn(hObject, eventdata, handles)
0177
0178
0179
0180
0181
0182
0183 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0184 set(hObject,'BackgroundColor','white');
0185 end
0186
0187
0188
0189 function popupmenu_target_point_Callback(hObject, eventdata, handles)
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 function popupmenu_target_point_CreateFcn(hObject, eventdata, handles)
0200
0201
0202
0203
0204 global controls
0205 controls.popupmenu_target_point=hObject;
0206
0207
0208
0209
0210 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0211 set(hObject,'BackgroundColor','white');
0212 end
0213
0214
0215
0216 function popupmenu_through_point_Callback(hObject, eventdata, handles)
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 function popupmenu_through_point_CreateFcn(hObject, eventdata, handles)
0227
0228
0229
0230 global controls
0231 controls.popupmenu_through_point=hObject;
0232
0233
0234
0235 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0236 set(hObject,'BackgroundColor','white');
0237 end
0238
0239
0240
0241 function popupmenu_speed_Callback(hObject, eventdata, handles)
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 function popupmenu_speed_CreateFcn(hObject, eventdata, handles)
0252
0253
0254
0255
0256 global controls
0257 controls.popupmenu_speed=hObject;
0258
0259
0260
0261 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0262 set(hObject,'BackgroundColor','white');
0263 end
0264
0265
0266
0267 function pushbutton1_Callback(hObject, eventdata, handles)
0268
0269
0270
0271
0272
0273
0274 function popupmenu_precision_Callback(hObject, eventdata, handles)
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 function popupmenu_precision_CreateFcn(hObject, eventdata, handles)
0285
0286
0287
0288 global controls
0289 controls.popupmenu_precision=hObject;
0290
0291
0292 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0293 set(hObject,'BackgroundColor','white');
0294 end
0295
0296
0297
0298 function slider_q1_Callback(hObject, eventdata, handles)
0299
0300
0301
0302
0303
0304
0305
0306 global configuration robot controls
0307 slider_value = get(hObject,'Value');
0308 set(controls.edit_q1, 'String', num2str(slider_value));
0309
0310 if robot.kind(1)=='R'
0311 robot.q(1) = slider_value*pi/180;
0312 else
0313 robot.q(1) = slider_value;
0314 end
0315
0316 update_T_Q();
0317 figure(configuration.figure.robot);
0318 drawrobot3d(robot, robot.q);
0319 draw_target_points();
0320
0321
0322 function slider_q1_CreateFcn(hObject, eventdata, handles)
0323
0324
0325
0326 global robot controls
0327 controls.slider_q1=hObject;
0328
0329
0330 if robot.DOF>0
0331
0332 set(hObject, 'Min',robot.maxangle(1,1)*180/pi,'Max',robot.maxangle(1,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0333 else
0334 disp('\nPlease set robot.DOF correspondingly')
0335 end
0336
0337
0338 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0339 set(hObject,'BackgroundColor',[.9 .9 .9]);
0340 end
0341
0342
0343
0344
0345
0346 function slider_q2_Callback(hObject, eventdata, handles)
0347
0348
0349
0350
0351
0352
0353 global configuration robot controls
0354 slider_value = get(hObject,'Value');
0355 set(controls.edit_q2, 'String', num2str(slider_value));
0356
0357
0358 if robot.kind(2)=='R'
0359 robot.q(2) = slider_value*pi/180;
0360 else
0361 robot.q(2) = slider_value;
0362 end
0363
0364 update_T_Q();
0365 figure(configuration.figure.robot);
0366 drawrobot3d(robot, robot.q);
0367 draw_target_points();
0368
0369
0370
0371 function slider_q2_CreateFcn(hObject, eventdata, handles)
0372
0373
0374
0375
0376 global robot controls
0377 controls.slider_q2=hObject;
0378
0379
0380 if robot.DOF>1
0381
0382 set(hObject, 'Min',robot.maxangle(2,1)*180/pi,'Max',robot.maxangle(2,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0383 else
0384
0385 set(hObject, 'Min',0,'Max',0, 'Value',0);
0386 disp('\nPlease set robot.DOF correspondingly')
0387 end
0388
0389
0390 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0391 set(hObject,'BackgroundColor',[.9 .9 .9]);
0392 end
0393
0394
0395
0396 function slider_q3_Callback(hObject, eventdata, handles)
0397
0398
0399
0400
0401
0402
0403
0404 global configuration robot controls
0405 slider_value = get(hObject,'Value');
0406 set(controls.edit_q3, 'String', num2str(slider_value));
0407
0408 if robot.kind(3)=='R'
0409 robot.q(3) = slider_value*pi/180;
0410 else
0411 robot.q(3) = slider_value;
0412 end
0413 figure(configuration.figure.robot);
0414 update_T_Q();
0415 drawrobot3d(robot, robot.q);
0416 draw_target_points();
0417
0418
0419 function slider_q3_CreateFcn(hObject, eventdata, handles)
0420
0421
0422
0423
0424
0425 global robot controls
0426 controls.slider_q3=hObject;
0427
0428 if robot.DOF>2
0429
0430 set(hObject, 'Min',robot.maxangle(3,1)*180/pi,'Max',robot.maxangle(3,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0431 else
0432
0433 set(hObject, 'Min',0,'Max',0, 'Value',0);
0434 disp('\nPlease set robot.DOF correspondingly')
0435 end
0436
0437
0438 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0439 set(hObject,'BackgroundColor',[.9 .9 .9]);
0440 end
0441
0442
0443
0444 function slider_q4_Callback(hObject, eventdata, handles)
0445
0446
0447
0448
0449
0450
0451
0452 global configuration robot controls
0453 slider_value = get(hObject,'Value');
0454 set(controls.edit_q4, 'String', num2str(slider_value));
0455
0456 if robot.kind(4)=='R'
0457 robot.q(4) = slider_value*pi/180;
0458 else
0459 robot.q(4) = slider_value;
0460 end
0461
0462 update_T_Q();
0463 figure(configuration.figure.robot);
0464 drawrobot3d(robot, robot.q);
0465 draw_target_points();
0466
0467
0468 function slider_q4_CreateFcn(hObject, eventdata, handles)
0469
0470
0471
0472
0473
0474 global robot controls
0475 controls.slider_q4=hObject;
0476
0477 if robot.DOF>3
0478
0479 set(hObject, 'Min',robot.maxangle(4,1)*180/pi,'Max',robot.maxangle(4,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0480 else
0481
0482 set(hObject, 'Min',0,'Max',0, 'Value',0);
0483 disp('\nPlease set robot.DOF correspondingly')
0484 end
0485
0486
0487
0488 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0489 set(hObject,'BackgroundColor',[.9 .9 .9]);
0490 end
0491
0492
0493
0494 function slider_q5_Callback(hObject, eventdata, handles)
0495
0496
0497
0498
0499
0500
0501
0502 global configuration robot controls
0503 slider_value = get(hObject,'Value');
0504 set(controls.edit_q5, 'String', num2str(slider_value));
0505
0506 if robot.kind(5)=='R'
0507 robot.q(5) = slider_value*pi/180;
0508 else
0509 robot.q(5) = slider_value;
0510 end
0511 update_T_Q();
0512 figure(configuration.figure.robot);
0513 drawrobot3d(robot, robot.q);
0514 draw_target_points();
0515
0516
0517 function slider_q5_CreateFcn(hObject, eventdata, handles)
0518
0519
0520
0521
0522
0523 global robot controls
0524 controls.slider_q5=hObject;
0525 if robot.DOF>4
0526
0527 set(hObject, 'Min',robot.maxangle(5,1)*180/pi,'Max',robot.maxangle(5,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0528 else
0529
0530 set(hObject, 'Min',0,'Max',0, 'Value',0);
0531 disp('\nPlease set robot.DOF correspondingly')
0532 end
0533
0534
0535
0536 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0537 set(hObject,'BackgroundColor',[.9 .9 .9]);
0538 end
0539
0540
0541
0542 function slider_q6_Callback(hObject, eventdata, handles)
0543
0544
0545
0546
0547
0548
0549
0550 global configuration robot controls
0551 slider_value = get(hObject,'Value');
0552 set(controls.edit_q6, 'String', num2str(slider_value));
0553
0554 if robot.kind(6)=='R'
0555 robot.q(6) = slider_value*pi/180;
0556 else
0557 robot.q(6) = slider_value;
0558 end
0559 update_T_Q();
0560 figure(configuration.figure.robot);
0561 drawrobot3d(robot, robot.q);
0562 draw_target_points();
0563
0564
0565
0566 function slider_q6_CreateFcn(hObject, eventdata, handles)
0567
0568
0569
0570
0571
0572 global robot controls
0573
0574 controls.slider_q6=hObject;
0575
0576 if robot.DOF>5
0577
0578 set(hObject, 'Min',robot.maxangle(6,1)*180/pi,'Max',robot.maxangle(6,2)*180/pi, 'Value',0,'SliderStep',[0.005 0.2]);
0579 else
0580
0581 set(hObject, 'Min',0,'Max',0, 'Value',0);
0582 disp('\nPlease set robot.DOF correspondingly')
0583 end
0584
0585
0586
0587 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0588 set(hObject,'BackgroundColor',[.9 .9 .9]);
0589 end
0590
0591
0592
0593
0594
0595 function pushbutton_x_minus_Callback(hObject, eventdata, handles)
0596
0597
0598
0599
0600 global robot controls
0601
0602
0603
0604 resolution=get(controls.popupmenu_resolution,'Value');
0605 if resolution==3
0606 delta=0.05;
0607 end
0608 if resolution==2
0609 delta=0.1;
0610 end
0611 if resolution==1
0612 delta=0.2;
0613 end
0614
0615
0616
0617 T = directkinematic(robot, robot.q);
0618 P_ini=T(1:3,4);
0619
0620 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0621
0622
0623 if line_reorient==1
0624 base=get(controls.popupmenu_base_end,'Value');
0625
0626 if base==1
0627 P_final = P_ini;
0628 P_final(1) = P_ini(1) - delta;
0629 else
0630 P_final = P_ini - delta*T(1:3,1);
0631 end
0632
0633 follow_line(P_ini,P_final);
0634
0635 else
0636
0637
0638 Trot = [1 0 0 0;
0639 0 cos(-delta) -sin(-delta) 0;
0640 0 sin(-delta) cos(-delta) 0;
0641 0 0 0 1];
0642
0643 base=get(controls.popupmenu_base_end,'Value');
0644
0645 if base==1
0646 T_final = Trot*T;
0647 else
0648 T_final = T*Trot;
0649 end
0650
0651 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
0652 conf=compute_configuration(robot, robot.q);
0653
0654
0655
0656 Q = T2quaternion(T_final);
0657 Q=real(Q);
0658 tp=[[P_ini'],[Q],conf,ejes_ext];
0659
0660 command =[' MoveJ(tp,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
0661 eval(command);
0662 end
0663
0664 update_T_Q();
0665 update_sliders();
0666 draw_target_points();
0667
0668
0669
0670 function pushbutton_x_plus_Callback(hObject, eventdata, handles)
0671
0672
0673
0674
0675 global robot controls
0676
0677
0678 resolution=get(controls.popupmenu_resolution,'Value');
0679 if resolution==3
0680 delta=0.05;
0681 end
0682 if resolution==2
0683 delta=0.1;
0684 end
0685 if resolution==1
0686 delta=0.2;
0687 end
0688
0689
0690 T = directkinematic(robot, robot.q);
0691 P_ini=T(1:3,4);
0692
0693 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0694
0695
0696 if line_reorient==1
0697 base=get(controls.popupmenu_base_end,'Value');
0698
0699 if base==1
0700 P_final = P_ini;
0701 P_final(1) = P_ini(1) + delta;
0702 else
0703 P_final = P_ini + delta*T(1:3,1);
0704 end
0705
0706 follow_line(P_ini,P_final);
0707
0708 else
0709
0710
0711 Trot = [1 0 0 0;
0712 0 cos(delta) -sin(delta) 0;
0713 0 sin(delta) cos(delta) 0;
0714 0 0 0 1];
0715
0716 base=get(controls.popupmenu_base_end,'Value');
0717
0718 if base==1
0719 T_final = Trot*T;
0720 else
0721 T_final = T*Trot;
0722 end
0723
0724 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
0725 conf=compute_configuration(robot, robot.q);
0726
0727
0728
0729 Q = T2quaternion(T_final);
0730 Q=real(Q);
0731 tp=[[P_ini'],[Q],conf,ejes_ext];
0732
0733 command =[' MoveJ(tp,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
0734 eval(command);
0735 end
0736
0737 update_T_Q();
0738 update_sliders();
0739 draw_target_points();
0740
0741
0742
0743 function pushbutton_y_plus_Callback(hObject, eventdata, handles)
0744
0745
0746
0747
0748
0749 global robot controls
0750
0751
0752 resolution=get(controls.popupmenu_resolution,'Value');
0753 if resolution==3
0754 delta=0.05;
0755 end
0756 if resolution==2
0757 delta=0.1;
0758 end
0759 if resolution==1
0760 delta=0.2;
0761 end
0762
0763
0764 T = directkinematic(robot, robot.q);
0765 P_ini=T(1:3,4);
0766
0767 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0768
0769
0770 if line_reorient==1
0771 base=get(controls.popupmenu_base_end,'Value');
0772
0773 if base==1
0774 P_final = P_ini;
0775 P_final(2) = P_ini(2) + delta;
0776 else
0777 P_final = P_ini + delta*T(1:3,2);
0778 end
0779
0780 follow_line(P_ini,P_final);
0781
0782 else
0783
0784
0785 Trot = [cos(delta) 0 sin(delta) 0;
0786 0 1 0 0;
0787 -sin(delta) 0 cos(delta) 0;
0788 0 0 0 1];
0789
0790 base=get(controls.popupmenu_base_end,'Value');
0791
0792 if base==1
0793 T_final = Trot*T;
0794 else
0795 T_final = T*Trot;
0796 end
0797
0798 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
0799 conf=compute_configuration(robot, robot.q);
0800
0801
0802
0803 Q = T2quaternion(T_final);
0804 Q=real(Q);
0805 tp=[[P_ini'],[Q],conf,ejes_ext];
0806
0807 command =['MoveJ(tp,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
0808 eval(command);
0809 end
0810
0811 update_T_Q();
0812 update_sliders();
0813 draw_target_points();
0814
0815
0816 function pushbutton_y_minus_Callback(hObject, eventdata, handles)
0817
0818
0819
0820 global robot controls
0821
0822
0823 resolution=get(controls.popupmenu_resolution,'Value');
0824 if resolution==3
0825 delta=0.05;
0826 end
0827 if resolution==2
0828 delta=0.1;
0829 end
0830 if resolution==1
0831 delta=0.2;
0832 end
0833
0834
0835 T = directkinematic(robot, robot.q);
0836 P_ini=T(1:3,4);
0837
0838 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0839
0840
0841 if line_reorient==1
0842 base=get(controls.popupmenu_base_end,'Value');
0843
0844 if base==1
0845 P_final = P_ini;
0846 P_final(2) = P_ini(2) - delta;
0847 else
0848 P_final = P_ini - delta*T(1:3,2);
0849 end
0850
0851 follow_line(P_ini,P_final);
0852
0853 else
0854
0855
0856 Trot = [cos(-delta) 0 sin(-delta) 0;
0857 0 1 0 0;
0858 -sin(-delta) 0 cos(-delta) 0;
0859 0 0 0 1];
0860
0861 base=get(controls.popupmenu_base_end,'Value');
0862
0863 if base==1
0864 T_final = Trot*T;
0865 else
0866 T_final = T*Trot;
0867 end
0868
0869 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
0870 conf=compute_configuration(robot, robot.q);
0871
0872
0873
0874 Q = T2quaternion(T_final);
0875 Q=real(Q);
0876 tp=[[P_ini'],[Q],conf,ejes_ext];
0877
0878 command =['MoveJ(tp,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
0879 eval(command);
0880 end
0881
0882 update_T_Q();
0883 update_sliders();
0884 draw_target_points();
0885
0886
0887 function pushbutton_z_plus_Callback(hObject, eventdata, handles)
0888
0889
0890
0891
0892 global robot controls
0893
0894
0895
0896 resolution=get(controls.popupmenu_resolution,'Value');
0897 if resolution==3
0898 delta=0.05;
0899 end
0900 if resolution==2
0901 delta=0.1;
0902 end
0903 if resolution==1
0904 delta=0.2;
0905 end
0906
0907
0908 T = directkinematic(robot, robot.q);
0909 P_ini=T(1:3,4);
0910
0911 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0912
0913
0914 if line_reorient==1
0915 base=get(controls.popupmenu_base_end,'Value');
0916
0917 if base==1
0918 P_final = P_ini;
0919 P_final(3) = P_ini(3) + delta;
0920 else
0921 P_final = P_ini + delta*T(1:3,3);
0922 end
0923
0924 follow_line(P_ini,P_final);
0925
0926 else
0927
0928
0929 Trot = [cos(delta) -sin(delta) 0 0;
0930 sin(delta) cos(delta) 0 0;
0931 0 0 1 0;
0932 0 0 0 1];
0933
0934 base=get(controls.popupmenu_base_end,'Value');
0935
0936 if base==1
0937 T_final = Trot*T;
0938 else
0939 T_final = T*Trot;
0940 end
0941
0942 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
0943 conf=compute_configuration(robot, robot.q);
0944
0945
0946
0947 Q = T2quaternion(T_final);
0948 Q=real(Q);
0949
0950 tp=[[P_ini'],[Q],conf,ejes_ext];
0951 MoveJ(tp, 'vmax', 'fine', robot.tool0, robot.wobj0);
0952
0953
0954 end
0955
0956 update_T_Q();
0957 update_sliders();
0958 draw_target_points();
0959
0960
0961 function pushbutton_z_minus_Callback(hObject, eventdata, handles)
0962
0963
0964
0965 global robot controls
0966
0967
0968 resolution=get(controls.popupmenu_resolution,'Value');
0969 if resolution==3
0970 delta=0.05;
0971 end
0972 if resolution==2
0973 delta=0.1;
0974 end
0975 if resolution==1
0976 delta=0.2;
0977 end
0978
0979
0980 T = directkinematic(robot, robot.q);
0981 P_ini=T(1:3,4);
0982
0983 line_reorient=get(controls.popupmenu_line_reorient,'Value');
0984
0985
0986 if line_reorient==1
0987 base=get(controls.popupmenu_base_end,'Value');
0988
0989 if base==1
0990 P_final = P_ini;
0991 P_final(3) = P_ini(3) - delta;
0992 else
0993 P_final = P_ini - delta*T(1:3,3);
0994 end
0995
0996 follow_line(P_ini,P_final);
0997
0998 else
0999
1000
1001 Trot = [cos(-delta) -sin(-delta) 0 0;
1002 sin(-delta) cos(-delta) 0 0;
1003 0 0 1 0;
1004 0 0 0 1];
1005
1006 base=get(controls.popupmenu_base_end,'Value');
1007
1008 if base==1
1009 T_final = Trot*T;
1010 else
1011 T_final = T*Trot;
1012 end
1013
1014 ejes_ext = [9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];
1015 conf=compute_configuration(robot, robot.q);
1016
1017
1018
1019 Q = T2quaternion(T_final);
1020 Q=real(Q);
1021 tp=[[P_ini'],[Q],conf,ejes_ext];
1022
1023 command =[' MoveJ(tp,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
1024 eval(command);
1025 end
1026
1027 update_T_Q();
1028 update_sliders();
1029 draw_target_points();
1030
1031
1032 function edit_q1_Callback(hObject, eventdata, handles)
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 function edit_q1_CreateFcn(hObject, eventdata, handles)
1043
1044
1045
1046
1047 global controls
1048
1049
1050 controls.edit_q1=hObject;
1051
1052
1053
1054 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1055 set(hObject,'BackgroundColor','white');
1056
1057 end
1058
1059
1060
1061 function edit_q2_Callback(hObject, eventdata, handles)
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 function edit_q2_CreateFcn(hObject, eventdata, handles)
1072
1073
1074
1075
1076 global controls
1077
1078
1079 controls.edit_q2=hObject;
1080
1081
1082
1083 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1084 set(hObject,'BackgroundColor','white');
1085 end
1086
1087
1088
1089 function edit_q3_Callback(hObject, eventdata, handles)
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100 function edit_q3_CreateFcn(hObject, eventdata, handles)
1101
1102
1103
1104
1105 global controls
1106
1107
1108 controls.edit_q3=hObject;
1109
1110
1111
1112 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1113 set(hObject,'BackgroundColor','white');
1114 end
1115
1116
1117
1118 function edit_q4_Callback(hObject, eventdata, handles)
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128 function edit_q4_CreateFcn(hObject, eventdata, handles)
1129
1130
1131
1132
1133
1134 global controls
1135
1136
1137 controls.edit_q4=hObject;
1138
1139
1140
1141 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1142 set(hObject,'BackgroundColor','white');
1143 end
1144
1145
1146
1147 function edit_q5_Callback(hObject, eventdata, handles)
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157 function edit_q5_CreateFcn(hObject, eventdata, handles)
1158
1159
1160
1161
1162
1163 global controls
1164
1165
1166 controls.edit_q5=hObject;
1167
1168
1169
1170 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1171 set(hObject,'BackgroundColor','white');
1172 end
1173
1174
1175
1176 function edit_q6_Callback(hObject, eventdata, handles)
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 function edit_q6_CreateFcn(hObject, eventdata, handles)
1187
1188
1189
1190
1191
1192 global controls
1193
1194
1195 controls.edit_q6=hObject;
1196
1197
1198
1199 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1200 set(hObject,'BackgroundColor','white');
1201 end
1202
1203
1204
1205 function pushbutton_load_Callback(hObject, eventdata, handles)
1206
1207
1208
1209
1210 global program controls targets robot
1211
1212 program=[];
1213
1214
1215 [filename, pathname] = uigetfile('*.m','Select .m program to load');
1216 if isequal(filename,0)
1217 disp('User selected Cancel')
1218 return;
1219 else
1220 disp(['User selected', fullfile(pathname, filename)])
1221 end
1222
1223
1224
1225 fp=fopen(fullfile(pathname, filename),'r');
1226
1227 disp('Loading target points');
1228 while 1
1229 a = fgets(fp);
1230 k = strfind(a, '%BEGINTARGETPOINTS');
1231
1232
1233 if k>=0
1234 break;
1235 end
1236 end
1237
1238 target_names=[];
1239
1240 N=0;
1241
1242 while 1
1243 a = fgets(fp);
1244 if length(a)<=1
1245 continue;
1246 end
1247 k = strfind(a, '%ENDTARGETPOINTS');
1248
1249 if k>=0
1250 break;
1251 end
1252
1253
1254 k = strfind(a, ':=');
1255 if k>=0
1256 continue;
1257 end
1258
1259 [name, Q, T, conf]=get_targetpoint_from_string(a);
1260
1261 N=N+1;
1262 targets{N}.name=name;
1263 targets{N}.Q=Q;
1264 targets{N}.T=T;
1265 targets{N}.conf=conf;
1266
1267
1268 qinv = inversekinematic(robot, T);
1269 q = select_configuration(robot, qinv, conf);
1270 targets{N}.q=q;
1271
1272 target_names{N}=name;
1273
1274
1275 set(controls.popupmenu_target_point,'String',target_names);
1276 set(controls.popupmenu_through_point,'String',target_names);
1277
1278 end
1279 controls.num_target_points=N;
1280
1281 disp('Loading program');
1282 program.n_lines=0;
1283
1284 target_names=[];
1285
1286 N=0;
1287
1288 while 1
1289 a = fgets(fp);
1290 if length(a)<=1
1291 continue;
1292 end
1293
1294 k = strfind(a, '%ENDMODULE');
1295
1296 if k>=0
1297 break;
1298 end
1299
1300
1301 k = strfind(a, '(');
1302 if isempty(k)
1303 continue;
1304 end
1305
1306 N = N+1;
1307
1308 program.n_lines=N;
1309 program.matlab_lines{N}=a(1:end-1);
1310
1311 end
1312
1313 fclose(fp);
1314
1315 draw_target_points();
1316
1317
1318
1319
1320 function pushbutton_save_Callback(hObject, eventdata, handles)
1321
1322
1323
1324
1325 global program controls targets
1326
1327
1328 [filename, pathname] = uiputfile('*.m','Save as .m');
1329 if isequal(filename,0) || isequal(pathname,0)
1330 disp('User selected Cancel')
1331 return;
1332 else
1333 disp(['User selected',fullfile(pathname,filename)])
1334 end
1335
1336
1337
1338 fp=fopen(fullfile(pathname, filename),'w');
1339
1340 disp('Saving target points');
1341
1342 fprintf(fp, '%%BEGINMODULE');
1343
1344 fprintf(fp, '\n%%BEGINTARGETPOINTS');
1345 for i=1:controls.num_target_points,
1346 tp = construct_target(i);
1347 ejes_ext = '[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];';
1348 a_rap = sprintf('%s:=[[%.5f, %.5f, %.5f],[%.5f, %.5f, %.5f, %.5f], [%.5f, %.5f, %.5f, %.5f], %s',...
1349 targets{i}.name, targets{i}.T(1,4),targets{i}.T(2,4),targets{i}.T(3,4),...
1350 targets{i}.Q(1), targets{i}.Q(2), targets{i}.Q(3), targets{i}.Q(4),...
1351 targets{i}.conf(1), targets{i}.conf(2), targets{i}.conf(3), targets{i}.conf(4), ejes_ext);
1352 a_mat = sprintf('%s=[[%.5f, %.5f, %.5f],[%.5f, %.5f, %.5f, %.5f], [%.5f, %.5f, %.5f, %.5f], %s',...
1353 targets{i}.name, targets{i}.T(1,4),targets{i}.T(2,4),targets{i}.T(3,4),...
1354 targets{i}.Q(1), targets{i}.Q(2), targets{i}.Q(3), targets{i}.Q(4),...
1355 targets{i}.conf(1), targets{i}.conf(2), targets{i}.conf(3), targets{i}.conf(4), ejes_ext);
1356
1357
1358 fprintf(fp, '\n%s', a_mat);
1359 end
1360
1361 fprintf(fp, '\n%%ENDTARGETPOINTS\n');
1362
1363
1364 disp('Saving program lines');
1365 for i=1:program.n_lines,
1366 fprintf(fp, '\n%s', program.matlab_lines{i});
1367
1368 end
1369
1370 fprintf(fp, '\n%%ENDMODULE\n');
1371 fclose(fp);
1372
1373
1374
1375
1376 function pushbutton_simulate_Callback(hObject, eventdata, handles)
1377
1378
1379
1380
1381 global program targets controls robot
1382
1383
1384 robot.q_vector=[];
1385 robot.qd_vector=[];
1386 robot.qdd_vector=[];
1387 robot.time=[];
1388
1389
1390 ejes_ext = '[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];';
1391
1392 for i=1:controls.num_target_points,
1393 a_mat = sprintf('%s=[[%.5f, %.5f, %.5f],[%.5f, %.5f, %.5f, %.5f], [%.5f, %.5f, %.5f, %.5f], %s',...
1394 targets{i}.name, targets{i}.T(1,4),targets{i}.T(2,4),targets{i}.T(3,4),...
1395 targets{i}.Q(1), targets{i}.Q(2), targets{i}.Q(3), targets{i}.Q(4),...
1396 targets{i}.conf(1), targets{i}.conf(2), targets{i}.conf(3), targets{i}.conf(4), ejes_ext);
1397 eval(a_mat);
1398 end
1399
1400 for i=1:program.n_lines,
1401 eval(program.matlab_lines{i});
1402 update_T_Q();
1403 update_sliders();
1404 draw_target_points();
1405 end
1406
1407 robot.q_vector=[];
1408 robot.qd_vector=[];
1409 robot.qdd_vector=[];
1410 robot.time=[];
1411
1412
1413
1414 function edit_nx_Callback(hObject, eventdata, handles)
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 function edit_nx_CreateFcn(hObject, eventdata, handles)
1425
1426
1427
1428 global controls
1429 controls.edit_nx=hObject;
1430
1431
1432 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1433 set(hObject,'BackgroundColor','white');
1434 end
1435
1436
1437
1438 function edit_ox_Callback(hObject, eventdata, handles)
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448 function edit_ox_CreateFcn(hObject, eventdata, handles)
1449
1450
1451
1452 global controls
1453 controls.edit_ox=hObject;
1454
1455
1456 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1457 set(hObject,'BackgroundColor','white');
1458 end
1459
1460
1461
1462 function edit_ax_Callback(hObject, eventdata, handles)
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472 function edit_ax_CreateFcn(hObject, eventdata, handles)
1473
1474
1475
1476 global controls
1477 controls.edit_ax=hObject;
1478
1479
1480 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1481 set(hObject,'BackgroundColor','white');
1482 end
1483
1484
1485
1486 function edit_pxt_Callback(hObject, eventdata, handles)
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496 function edit_pxt_CreateFcn(hObject, eventdata, handles)
1497
1498
1499
1500 global controls
1501 controls.edit_pxt=hObject;
1502
1503
1504 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1505 set(hObject,'BackgroundColor','white');
1506 end
1507
1508
1509
1510 function edit_ny_Callback(hObject, eventdata, handles)
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520 function edit_ny_CreateFcn(hObject, eventdata, handles)
1521
1522
1523
1524 global controls
1525 controls.edit_ny=hObject;
1526
1527
1528 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1529 set(hObject,'BackgroundColor','white');
1530 end
1531
1532
1533
1534 function edit_oy_Callback(hObject, eventdata, handles)
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 function edit_oy_CreateFcn(hObject, eventdata, handles)
1545
1546
1547
1548 global controls
1549 controls.edit_oy=hObject;
1550
1551
1552 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1553 set(hObject,'BackgroundColor','white');
1554 end
1555
1556
1557
1558 function edit_ay_Callback(hObject, eventdata, handles)
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568 function edit_ay_CreateFcn(hObject, eventdata, handles)
1569
1570
1571
1572 global controls
1573 controls.edit_ay=hObject;
1574
1575
1576 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1577 set(hObject,'BackgroundColor','white');
1578 end
1579
1580
1581
1582 function edit_pyt_Callback(hObject, eventdata, handles)
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592 function edit_pyt_CreateFcn(hObject, eventdata, handles)
1593
1594
1595
1596 global controls
1597 controls.edit_pyt=hObject;
1598
1599
1600 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1601 set(hObject,'BackgroundColor','white');
1602 end
1603
1604
1605
1606 function edit_nz_Callback(hObject, eventdata, handles)
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616 function edit_nz_CreateFcn(hObject, eventdata, handles)
1617
1618
1619
1620 global controls
1621 controls.edit_nz=hObject;
1622
1623
1624 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1625 set(hObject,'BackgroundColor','white');
1626 end
1627
1628
1629
1630 function edit_oz_Callback(hObject, eventdata, handles)
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640 function edit_oz_CreateFcn(hObject, eventdata, handles)
1641
1642
1643
1644 global controls
1645 controls.edit_oz=hObject;
1646
1647
1648 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1649 set(hObject,'BackgroundColor','white');
1650 end
1651
1652
1653
1654 function edit_az_Callback(hObject, eventdata, handles)
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664 function edit_az_CreateFcn(hObject, eventdata, handles)
1665
1666
1667
1668 global controls
1669 controls.edit_az=hObject;
1670
1671
1672 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1673 set(hObject,'BackgroundColor','white');
1674 end
1675
1676
1677
1678 function edit_pzt_Callback(hObject, eventdata, handles)
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688 function edit_pzt_CreateFcn(hObject, eventdata, handles)
1689
1690
1691
1692 global controls
1693 controls.edit_pzt=hObject;
1694
1695
1696 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1697 set(hObject,'BackgroundColor','white');
1698 end
1699
1700
1701
1702
1703
1704 function pushbutton_moveT_Callback(hObject, eventdata, handles)
1705
1706
1707
1708
1709
1710 global robot controls configuration
1711
1712
1713 [T,Q,P]=get_TQ_from_dialog();
1714
1715
1716
1717
1718
1719 if isfield(robot, 'tool')
1720
1721 T=T/(robot.tool.TCP);
1722 end
1723
1724
1725
1726 qinv = inversekinematic(robot, T);
1727
1728 distance_joint=[];
1729 for i=1:size(qinv,2),
1730 distance_joint(i)=sum(abs(qinv(:,i)-robot.q(:)));
1731 end
1732 [val,i]=min(distance_joint);
1733
1734 q_current=robot.q(:);
1735 q_final = qinv(:,i);
1736
1737 path = lineal_path_plan(q_current, q_final);
1738
1739 robot.q_vector=path;
1740
1741 test_joint_limits(robot);
1742
1743
1744 for i=1:size(path,2),
1745 drawrobot3d(robot, path(:,i));
1746 pause(configuration.time_delay);
1747 end
1748
1749 robot.q=q_final;
1750 update_T_Q();
1751 update_sliders();
1752 draw_target_points()
1753
1754 function edit_Q0_Callback(hObject, eventdata, handles)
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764 function edit_Q0_CreateFcn(hObject, eventdata, handles)
1765
1766
1767
1768 global controls
1769 controls.edit_Q0=hObject;
1770
1771
1772 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1773 set(hObject,'BackgroundColor','white');
1774 end
1775
1776
1777
1778 function edit_Q1_Callback(hObject, eventdata, handles)
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788 function edit_Q1_CreateFcn(hObject, eventdata, handles)
1789
1790
1791
1792 global controls
1793 controls.edit_Q1=hObject;
1794
1795
1796 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1797 set(hObject,'BackgroundColor','white');
1798 end
1799
1800
1801
1802 function edit_Q2_Callback(hObject, eventdata, handles)
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812 function edit_Q2_CreateFcn(hObject, eventdata, handles)
1813
1814
1815
1816 global controls
1817 controls.edit_Q2=hObject;
1818
1819
1820 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1821 set(hObject,'BackgroundColor','white');
1822 end
1823
1824
1825
1826 function edit_Q3_Callback(hObject, eventdata, handles)
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836 function edit_Q3_CreateFcn(hObject, eventdata, handles)
1837
1838
1839
1840 global controls
1841 controls.edit_Q3=hObject;
1842
1843
1844 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1845 set(hObject,'BackgroundColor','white');
1846 end
1847
1848
1849
1850 function edit_pxq_Callback(hObject, eventdata, handles)
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860 function edit_pxq_CreateFcn(hObject, eventdata, handles)
1861
1862
1863
1864 global controls
1865 controls.edit_pxq=hObject;
1866
1867
1868 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1869 set(hObject,'BackgroundColor','white');
1870 end
1871
1872
1873
1874 function edit_pyq_Callback(hObject, eventdata, handles)
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884 function edit_pyq_CreateFcn(hObject, eventdata, handles)
1885
1886
1887
1888 global controls
1889 controls.edit_pyq=hObject;
1890
1891
1892 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1893 set(hObject,'BackgroundColor','white');
1894 end
1895
1896
1897
1898 function edit_pzq_Callback(hObject, eventdata, handles)
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908 function edit_pzq_CreateFcn(hObject, eventdata, handles)
1909
1910
1911
1912 global controls
1913 controls.edit_pzq=hObject;
1914
1915
1916 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1917 set(hObject,'BackgroundColor','white');
1918 end
1919
1920
1921
1922
1923
1924
1925 function pushbutton_moveQ_Callback(hObject, eventdata, handles)
1926
1927
1928
1929
1930
1931 global robot controls configuration
1932
1933
1934 [T,Q,P]=get_TQ_from_dialog();
1935
1936
1937 T = quaternion2T(Q);
1938
1939 T(1,4)=P(1);
1940 T(2,4)=P(2);
1941 T(3,4)=P(3);
1942
1943
1944
1945
1946
1947 if isfield(robot, 'tool')
1948 T=T*inv(robot.tool.TCP);
1949 end
1950
1951
1952
1953
1954 qinv = inversekinematic(robot, T);
1955
1956 distance_joint=[];
1957 for i=1:size(qinv,2),
1958 distance_joint(i)=sum(abs(qinv(:,i)-robot.q(:)));
1959 end
1960 [val,i]=min(distance_joint);
1961
1962 q_current=robot.q;
1963 q_final = qinv(:,i);
1964
1965 path = lineal_path_plan(q_current, q_final);
1966
1967 robot.q_vector=path;
1968
1969 test_joint_limits(robot);
1970
1971
1972 for i=1:size(path,2),
1973 drawrobot3d(robot, path(:,i));
1974 pause(configuration.time_delay);
1975 end
1976
1977 robot.q=q_final;
1978 update_T_Q();
1979 update_sliders();
1980 draw_target_points()
1981
1982
1983
1984
1985
1986 function pushbutton_save_target_point_Callback(hObject, eventdata, handles)
1987
1988
1989
1990 global controls robot targets
1991
1992 target_point_name = get(controls.edit_target_point,'String');
1993
1994
1995 controls.num_target_points = controls.num_target_points+1;
1996
1997 T = directkinematic(robot, robot.q);
1998
1999
2000
2001 if isfield(robot, 'tool')
2002 T=T*robot.tool.TCP;
2003 end
2004
2005
2006 Q = T2quaternion(T);
2007 Q=real(Q);
2008 target.T = T;
2009 target.Q = Q;
2010 target.q = robot.q;
2011 target.conf = compute_configuration(robot, robot.q);
2012 target.name = target_point_name;
2013
2014
2015 targets{controls.num_target_points}=target;
2016 draw_target_points();
2017
2018 s0=get(controls.popupmenu_target_point,'String');
2019 a=length(s0);
2020 s0{a+1}=target_point_name;
2021
2022
2023 set(controls.popupmenu_target_point,'String',s0);
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036 function edit_target_point_Callback(hObject, eventdata, handles)
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046 function edit_target_point_CreateFcn(hObject, eventdata, handles)
2047
2048
2049
2050 global controls
2051 controls.edit_target_point = hObject;
2052
2053
2054
2055 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2056 set(hObject,'BackgroundColor','white');
2057 end
2058
2059
2060
2061 function popupmenu6_Callback(hObject, eventdata, handles)
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071 function popupmenu6_CreateFcn(hObject, eventdata, handles)
2072
2073
2074
2075
2076
2077
2078 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2079 set(hObject,'BackgroundColor','white');
2080 end
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259 function slider_q1_KeyPressFcn(hObject, eventdata, handles)
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271 function popupmenu_base_end_Callback(hObject, eventdata, handles)
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281 function popupmenu_base_end_CreateFcn(hObject, eventdata, handles)
2282
2283
2284
2285
2286 global controls
2287 controls.popupmenu_base_end=hObject;
2288
2289
2290
2291 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2292 set(hObject,'BackgroundColor','white');
2293 end
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303 function update_T_Q()
2304
2305 global robot controls
2306
2307
2308 T = directkinematic(robot, robot.q);
2309
2310
2311
2312 if isfield(robot, 'tool')
2313 T=T*robot.tool.TCP;
2314 end
2315
2316
2317 set(controls.edit_nx, 'String', num2str(T(1,1), '%.3f'));
2318 set(controls.edit_ny, 'String', num2str(T(2,1), '%.3f'));
2319 set(controls.edit_nz, 'String', num2str(T(3,1), '%.3f'));
2320 set(controls.edit_ox, 'String', num2str(T(1,2), '%.3f'));
2321 set(controls.edit_oy, 'String', num2str(T(2,2), '%.3f'));
2322 set(controls.edit_oz, 'String', num2str(T(3,2), '%.3f'));
2323 set(controls.edit_ax, 'String', num2str(T(1,3), '%.3f'));
2324 set(controls.edit_ay, 'String', num2str(T(2,3), '%.3f'));
2325 set(controls.edit_az, 'String', num2str(T(3,3), '%.3f'));
2326 set(controls.edit_pxt, 'String', num2str(T(1,4), '%.3f'));
2327 set(controls.edit_pyt, 'String', num2str(T(2,4), '%.3f'));
2328 set(controls.edit_pzt, 'String', num2str(T(3,4), '%.3f'));
2329
2330
2331 Q = T2quaternion(T);
2332 Q=real(Q);
2333 set(controls.edit_Q0, 'String', num2str(Q(1),'%.3f'));
2334 set(controls.edit_Q1, 'String', num2str(Q(2), '%.3f'));
2335 set(controls.edit_Q2, 'String', num2str(Q(3), '%.3f'));
2336 set(controls.edit_Q3, 'String', num2str(Q(4), '%.3f'));
2337
2338 set(controls.edit_pxq, 'String', num2str(T(1,4), '%.3f'));
2339 set(controls.edit_pyq, 'String', num2str(T(2,4), '%.3f'));
2340 set(controls.edit_pzq, 'String', num2str(T(3,4), '%.3f'));
2341
2342
2343
2344 function [T,Q,P]=get_TQ_from_dialog()
2345
2346 global robot controls
2347
2348
2349 T = eye(4);
2350
2351
2352 T(1,1)=sscanf(get(controls.edit_nx, 'String'),'%f');
2353 T(2,1)=sscanf(get(controls.edit_ny, 'String'), '%f');
2354 T(3,1)=sscanf(get(controls.edit_nz, 'String'), '%f');
2355 T(1,2)=sscanf(get(controls.edit_ox, 'String'), '%f');
2356 T(2,2)=sscanf(get(controls.edit_oy, 'String'), '%f');
2357 T(3,2)=sscanf(get(controls.edit_oz, 'String'), '%f');
2358 T(1,3)=sscanf(get(controls.edit_ax, 'String'), '%f');
2359 T(2,3)=sscanf(get(controls.edit_ay, 'String'), '%f');
2360 T(3,3)=sscanf(get(controls.edit_az, 'String'), '%f');
2361 T(1,4)=sscanf(get(controls.edit_pxt, 'String'), '%f');
2362 T(2,4)=sscanf(get(controls.edit_pyt, 'String'), '%f');
2363 T(3,4)=sscanf(get(controls.edit_pzt, 'String'), '%f');
2364
2365 Q = zeros(1,4);
2366 Q(1)=sscanf(get(controls.edit_Q0, 'String'),'%f');
2367 Q(2)=sscanf(get(controls.edit_Q1, 'String'),'%f');
2368 Q(3)=sscanf(get(controls.edit_Q2, 'String'),'%f');
2369 Q(4)=sscanf(get(controls.edit_Q3, 'String'),'%f');
2370
2371 P(1)=sscanf(get(controls.edit_pxq, 'String'), '%f');
2372 P(2)=sscanf(get(controls.edit_pyq, 'String'), '%f');
2373 P(3)=sscanf(get(controls.edit_pzq, 'String'), '%f');
2374
2375
2376
2377
2378 function update_sliders()
2379
2380 global robot controls
2381
2382 error = test_joints(robot, robot.q);
2383
2384
2385 if error == 1
2386 return;
2387 end
2388
2389 if robot.DOF > 0
2390
2391 set(controls.slider_q1, 'Value', robot.q(1)*180/pi);
2392
2393 set(controls.edit_q1, 'String', num2str(robot.q(1)*180/pi,3));
2394 end
2395 if robot.DOF > 1
2396 set(controls.slider_q2, 'Value', robot.q(2)*180/pi);
2397 set(controls.edit_q2, 'String', num2str(robot.q(2)*180/pi,3));
2398 end
2399 if robot.DOF > 2
2400 set(controls.slider_q3, 'Value', robot.q(3)*180/pi);
2401 set(controls.edit_q3, 'String', num2str(robot.q(3)*180/pi,3));
2402 end
2403 if robot.DOF > 3
2404 set(controls.slider_q4, 'Value', robot.q(4)*180/pi);
2405 set(controls.edit_q4, 'String', num2str(robot.q(4)*180/pi,3));
2406 end
2407 if robot.DOF > 4
2408 set(controls.slider_q5, 'Value', robot.q(5)*180/pi);
2409 set(controls.edit_q5, 'String', num2str(robot.q(5)*180/pi,3));
2410 end
2411 if robot.DOF > 5
2412 set(controls.slider_q6, 'Value', robot.q(6)*180/pi);
2413 set(controls.edit_q6, 'String', num2str(robot.q(6)*180/pi,3));
2414 end
2415
2416 if robot.DOF > 6
2417 disp('Not showing q when robot.DOF >= 7');
2418 end
2419
2420
2421
2422 function path=lineal_path_plan(q_ini, q_final)
2423
2424 global robot
2425
2426
2427 num_points = 15;
2428
2429 path = [];
2430
2431 for i=1:robot.DOF,
2432 delta = (q_final(i)-q_ini(i))/num_points;
2433 for j=1:num_points-1;
2434 path(i,j)= q_ini(i)+delta*j;
2435 end
2436 path(i,num_points)=q_final(i);
2437 end
2438
2439
2440
2441
2442 function path=lineal_path_planXYZ(P_ini, P_final)
2443
2444 global robot
2445
2446
2447 num_points = 5;
2448
2449 path = [];
2450
2451 for i=1:3,
2452 delta = (P_final(i)-P_ini(i))/num_points;
2453 for j=1:num_points-1;
2454 path(i,j)= P_ini(i)+delta*j;
2455 end
2456 path(i,num_points)=P_final(i);
2457 end
2458
2459
2460
2461
2462 function follow_line(P_ini,P_final)
2463 global robot configuration
2464
2465 T = directkinematic(robot, robot.q);
2466
2467 current_conf = compute_configuration(robot, robot.q);
2468
2469 path = lineal_path_planXYZ(P_ini,P_final);
2470
2471 for i=1:size(path,2),
2472 T(1:3,4)=path(:,i);
2473
2474 qinv = inversekinematic(robot, T);
2475
2476
2477 q=select_closest_joint_coordinates(qinv, robot.q);
2478
2479 robot.q = q;
2480
2481
2482 error = test_joints(robot, robot.q);
2483
2484 drawrobot3d(robot, robot.q);
2485
2486
2487
2488 if error == 1
2489 disp('\nAn error has occurred during the trajectory. Please check angle ranges');
2490 break;
2491 end
2492 end
2493 update_T_Q();
2494 update_sliders();
2495 plot3(path(1,:),path(2,:),path(3,:),'k', 'LineWidth', 3);
2496
2497 draw_target_points();
2498
2499
2500
2501
2502 function draw_target_points()
2503 global targets configuration controls
2504 figure(configuration.figure.robot)
2505
2506 s=0.1;
2507
2508 for i=1:controls.num_target_points,
2509
2510 T = targets{i}.T;
2511 p0=T(1:3,4)';
2512 x=p0+s*T(1:3,1)';
2513 y=p0+s*T(1:3,2)';
2514 z=p0+s*T(1:3,3)';
2515
2516 vect_arrow(p0,x,'r')
2517 vect_arrow(p0,y,'g')
2518 vect_arrow(p0,z,'b')
2519
2520 text(x(1)+0.01, x(2)+0.01, x(3)+0.01,targets{i}.name, 'FontWeight', 'bold', 'HorizontalAlignment', 'Center', 'FontSize', 14);
2521 end
2522
2523
2524 function tp = construct_target(target_num)
2525
2526 global targets
2527
2528 T = targets{target_num}.T;
2529 Q = targets{target_num}.Q;
2530 conf = targets{target_num}.conf;
2531
2532 tp = [[T(1,4),T(2,4),T(3,4)],[Q(1), Q(2), Q(3), Q(4)], [conf(1), conf(2), conf(3), conf(4)], [9E9,9E9,9E9,9E9,9E9,9E9]];
2533
2534
2535
2536
2537 function [name, Q, T, conf]=get_targetpoint_from_string(a)
2538
2539
2540 [name, remain] = strtok(a,'=');
2541 [token, remain] = strtok(remain,'[');
2542
2543 eval(['target=' remain]);
2544
2545 px=target(1);
2546 py=target(2);
2547 pz=target(3);
2548
2549 Q = target(4:7);
2550 T = quaternion2T(Q, [px py pz]);
2551
2552 conf = target(8:11);
2553
2554
2555
2556
2557 function [instruction_matlab, instruction_rapid, tp1, tp2, joint_coord]=build_instruction_to_eval()
2558
2559 global controls targets robot
2560
2561 s = get(controls.popupmenu_instruction,'String');
2562 i = get(controls.popupmenu_instruction,'Value');
2563 s1=s{i};
2564
2565 tp1=[];
2566 tp1_name=[];
2567 tp2=[];
2568 tp2_name = [];
2569 joint_coord=[];
2570 switch s1
2571 case {'MoveJ','MoveL'}
2572
2573 s = get(controls.popupmenu_target_point,'String');
2574 target_num = get(controls.popupmenu_target_point,'Value');
2575 s2=s{target_num};
2576
2577 s = get(controls.popupmenu_speed,'String');
2578 i = get(controls.popupmenu_speed,'Value');
2579 s3=s{i};
2580
2581 s = get(controls.popupmenu_precision,'String');
2582 i = get(controls.popupmenu_precision,'Value');
2583 s4=s{i};
2584
2585 instruction_rapid = [s1 ' ' s2 ',' s3 ',' s4 ',tool0\Wobj:=wobj0;'];
2586
2587 tp1=construct_target(target_num);
2588
2589
2590 s = get(controls.popupmenu_target_point,'String');
2591 target_num = get(controls.popupmenu_target_point,'Value');
2592 tp1_name=s{target_num};
2593
2594 instruction_matlab = ['robot=' s1 '(robot, tp1,' sprintf(' ''%s'' ', s3) ',' sprintf(' ''%s'' ', s4) ', robot.tool0, robot.wobj0);'];
2595 fprintf('\n**********************************************\n');
2596 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2597 fprintf('**********************************************\n');
2598
2599
2600
2601 case 'MoveAbsJ'
2602
2603 s = get(controls.popupmenu_target_point,'String');
2604 target_num = get(controls.popupmenu_target_point,'Value');
2605 s2=s{target_num};
2606
2607 s = get(controls.popupmenu_speed,'String');
2608 i = get(controls.popupmenu_speed,'Value');
2609 s3=s{i};
2610
2611 s = get(controls.popupmenu_precision,'String');
2612 i = get(controls.popupmenu_precision,'Value');
2613 s4=s{i};
2614
2615 instruction_rapid = [s1 ' ' s2 ',' s3 ',' s4 ',tool0\Wobj:=wobj0;'];
2616
2617
2618 joint_coord=[targets{target_num}.q' 1e9, 1e9, 1e9, 1e9, 1e9, 1e9];
2619
2620
2621 instruction_matlab = ['robot=' s1 '(robot, joint_coord,' sprintf(' ''%s'' ', s3) ',' sprintf(' ''%s'' ', s4) ', robot.tool0, robot.wobj0);'];
2622 fprintf('\n**********************************************\n');
2623 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2624 fprintf('**********************************************\n');
2625
2626
2627
2628
2629 case 'MoveC'
2630 s = get(controls.popupmenu_target_point,'String');
2631 target_num1 = get(controls.popupmenu_target_point,'Value');
2632 s2=s{target_num1};
2633
2634 s = get(controls.popupmenu_through_point,'String');
2635 target_num2 = get(controls.popupmenu_through_point,'Value');
2636 s3=s{target_num2};
2637
2638 s = get(controls.popupmenu_speed,'String');
2639 i = get(controls.popupmenu_speed,'Value');
2640 vel=s{i};
2641
2642 s = get(controls.popupmenu_precision,'String');
2643 i = get(controls.popupmenu_precision,'Value');
2644 prec=s{i};
2645
2646 instruction_rapid = [s1 ' ' s3 ',' s2 ',' vel ',' prec ',tool0\Wobj:=wobj0;'];
2647
2648 tp2=construct_target(target_num1);
2649 tp1=construct_target(target_num2);
2650
2651 instruction_matlab = ['robot=' s1 '(robot, tp1, tp2, ' sprintf(' ''%s'' ', vel) ',' sprintf(' ''%s'' ', prec) ', robot.tool0, robot.wobj0);'];
2652 fprintf('\n**********************************************\n');
2653 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2654 fprintf('**********************************************\n');
2655
2656
2657
2658 otherwise disp('RAPID instruction not supported');
2659 end
2660
2661
2662
2663 function [instruction_matlab, instruction_rapid]=build_instruction_to_save()
2664
2665 global controls targets robot
2666
2667 s = get(controls.popupmenu_instruction,'String');
2668 i = get(controls.popupmenu_instruction,'Value');
2669 s1=s{i};
2670
2671 tp1=[];
2672 tp1_name=[];
2673 tp2=[];
2674 tp2_name = [];
2675 joint_coord=[];
2676 switch s1
2677 case {'MoveJ','MoveL'}
2678
2679 s = get(controls.popupmenu_target_point,'String');
2680 target_num = get(controls.popupmenu_target_point,'Value');
2681 s2=s{target_num};
2682
2683 s = get(controls.popupmenu_speed,'String');
2684 i = get(controls.popupmenu_speed,'Value');
2685 s3=s{i};
2686
2687 s = get(controls.popupmenu_precision,'String');
2688 i = get(controls.popupmenu_precision,'Value');
2689 s4=s{i};
2690
2691 instruction_rapid = [s1 ' ' s2 ',' s3 ',' s4 ',tool0\Wobj:=wobj0;'];
2692
2693
2694
2695 s = get(controls.popupmenu_target_point,'String');
2696 target_num = get(controls.popupmenu_target_point,'Value');
2697 tp_name=s{target_num};
2698
2699 instruction_matlab = ['robot=' s1 '(robot,' tp_name ',' ...
2700 sprintf(' ''%s'' ', s3) ',' sprintf(' ''%s'' ', s4) ', robot.tool0, robot.wobj0);'];
2701 fprintf('\n**********************************************\n');
2702 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2703 fprintf('**********************************************\n');
2704
2705
2706
2707 case 'MoveAbsJ'
2708
2709 s = get(controls.popupmenu_target_point,'String');
2710 target_num = get(controls.popupmenu_target_point,'Value');
2711 s2=s{target_num};
2712
2713 s = get(controls.popupmenu_speed,'String');
2714 i = get(controls.popupmenu_speed,'Value');
2715 s3=s{i};
2716
2717 s = get(controls.popupmenu_precision,'String');
2718 i = get(controls.popupmenu_precision,'Value');
2719 s4=s{i};
2720
2721 instruction_rapid = [s1 ' ' s2 ',' s3 ',' s4 ',tool0\Wobj:=wobj0;'];
2722
2723
2724
2725
2726 s = get(controls.popupmenu_target_point,'String');
2727 target_num = get(controls.popupmenu_target_point,'Value');
2728 tp_name=s{target_num};
2729
2730 instruction_matlab = ['robot=' s1 '(robot,' tp_name ','...
2731 sprintf(' ''%s'' ', s3) ',' sprintf(' ''%s'' ', s4) ', robot.tool0, robot.wobj0);'];
2732 fprintf('\n**********************************************\n');
2733 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2734 fprintf('**********************************************\n');
2735
2736
2737
2738
2739 case 'MoveC'
2740 s = get(controls.popupmenu_target_point,'String');
2741 target_num1 = get(controls.popupmenu_target_point,'Value');
2742 s2=s{target_num1};
2743
2744 s = get(controls.popupmenu_through_point,'String');
2745 target_num2 = get(controls.popupmenu_through_point,'Value');
2746 s3=s{target_num2};
2747
2748 s = get(controls.popupmenu_speed,'String');
2749 i = get(controls.popupmenu_speed,'Value');
2750 vel=s{i};
2751
2752 s = get(controls.popupmenu_precision,'String');
2753 i = get(controls.popupmenu_precision,'Value');
2754 prec=s{i};
2755
2756 instruction_rapid = [s1 ' ' s3 ',' s2 ',' vel ',' prec ',tool0\Wobj:=wobj0;'];
2757
2758
2759
2760 instruction_matlab = ['robot=' s1 '(robot,' s3 ',' s2 ', ' sprintf(' ''%s'' ', vel) ',' sprintf(' ''%s'' ', prec) ', robot.tool0, robot.wobj0);'];
2761 fprintf('\n**********************************************\n');
2762 fprintf('Evaluating instruction:\nRAPID:\n\t%s\nMatlab:\n\t%s\n', instruction_rapid, instruction_matlab);
2763 fprintf('**********************************************\n');
2764
2765
2766
2767 otherwise disp('RAPID instruction not supported');
2768 end
2769
2770
2771
2772 function popupmenu_line_reorient_Callback(hObject, eventdata, handles)
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782 function popupmenu_line_reorient_CreateFcn(hObject, eventdata, handles)
2783
2784
2785
2786
2787
2788
2789 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2790 set(hObject,'BackgroundColor','white');
2791 end
2792
2793
2794 global controls
2795 controls.popupmenu_line_reorient=hObject;
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807 function pushbutton_show_target_point_Callback(hObject, eventdata, handles)
2808
2809
2810
2811
2812 global controls targets robot
2813
2814 T = directkinematic(robot, robot.q);
2815
2816
2817
2818 if isfield(robot, 'tool')
2819 T=T*robot.tool.TCP;
2820 disp('Show Target Point: The tool has been considered in the Target Point! OK!')
2821 end
2822
2823
2824 Q = T2quaternion(T);
2825
2826 Q = real(Q);
2827 conf = compute_configuration(robot, robot.q);
2828
2829
2830
2831
2832
2833
2834 tp=round_4_digits(T, Q, conf);
2835
2836 fprintf('\n\ntp:=[[%.4f,%.4f,%.4f],[%.4f,%.4f,%.4f,%.4f],[%d,%d,%d,%d],[9E9,9E9,9E9,9E9,9E9,9E9]];\n\n',tp(1),tp(2),tp(3),tp(4),tp(5),tp(6),tp(7),tp(8),tp(9),tp(10),tp(11));
2837
2838
2839 function tp=round_4_digits(T, Q, conf)
2840
2841 global robot
2842
2843 tp = [round(10000*[T(1,4),T(2,4),T(3,4)])/10000,round(10000*[Q(1), Q(2), Q(3), Q(4)])/10000, [conf(1), conf(2), conf(3), conf(4)], [9E9,9E9,9E9,9E9,9E9,9E9]];
2844
2845
2846 T_target = transform_to_homogeneous(tp);
2847
2848
2849
2850 if isfield(robot, 'tool')
2851 T = T_target/robot.tool.TCP;
2852 end
2853
2854 q=inversekinematic(robot, T_target);
2855
2856
2857
2858
2859
2860
2861
2862
2863 index=find_closest(q, robot.q);
2864
2865
2866
2867 T = directkinematic(robot, q(:,index));
2868
2869
2870 Q = T2quaternion(T);
2871
2872 Q = real(Q);
2873 conf = compute_configuration(robot, q(:,index));
2874
2875 tp = [[T(1,4),T(2,4),T(3,4)],[Q(1), Q(2), Q(3), Q(4)], [conf(1), conf(2), conf(3), conf(4)], [9E9,9E9,9E9,9E9,9E9,9E9]];
2876
2877
2878
2879
2880
2881 function pushbutton_show_target_point_KeyPressFcn(hObject, eventdata, handles)
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894 function popupmenu_resolution_Callback(hObject, eventdata, handles)
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904 function popupmenu_resolution_CreateFcn(hObject, eventdata, handles)
2905
2906
2907
2908
2909 global controls
2910 controls.popupmenu_resolution=hObject;
2911
2912
2913
2914
2915 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2916 set(hObject,'BackgroundColor','white');
2917 end
2918
2919
2920
2921
2922
2923
2924 function pushbutton_reset_all_Callback(hObject, eventdata, handles)
2925
2926
2927
2928
2929 global configuration robot controls
2930
2931 update_T_Q();
2932 figure(configuration.figure.robot);
2933
2934
2935 drawrobot3d(robot, robot.q);
2936
2937 final_joints = zeros(1,robot.DOF);
2938
2939 command =[' MoveAbsJ(final_joints,' sprintf(' ''%s'' ', 'vmax') ',' sprintf(' ''%s'' ', 'fine') ',robot.tool0, robot.wobj0);'];
2940 eval(command);
2941 robot.q=final_joints;
2942
2943 update_T_Q();
2944 draw_target_points();
2945 update_sliders();
2946
2947
2948
2949 function pushbutton_save_target_point_KeyPressFcn(hObject, eventdata, handles)
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964 function index=find_closest(q,qi)
2965
2966 qq=zeros(size(q,1),size(q,2));
2967 for i=1:size(q,2),
2968 qq(:,i)=qi;
2969 end
2970
2971 a=sum((q-qq).^2);
2972
2973 [val, index] = min(a);
2974
2975
2976
2977 function pushbutton_load_robot_Callback(hObject, eventdata, handles)
2978
2979
2980
2981 global configuration robot controls
2982
2983
2984 robot=load_robot()
2985
2986
2987 function pushbutton_load_robot_KeyPressFcn(hObject, eventdata, handles)
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998 function push_button_load_end_tool_Callback(hObject, eventdata, handles)
2999
3000
3001
3002 global configuration robot controls
3003
3004
3005 robot.tool=load_robot
3006
3007
3008 function push_button_load_end_tool_KeyPressFcn(hObject, eventdata, handles)
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020 function push_button_load_environment_Callback(hObject, eventdata, handles)
3021
3022
3023
3024
3025 global configuration robot controls
3026
3027 robot.equipment=load_robot
3028
3029
3030 function push_button_load_environment_KeyPressFcn(hObject, eventdata, handles)
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040 function pushbutton_simulate_instruction_KeyPressFcn(hObject, eventdata, handles)
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050 function push_button_save_TP_Callback(hObject, eventdata, handles)
3051
3052
3053
3054
3055
3056 global controls targets robot
3057
3058
3059
3060 [filename, pathname] = uiputfile('*.m','Save as .m');
3061 if isequal(filename,0) || isequal(pathname,0)
3062 disp('User selected Cancel')
3063 return;
3064 else
3065 disp(['User selected',fullfile(pathname,filename)])
3066 end
3067
3068
3069
3070 fp=fopen(fullfile(pathname, filename),'w');
3071
3072 fprintf('Saving %d target points to file', controls.num_target_points);
3073
3074 for i=1:controls.num_target_points,
3075
3076
3077 tp=round_4_digits(targets{i}.T, targets{i}.Q, targets{i}.conf);
3078 ejes_ext = '[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];';
3079
3080
3081
3082
3083
3084
3085
3086
3087 a_mat = sprintf('%s=[[%.4f, %.4f, %.4f],[%.4f, %.4f, %.4f, %.4f], [%d, %d, %d, %d], %s',...
3088 targets{i}.name, tp(1), tp(2), tp(3),...
3089 tp(4), tp(5), tp(6), tp(7),...
3090 tp(8), tp(9),tp(10), tp(11), ejes_ext);
3091
3092
3093 fprintf(fp, '\n%s', a_mat);
3094 end
3095
3096 fclose(fp);
3097
3098
3099
3100 function pushbutton_refresh_Callback(hObject, eventdata, handles)
3101
3102
3103
3104 global robot
3105
3106 update_T_Q();
3107 update_sliders();
3108 draw_target_points();
3109 drawrobot3d(robot, robot.q)
3110
3111
3112 function pushbutton_refresh_KeyPressFcn(hObject, eventdata, handles)
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124 function pushbutton_load_piece_Callback(hObject, eventdata, handles)
3125
3126
3127
3128
3129 global robot
3130
3131 robot.piece=load_robot();
3132