-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPuma_Simulation.m
1853 lines (1732 loc) · 67.5 KB
/
Puma_Simulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% This is Puma_Simulation.m, a 3D Matlab Kinematic model of a Puma robot located
% in the robotics lab of Walla Walla University.
% The Code is based on puma3d.m by Don Riley and was modified and enhanced
% by Paschalis Pelitaris.
%
% puma3d.m code can be found in https://www.mathworks.com/matlabcentral/fileexchange/14932-3d-puma-robot-demo
% It also containts maximize.m function by Oliver Woodford https://www.mathworks.com/matlabcentral/fileexchange/25471-maximize
%
% The file uses CAD data converted to Matlab using cad2matdemo.m, which
% is located on the Mathworks central file exchange.
%
function Puma_Simulation
% GUI kinematic demo for the Puma Robot.
% Robot geometry uses the CAD2MATDEMO code in the Mathworks file exchange
%
%%
clear;close all; clc
%% GUI Initialisation
loaddata
InitHome
%
% Create the push buttons: pos is: [left bottom width height]
draw_demo = uicontrol(fig_1,'String','Draw','callback',@draw_demo_button_press,...
'Position',[20 5 60 20]);
Drawing_pop = uicontrol(fig_1,'style','popupmenu',...
'String',{'fibonacci' 'Puma' 'Duth Robotics' 'DUTH' 'P.P.'}, 'Value', 1,...
'Position',[85 10 50 15]);
rnd_demo = uicontrol(fig_1,'String','Random Move','callback',@rnd_demo_button_press,...
'Position',[150 5 80 20]);
clr_trail = uicontrol(fig_1,'String','Clr Trail','callback',@clr_trail_button_press,...
'Position',[250 5 60 20]);
%
home = uicontrol(fig_1,'String','Home','callback',@home_button_press,...
'Position',[330 5 70 20]);
%
DH_Tm = uicontrol(fig_1,'String','DH & T matrix','callback',@DH_Tm_button_press,...
'Position',[420 5 100 20]);
%
InverseKin = uicontrol(fig_1, 'units','normalized', 'String','Inverse Kinematics','callback',@InverseKin_button_press,...
'Position',[0.0781 0.385 0.0781 0.029]);
%
%% Kinematics Panel
%
K_p = uipanel(fig_1, 'units','normalized', 'Position',[0.0156 0.05625 0.207 ,0.31], ...
'Title','Forward Kinematics','FontSize',11);
%% Inverse Kinematics Panel
%
IK_p = uipanel(fig_1, 'units','normalized', 'Position',[0.0156 0.415 0.207 0.495],...
'Title','Inverse Kinematics','FontSize',11);
%% D-H Table Panel
%
DH_p = uipanel(fig_1, 'units','normalized', 'Position',[0.7813 0.05625 0.207 0.365],...
'Visible', 'On', 'Title','Denavit–Hartenberg','FontSize',11);
%% Tranformation matrix Panel
%
Tm_p = uipanel(fig_1, 'units','normalized', 'Position',[0.75 0.43 0.25 0.3],...
'Visible', 'On', 'Title','Tranformation matrix','FontSize',11);
%
% Angle Range Default Name
% Theta 1: 320 (-160 to 160) 90 Waist Joint
% Theta 2: 220 (-110 to 110) -90 Shoulder Joint
% Theta 3: 270 (-135 to 135) -90 Elbow Joint
% Theta 4: 532 (-266 to 266) 0 Wrist Roll
% Theta 5: 200 (-100 to 100) 0 Wrist Bend
% Theta 6: 600 (-300 to 300) 0 Wrist Swivel
t1_home = 90; % offset to define the "home" position as UP.
t2_home = -90;
t3_home = -90;
LD = 105; % Left, used to set the GUI.
HT = 18; % Height
BT = 156; % Bottom
%% GUI buttons for Theta 1. pos is: [left bottom width height]
t1_slider = uicontrol(K_p,'style','slider',...
'Max',160,'Min',-160,'Value',0,...
'SliderStep',[0.05 0.2],... % (160*2*0,05)
'callback',@t1_slider_button_press,...
'Position',[LD BT 120 HT]);
t1_min = uicontrol(K_p,'style','text',...
'String','-160',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t1_max = uicontrol(K_p,'style','text',...
'String','+160',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t1_text = uibutton(K_p,'style','text',... % Nice program Doug. Need this
'String','\theta_1',... % due to no TeX in uicontrols.
'Position',[LD-100 BT 20 HT]); % L, B, W, H
% t1_text = uicontrol(K_p,'style','text',... % when matlab fixes uicontrol
% 'String','t1',... % for TeX, then I can use this.
% 'Position',[LD-100 BT 20 HT]); % L, B, W, H
t1_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t1_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
%% GUI buttons for Theta 2.
BT = 126; % Bottom
t2_slider = uicontrol(K_p,'style','slider',...
'Max',110,'Min',-110,'Value',0,... % Mech. stop limits ! diorthosa kai to 115 se 110
'SliderStep',[0.05 0.2],...
'callback',@t2_slider_button_press,...
'Position',[LD BT 120 HT]);
t2_min = uicontrol(K_p,'style','text',...
'String','-110',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t2_max = uicontrol(K_p,'style','text',...
'String','+110',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t2_text = uibutton(K_p,'style','text',...
'String','\theta_2',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
t2_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t2_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
%% GUI buttons for Theta 3.
BT = 96; % Bottom
t3_slider = uicontrol(K_p,'style','slider',...
'Max',135,'Min',-135,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@t3_slider_button_press,...
'Position',[LD BT 120 HT]);
t3_min = uicontrol(K_p,'style','text',...
'String','-135',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t3_max = uicontrol(K_p,'style','text',...
'String','+135',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t3_text = uibutton(K_p,'style','text',...
'String','\theta_3',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
t3_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t3_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
%% GUI buttons for Theta 4.
BT = 66; % Bottom
t4_slider = uicontrol(K_p,'style','slider',...
'Max',266,'Min',-266,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@t4_slider_button_press,...
'Position',[LD BT 120 HT]);
t4_min = uicontrol(K_p,'style','text',...
'String','-266',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t4_max = uicontrol(K_p,'style','text',...
'String','+266',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t4_text = uibutton(K_p,'style','text',...
'String','\theta_4',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
t4_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t4_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
%% GUI buttons for Theta 5.
BT = 36; % Bottom
t5_slider = uicontrol(K_p,'style','slider',...
'Max',100,'Min',-100,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@t5_slider_button_press,...
'Position',[LD BT 120 HT]);
t5_min = uicontrol(K_p,'style','text',...
'String','-100',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t5_max = uicontrol(K_p,'style','text',...
'String','+100',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t5_text = uibutton(K_p,'style','text',...
'String','\theta_5',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
t5_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t5_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
%% GUI buttons for Theta 6.
BT = 6; % Bottom
t6_slider = uicontrol(K_p,'style','slider',...
'Max',300,'Min',-300,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@t6_slider_button_press,...
'Position',[LD BT 120 HT]);
t6_min = uicontrol(K_p,'style','text',...
'String','-300',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
t6_max = uicontrol(K_p,'style','text',...
'String','+300',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
t6_text = uibutton(K_p,'style','text',...
'String','\theta_6',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
t6_edit = uicontrol(K_p,'style','edit',...
'String',0,...
'callback',@t6_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%
BT = 275;
%% GUI buttons for Px axis.
Px_slider = uicontrol(IK_p,'style','slider',...
'Max',1250,'Min',-1250,'Value',0,... % to 1250 isws den einai swsto
'SliderStep',[0.05 0.2],...
'callback',@Px_slider_button_press,...
'Position',[LD BT 120 HT]);
Px_min = uicontrol(IK_p,'style','text',...
'String','-1250',...
'Position',[LD-33 BT+1 32 HT-4]); % L, from bottom, W, H
Px_max = uicontrol(IK_p,'style','text',...
'String','+1250',...
'Position',[LD+122 BT+1 32 HT-4]); % L, B, W, H
Px_text = uibutton(IK_p,'style','text',...
'String','P_x',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
Px_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@Px_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for Py axis.
BT = BT-30;
Py_slider = uicontrol(IK_p,'style','slider',...
'Max',1250,'Min',-1250,'Value',0,... % to 1250 isws den einai swsto
'SliderStep',[0.05 0.2],...
'callback',@Py_slider_button_press,...
'Position',[LD BT 120 HT]);
Py_min = uicontrol(IK_p,'style','text',...
'String','-1250',...
'Position',[LD-33 BT+1 32 HT-4]); % L, from bottom, W, H
Py_max = uicontrol(IK_p,'style','text',...
'String','+1250',...
'Position',[LD+122 BT+1 32 HT-4]); % L, B, W, H
Py_text = uibutton(IK_p,'style','text',...
'String','P_y',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
Py_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@Py_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for Pz axis.
BT = BT-30;
Pz_slider = uicontrol(IK_p,'style','slider',...
'Max',1250,'Min',-1250,'Value',0,... % to 1250 den einai swsto
'SliderStep',[0.05 0.2],...
'callback',@Pz_slider_button_press,...
'Position',[LD BT 120 HT]);
Pz_min = uicontrol(IK_p,'style','text',...
'String','-1250',...
'Position',[LD-33 BT+1 32 HT-4]); % L, from bottom, W, H
Pz_max = uicontrol(IK_p,'style','text',...
'String','+1250',...
'Position',[LD+122 BT+1 32 HT-4]); % L, B, W, H
Pz_text = uibutton(IK_p,'style','text',...
'String','P_z',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
Pz_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@Pz_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R11 axis.
BT = BT-30;
R11_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R11_slider_button_press,...
'Position',[LD BT 120 HT]);
R11_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R11_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R11_text = uibutton(IK_p,'style','text',...
'String','r_1_1',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R11_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R11_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R21 axis.
BT = BT-30;
R21_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R21_slider_button_press,...
'Position',[LD BT 120 HT]);
R21_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R21_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R21_text = uibutton(IK_p,'style','text',...
'String','r_2_1',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R21_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R21_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R31 axis.
BT = BT-30;
R31_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R31_slider_button_press,...
'Position',[LD BT 120 HT]);
R31_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R31_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R31_text = uibutton(IK_p,'style','text',...
'String','r_3_1',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R31_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R31_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R13 axis.
BT = BT-30;
R13_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R13_slider_button_press,...
'Position',[LD BT 120 HT]);
R13_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R13_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R13_text = uibutton(IK_p,'style','text',...
'String','r_1_3',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R13_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R13_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R23 axis.
BT = BT-30;
R23_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R23_slider_button_press,...
'Position',[LD BT 120 HT]);
R23_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R23_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R23_text = uibutton(IK_p,'style','text',...
'String','r_2_3',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R23_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R23_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% GUI buttons for R33 axis.
BT = BT-30;
R33_slider = uicontrol(IK_p,'style','slider',...
'Max',1,'Min',-1,'Value',0,...
'SliderStep',[0.05 0.2],...
'callback',@R33_slider_button_press,...
'Position',[LD BT 120 HT]);
R33_min = uicontrol(IK_p,'style','text',...
'String','-1',...
'Position',[LD-30 BT+1 25 HT-4]); % L, from bottom, W, H
R33_max = uicontrol(IK_p,'style','text',...
'String','+1',...
'Position',[LD+125 BT+1 25 HT-4]); % L, B, W, H
R33_text = uibutton(IK_p,'style','text',...
'String','r_3_3',...
'Position',[LD-100 BT 20 HT]); % L, B, W, H
R33_edit = uicontrol(IK_p,'style','edit',...
'String',0,...
'callback',@R33_edit_button_press,...
'Position',[LD-75 BT 30 HT]); % L, B, W, H
%% Elbow & flip sign
Elbow_Sign_button = uicontrol(IK_p,'style','radiobutton',...
'String','Elbow Up / Down',...
'callback',@elbow_sign_func,...
'Position',[LD-100 BT-30 130 HT]);
Flip_Sign_button = uicontrol(IK_p,'style','radiobutton',...
'String','No Flip',...
'callback',@flip_sign_func,...
'Position',[LD+40 BT-30 130 HT]);
%% D-H Parameters Table
% from The Development of a Genetic Programming Method for Kinematic Robot
% Calibration by Dolinsky Jens-Uwe.
BT = 195;
link_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','Link',...
'Position',[LD-92 BT 20 HT]); % L, B, W, H
link1_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','1',...
'Position',[LD-92 BT-30 20 HT]); % L, B, W, H
link2_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','2',...
'Position',[LD-92 BT-60 20 HT]); % L, B, W, H
link3_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','3',...
'Position',[LD-92 BT-90 20 HT]); % L, B, W, H
link4_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','4',...
'Position',[LD-92 BT-120 20 HT]); % L, B, W, H
link5_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','5',...
'Position',[LD-92 BT-150 20 HT]); % L, B, W, H
link6_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','6',...
'Position',[LD-92 BT-180 20 HT]); % L, B, W, H
Joint_txt = uibutton(DH_p,'style','text',...
'FontSize', 11, 'String','Joint Type',...
'Position',[LD-32 BT 20 HT]); % L, B, W, H
Joint1_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-30 20 HT]); % L, B, W, H
Joint2_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-60 20 HT]); % L, B, W, H
Joint3_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-90 20 HT]); % L, B, W, H
Joint4_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-120 20 HT]); % L, B, W, H
Joint5_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-150 20 HT]); % L, B, W, H
Joint6_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','Revolute',...
'Position',[LD-32 BT-180 20 HT]); % L, B, W, H
Theta_txt = uibutton(DH_p,'style','text',...
'FontSize', 12, 'String','\theta *',...
'FontWeight', 'bold',...
'Position',[LD+28.5 BT 20 HT]); % L, B, W, H
Th1_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-30 20 HT]); % L, B, W, H
Th2_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-60 20 HT]); % L, B, W, H
Th3_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-90 20 HT]); % L, B, W, H
Th4_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-120 20 HT]); % L, B, W, H
Th5_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-150 20 HT]); % L, B, W, H
Th6_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+28.5 BT-180 20 HT]); % L, B, W, H
d_txt = uibutton(DH_p,'style','text',...
'FontSize', 12, 'String','d',...
'Position',[LD+60 BT 20 HT]); % L, B, W, H
d1_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+60 BT-30 20 HT]); % L, B, W, H
d2_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','190',...
'Position',[LD+60 BT-60 20 HT]); % L, B, W, H
d3_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+60 BT-90 20 HT]); % L, B, W, H
d4_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','600',...
'Position',[LD+60 BT-120 20 HT]); % L, B, W, H
d5_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+60 BT-150 20 HT]); % L, B, W, H
d6_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','125',...
'Position',[LD+60 BT-180 20 HT]); % L, B, W, H
a_txt = uibutton(DH_p,'style','text',...
'FontSize', 12, 'String','a',...
'Position',[LD+92.5 BT 20 HT]); % L, B, W, H
a1_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+92.5 BT-30 20 HT]); % L, B, W, H
a2_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','650',...
'Position',[LD+92.5 BT-60 20 HT]); % L, B, W, H
a3_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+92.5 BT-90 20 HT]); % L, B, W, H
a4_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+92.5 BT-120 20 HT]); % L, B, W, H
a5_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+92.5 BT-150 20 HT]); % L, B, W, H
a6_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+92.5 BT-180 20 HT]); % L, B, W, H
alpha_txt = uibutton(DH_p,'style','text',...
'FontSize', 12, 'String','\alpha',...
'FontWeight', 'bold',...
'Position',[LD+125 BT 20 HT]); % L, B, W, H
alp1_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','-90',...
'Position',[LD+125 BT-30 20 HT]); % L, B, W, H
alp2_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+125 BT-60 20 HT]); % L, B, W, H
alp3_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','90',...
'Position',[LD+125 BT-90 20 HT]); % L, B, W, H
alp4_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','-90',...
'Position',[LD+125 BT-120 20 HT]); % L, B, W, H
alp5_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','90',...
'Position',[LD+125 BT-150 20 HT]); % L, B, W, H
alp6_txt = uibutton(DH_p,'style','text',...
'FontSize', 9, 'String','0',...
'Position',[LD+125 BT-180 20 HT]); % L, B, W, H
%% Tranformation matrix Table
nx_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','n_x=',...
'Position',[LD-75 BT-60 20 HT]); % L, B, W, H
ny_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','n_y=',...
'Position',[LD-75 BT-100 20 HT]); % L, B, W, H
nz_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','n_z=',...
'Position',[LD-75 BT-140 20 HT]); % L, B, W, H
lr1_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','0',...
'Position',[LD-75 BT-180 20 HT]); % L, B, W, H
ox_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','o_x= ',...
'Position',[LD BT-60 20 HT]); % L, B, W, H
oy_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','o_y= ',...
'Position',[LD BT-100 20 HT]); % L, B, W, H
oz_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','o_z= ',...
'Position',[LD BT-140 20 HT]); % L, B, W, H
lr2_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','0',...
'Position',[LD BT-180 20 HT]); % L, B, W, H
ax_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','a_x=',...
'Position',[LD+85 BT-60 20 HT]); % L, B, W, H
ay_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','a_y=',...
'Position',[LD+85 BT-100 20 HT]); % L, B, W, H
az_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','a_z=',...
'Position',[LD+85 BT-140 20 HT]); % L, B, W, H
lr3_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','0',...
'Position',[LD+85 BT-180 20 HT]); % L, B, W, H
px_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','p_x=',...
'Position',[LD+165 BT-60 20 HT]); % L, B, W, H
py_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','p_y=',...
'Position',[LD+165 BT-100 20 HT]); % L, B, W, H
pz_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','p_z= ',...
'Position',[LD+165 BT-140 20 HT]); % L, B, W, H
lr4_txt = uibutton(Tm_p,'style','text',...
'FontSize', 11, 'String','1',...
'Position',[LD+165 BT-180 20 HT]); % L, B, W, H
%% Slider for Theta 1 motion.
%
function t1_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t1_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t2old = T_Old(2); t3old = T_Old(3); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
pumaANI(slider_value+t1_home,t2old,t3old,t4old,t5old,t6old,10,'n')
end
%
%% Slider for Theta 2 motion.
function t2_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t2_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t1old = T_Old(1); t3old = T_Old(3); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
pumaANI(t1old,slider_value+t2_home,t3old,t4old,t5old,t6old,10,'n')
end
%
%% Slider for Theta 3 motion.
function t3_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t3_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t1old = T_Old(1); t2old = T_Old(2); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
pumaANI(t1old,t2old,slider_value+t3_home,t4old,t5old,t6old,10,'n')
end
%
%% Slider for Theta 4 motion.
function t4_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t4_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t5old = T_Old(5); t6old = T_Old(6);
pumaANI(t1old,t2old,t3old,slider_value,t5old,t6old,10,'n')
end
%
%% Slider for Theta 5 motion.
function t5_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t5_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t4old = T_Old(4); t6old = T_Old(6);
pumaANI(t1old,t2old,t3old,t4old,slider_value,t6old,10,'n')
end
%
%% Slider for Theta 6 motion.
function t6_slider_button_press(h,dummy)
slider_value = round(get(h,'Value'));
set(t6_edit,'string',slider_value);
T_Old = getappdata(0,'ThetaOld');
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t4old = T_Old(4); t5old = T_Old(5);
pumaANI(t1old,t2old,t3old,t4old,t5old,slider_value,10,'n')
end
%
%% Slider for Px motion.
%
function Px_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(Px_edit,'string',slider_value);
end
%
%% Slider for Py motion.
%
function Py_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(Py_edit,'string',slider_value);
end
%
%% Slider for Pz motion.
%
function Pz_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(Pz_edit,'string',slider_value);
end
%
%% Slider for R11 motion.
%
function R11_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R11_edit,'string',slider_value);
end
%
%% Slider for R21 motion.
%
function R21_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R21_edit,'string',slider_value);
end
%
%% Slider for R31 motion.
%
function R31_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R31_edit,'string',slider_value);
end
%
%% Slider for R13 motion.
%
function R13_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R13_edit,'string',slider_value);
end
%
%% Slider for R23 motion.
%
function R23_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R23_edit,'string',slider_value);
end
%
%% Slider for R33 motion.
%
function R33_slider_button_press(h,dummy)
slider_value = get(h,'Value');
set(R33_edit,'string',slider_value);
end
%
%% Edit box for Theta 1 motion.
%
function t1_edit_button_press(h,dummy)
user_entry = check_edit(h,-160,160,0,t1_edit);
set(t1_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t2old = T_Old(2); t3old = T_Old(3); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
%
pumaANI(user_entry+t1_home,t2old,t3old,t4old,t5old,t6old,10,'n')
end
%
%% Edit box for Theta 2 motion.
%
function t2_edit_button_press(h,dummy)
user_entry = check_edit(h,-110,110,0,t2_edit);
set(t2_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t1old = T_Old(1); t3old = T_Old(3); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
%
pumaANI(t1old,user_entry+t2_home,t3old,t4old,t5old,t6old,10,'n')
end
%% Edit box for Theta 3 motion.
%
function t3_edit_button_press(h,dummy)
user_entry = check_edit(h,-135,135,0,t3_edit);
set(t3_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t1old = T_Old(1); t2old = T_Old(2); t4old = T_Old(4);
t5old = T_Old(5); t6old = T_Old(6);
%
pumaANI(t1old,t2old,user_entry+t3_home,t4old,t5old,t6old,10,'n')
end
%% Edit box for Theta 4 motion.
%
function t4_edit_button_press(h,dummy)
user_entry = check_edit(h,-266,266,0,t4_edit);
set(t4_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t5old = T_Old(5); t6old = T_Old(6);
%
pumaANI(t1old,t2old,t3old,user_entry,t5old,t6old,10,'n')
end
%% Edit box for Theta 5 motion.
%
function t5_edit_button_press(h,dummy)
user_entry = check_edit(h,-100,100,0,t5_edit);
set(t5_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t4old = T_Old(4); t6old = T_Old(6);
%
pumaANI(t1old,t2old,t3old,t4old,user_entry,t6old,10,'n')
end
%% Edit box for Theta 6 motion.
%
function t6_edit_button_press(h,dummy)
user_entry = check_edit(h,-300,300,0,t6_edit);
disp (user_entry);
set(t6_slider,'Value',user_entry);
T_Old = getappdata(0,'ThetaOld'); % Current pose
%
t1old = T_Old(1); t2old = T_Old(2); t3old = T_Old(3);
t4old = T_Old(4); t5old = T_Old(5);
%
pumaANI(t1old,t2old,t3old,t4old,t5old,user_entry,10,'n')
end
%
%% Edit box for Px motion.
%
function Px_edit_button_press(h,dummy)
user_entry = check_edit(h,-1250,1250,0,Px_edit);
set(Px_slider,'Value',user_entry);
setappdata (0,'Pxold',user_entry);
end
%% Edit box for Py motion.
%
function Py_edit_button_press(h,dummy)
user_entry = check_edit(h,-1250,1250,0,Py_edit);
set(Py_slider,'Value',user_entry);
setappdata (0,'Pyold',user_entry);
end
%% Edit box for Pz motion.
%
function Pz_edit_button_press(h,dummy)
user_entry = check_edit(h,-1250,1250,0,Pz_edit);
set(Pz_slider,'Value',user_entry);
setappdata (0,'Pzold',user_entry);
end
%% Edit box for R11 motion.
%
function R11_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R11_edit);
set(R11_slider,'Value',user_entry);
setappdata (0,'R11old',user_entry);
end
%% Edit box for R21 motion.
%
function R21_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R21_edit);
set(R21_slider,'Value',user_entry);
setappdata (0,'R21old',user_entry);
end
%% Edit box for R31 motion.
%
function R31_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R31_edit);
set(R31_slider,'Value',user_entry);
setappdata (0,'R31old',user_entry);
end
%% Edit box for R13 motion.
%
function R13_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R13_edit);
set(R13_slider,'Value',user_entry);
setappdata (0,'R13old',user_entry);
end
%% Edit box for R23 motion.
%
function R23_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R23_edit);
set(R23_slider,'Value',user_entry);
setappdata (0,'R23old',user_entry);
end
%% Edit box for R33 motion.
%
function R33_edit_button_press(h,dummy)
user_entry = check_edit(h,-1200,1200,0,R33_edit);
set(R33_slider,'Value',user_entry);
setappdata (0,'R33old',user_entry);
end
%% UIControl funactions
function elbow_sign_func (h,dummy)
if get(Elbow_Sign_button,'Value')== 1
set(Elbow_Sign_button, 'String', 'Elbow Down'); % Change button's String
else
set(Elbow_Sign_button, 'String', 'Elbow Up'); % Change button's String
end
end
function flip_sign_func (h,dummy)
if get(Flip_Sign_button,'Value')== 1
set(Flip_Sign_button, 'String', 'Flip'); % Change button's String
else
set(Flip_Sign_button, 'String', 'No Flip'); % Change button's String
end
end
function user_entry = check_edit(h,min_v,max_v,default,h_edit)
% This function will check the value typed in the text input box
% against min and max values, and correct errors.
%
% h: handle of gui
% min_v min value to check
% max_v max value to check
% default is the default value if user enters non number
% h_edit is the edit value to update.
%
user_entry = str2double(get(h,'string'));
if isnan(user_entry)
errordlg(['You must enter a numeric value, defaulting to ',num2str(default),'.'],'Bad Input','modal')
set(h_edit,'string',default);
user_entry = default;
end
%
if user_entry < min_v
errordlg(['Minimum limit is ',num2str(min_v),' degrees, using ',num2str(min_v),'.'],'Bad Input','modal')
user_entry = min_v;
set(h_edit,'string',user_entry);
end
if user_entry > max_v
errordlg(['Maximum limit is ',num2str(max_v),' degrees, using ',num2str(max_v),'.'],'Bad Input','modal')
user_entry = max_v;
set(h_edit,'string',user_entry);
end
end
% Draw demo button's callback
function draw_demo_button_press(h,dummy)
clr_trail_button_press(h,dummy);
drawing = get (Drawing_pop, 'Value');
graphics=load('graphics', 'FI', 'DR', 'DU', 'PU', 'PP');
n = 2; % draw ani steps
num = 30; % home to start, and end to home ani steps
switch drawing
case 1, graf = graphics.FI;
case 2, graf = graphics.PU;
case 3, graf = graphics.DR;
case 4, graf = graphics.DU;
case 5, graf = graphics.PP;
otherwise, disp('something went wrong');
end
for i=1:size(graf,1)
Px = graf(i,1);
Pz = graf(i,2);
Py = graf(i,3);
[theta1,theta2,theta3,theta4,theta5,theta6] = PumaIK(Px,Py,Pz,0,0,0,0,0,0);
pumaANI(theta1,theta2,theta3-180,theta4,theta5,theta6,n,'y')
set(t1_edit,'string',round(theta1)); % Update slider and text.
set(t1_slider,'Value',round(theta1));
set(Th1_txt,'string',round(theta1));
set(t2_edit,'string',round(theta2));
set(t2_slider,'Value',round(theta2));
set(Th2_txt,'string',round(theta2));
set(t3_edit,'string',round(theta3-180));
set(t3_slider,'Value',round(theta3-180));
set(Th3_txt,'string',round(theta3-180));
set(t4_edit,'string',round(theta4));
set(t4_slider,'Value',round(theta4));
set(Th4_txt,'string',round(theta4));
set(t5_edit,'string',round(theta5));
set(t5_slider,'Value',round(theta5));
set(Th5_txt,'string',round(theta5));
set(t6_edit,'string',round(theta6));
set(t6_slider,'Value',round(theta6));
set(Th6_txt,'string',round(theta6));
end
gohome
end
function home_button_press(h,dummy)
%disp('pushed home bottom');
gohome
end
function clr_trail_button_press(h,dummy)
%disp('pushed clear trail bottom');
handles = getappdata(0,'patch_h'); %
Tr = handles(9);
%
setappdata(0,'xtrail',0); % used for trail tracking.
setappdata(0,'ytrail',0); % used for trail tracking.
setappdata(0,'ztrail',0); % used for trail tracking.
%
set(Tr,'xdata',0,'ydata',0,'zdata',0);
end
function rnd_demo_button_press(h, dummy)
%disp('pushed random demo bottom');
% a = 10; b = 50; x = a + (b-a) * rand(5)
% Angle Range Default Name
% Theta 1: 320 (-160 to 160) 90 Waist Joint
% Theta 2: 220 (-110 to 110) -90 Shoulder Joint
% Theta 3: 270 (-135 to 135) -90 Elbow Joint
% Theta 4: 532 (-266 to 266) 0 Wrist Roll
% Theta 5: 200 (-100 to 100) 0 Wrist Bend
% Theta 6: 600 (-300 to 300) 0 Wrist Swival
t1_home = 90; % offsets to define the "home" postition as UP.
t2_home = -90;
t3_home = -90;
theta1 = -160 + 320*rand(1); % offset for home
theta2 = -110 + 220*rand(1); % in the UP pos.
theta3 = -135 + 270*rand(1);
theta4 = -266 + 532*rand(1);
theta5 = -100 + 200*rand(1);
theta6 = -300 + 600*rand(1);
n = 50;
pumaANI(theta1+t1_home,theta2+t2_home,theta3+t3_home,theta4,theta5,theta6,n,'y')