-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrobotiq_preamble.py
1334 lines (1334 loc) · 45.8 KB
/
robotiq_preamble.py
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
NEW_LINE = "\n"
QUOTATION = "\""
ROBOTIQ_PREAMBLE = "\n".join([
"#aliases for the gripper variable names",
"ACT = 1",
"GTO = 2",
"ATR = 3",
"ARD = 4",
"FOR = 5",
"SPE = 6",
"OBJ = 7",
"STA = 8",
"FLT = 9",
"POS = 10",
"PRE = 11",
"LBP = 12",
"LRD = 13",
"LBL = 14",
"LGN = 15",
"MSC = 16",
"MOD = 17",
"",
"gripper_1_connected = False",
"gripper_2_connected = False",
"gripper_3_connected = False",
"gripper_4_connected = False",
"",
"gripper_1_socket_open = False",
"gripper_2_socket_open = False",
"gripper_3_socket_open = False",
"gripper_4_socket_open = False",
"",
"def rq_init_comm_if_connected(gripper_sid=9, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" if(not is_gripper_socket_open(gripper_socket)):",
" open_gripper_socket(gripper_socket)",
" end",
"",
" is_gripper_connected = rq_is_gripper_connected(gripper_sid, gripper_socket)",
" if(is_gripper_connected):",
" rq_set_gripper_connected(gripper_socket)",
" end",
"",
" return is_gripper_connected",
"end",
"",
"def open_gripper_socket(gripper_socket):",
" is_open = socket_open(" + QUOTATION + "127.0.0.1" + QUOTATION + ",63352, gripper_socket)",
" set_gripper_socket_open(gripper_socket, is_open)",
"end",
"",
"def is_gripper_socket_open(gripper_socket):",
" if(gripper_socket == " + QUOTATION + "1" + QUOTATION + "):",
" return gripper_1_socket_open",
" elif(gripper_socket == " + QUOTATION + "2" + QUOTATION + "):",
" return gripper_2_socket_open",
" elif(gripper_socket == " + QUOTATION + "3" + QUOTATION + "):",
" return gripper_3_socket_open",
" elif(gripper_socket == " + QUOTATION + "4" + QUOTATION + "):",
" return gripper_4_socket_open",
" else:",
" return False",
" end",
"end",
"",
"def set_gripper_socket_open(gripper_socket, is_open):",
" if(gripper_socket == " + QUOTATION + "1" + QUOTATION + "):",
" gripper_1_socket_open = is_open",
" elif(gripper_socket == " + QUOTATION + "2" + QUOTATION + "):",
" gripper_2_socket_open = is_open",
" elif(gripper_socket == " + QUOTATION + "3" + QUOTATION + "):",
" gripper_3_socket_open = is_open",
" elif(gripper_socket == " + QUOTATION + "4" + QUOTATION + "):",
" gripper_4_socket_open = is_open",
" else:",
" end",
"end",
"",
"def rq_is_gripper_connected(gripper_sid=9, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_set_var(" + QUOTATION + "SID" + QUOTATION + ", gripper_sid, gripper_socket)",
" ack = socket_read_byte_list(3, gripper_socket, 0.1)",
" return is_ack(ack)",
"end",
"",
"def rq_set_gripper_connected(gripper_id=" + QUOTATION + "1" + QUOTATION + "):",
" if(gripper_id == " + QUOTATION + "1" + QUOTATION + "):",
" gripper_1_connected = True",
" end",
"",
" if (gripper_id == " + QUOTATION + "2" + QUOTATION + "):",
" gripper_2_connected = True",
" end",
"",
" if (gripper_id == " + QUOTATION + "3" + QUOTATION + "):",
" gripper_3_connected = True",
" end",
"",
" if (gripper_id == " + QUOTATION + "4" + QUOTATION + "):",
" gripper_4_connected = True",
" end",
"end",
"",
"def rq_wait_for_gripper_connected():",
" gripper_socket = " + QUOTATION + "gripper_conn_socket" + QUOTATION + "",
" socket_open(" + QUOTATION + "127.0.0.1" + QUOTATION + ",63352, gripper_socket)",
"",
" retryCtr = 1",
" sid_list = rq_get_sid(gripper_socket)",
" gripper_is_connected = rq_is_any_gripper_connected(sid_list)",
"",
" while(not gripper_is_connected and retryCtr < 2000):",
" retryCtr = retryCtr + 1",
" sid_list = rq_get_sid(gripper_socket)",
" gripper_is_connected = rq_is_any_gripper_connected(sid_list)",
" end",
"",
" socket_close(gripper_socket)",
"end",
"",
"def rq_is_any_gripper_connected(sid_list):",
" is_gripper_1_connected = rq_is_gripper1_in_sid_list(sid_list)",
" is_gripper_2_connected = rq_is_gripper2_in_sid_list(sid_list)",
" is_gripper_3_connected = rq_is_gripper3_in_sid_list(sid_list)",
" is_gripper_4_connected = rq_is_gripper4_in_sid_list(sid_list)",
"",
" if(is_gripper_1_connected or is_gripper_2_connected or is_gripper_3_connected or is_gripper_4_connected):",
" return True",
" else:",
" return False",
" end",
"end",
"",
"def rq_is_gripper_in_sid_list(gripper_sid, sid_list):",
" sid_list_length = sid_list[0]",
" sid_list_empty_length = 2",
"",
" if (sid_list_length <= sid_list_empty_length):",
" return False",
" end",
"",
" sid1 = sid_list[2]",
" sid2 = sid_list[5]",
" sid3 = sid_list[8]",
" sid4 = sid_list[11]",
"",
" if(sid1 == gripper_sid or sid2 == gripper_sid or sid3 == gripper_sid or sid4 == gripper_sid):",
" return True",
" else:",
" return False",
" end",
"end",
"",
"def rq_is_gripper1_in_sid_list(sid_list):",
" gripper_1_sid_ascii = 57",
" return rq_is_gripper_in_sid_list(gripper_1_sid_ascii, sid_list)",
"end",
"",
"def rq_is_gripper2_in_sid_list(sid_list):",
" gripper_2_sid_ascii = 50",
" return rq_is_gripper_in_sid_list(gripper_2_sid_ascii, sid_list)",
"end",
"",
"def rq_is_gripper3_in_sid_list(sid_list):",
" gripper_3_sid_ascii = 51",
" return rq_is_gripper_in_sid_list(gripper_3_sid_ascii, sid_list)",
"end",
"",
"def rq_is_gripper4_in_sid_list(sid_list):",
" gripper_4_sid_ascii = 52",
" return rq_is_gripper_in_sid_list(gripper_4_sid_ascii, sid_list)",
"end",
"",
"def rq_set_sid(gripper_sid=9, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_set_var(" + QUOTATION + "SID" + QUOTATION + ", gripper_sid, gripper_socket)",
" sync()",
" ack = socket_read_byte_list(3, gripper_socket)",
" return is_ack(ack)",
"end",
"",
"def rq_get_sid(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET SID" + QUOTATION + ", gripper_socket)",
" sync()",
" sid_list = socket_read_byte_list(17, gripper_socket)",
" sync()",
" return sid_list",
"end",
"",
"def rq_activate(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_gripper_act = 0",
"",
" if (not rq_is_gripper_activated(gripper_socket)):",
" rq_reset(gripper_socket)",
"",
" while(socket_get_var(" + QUOTATION + "ACT" + QUOTATION + ",gripper_socket) == 1):",
" sleep(0.1)",
" rq_reset(gripper_socket)",
" end",
" end",
"",
" rq_set_var(ACT,1, gripper_socket)",
"end",
"",
"def rq_activate_and_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_activate(gripper_socket)",
" sleep(1.0)",
"",
" while(not rq_is_gripper_activated(gripper_socket)):",
" # wait for activation completed",
" end",
" sleep(0.5)",
"end",
"",
"def rq_activate_all_grippers(reset=False):",
" if(gripper_1_connected):",
" rq_reset_and_activate(" + QUOTATION + "1" + QUOTATION + ", reset)",
" end",
"",
" if(gripper_2_connected):",
" rq_reset_and_activate(" + QUOTATION + "2" + QUOTATION + ", reset)",
" end",
"",
" if(gripper_3_connected):",
" rq_reset_and_activate(" + QUOTATION + "3" + QUOTATION + ", reset)",
" end",
"",
" if(gripper_4_connected):",
" rq_reset_and_activate(" + QUOTATION + "4" + QUOTATION + ", reset)",
" end",
"",
" sleep(0.2)",
"end",
"",
"def rq_reset_and_activate(gripper_socket=" + QUOTATION + "1" + QUOTATION + ", reset=False):",
" if(reset):",
" rq_reset(gripper_socket)",
" sleep(0.5)",
" rq_activate_and_wait(gripper_socket)",
" elif(not rq_is_gripper_activated(gripper_socket)):",
" rq_activate_and_wait(gripper_socket)",
" end",
"end",
"",
"def rq_scan_block():",
" gripper_socket = " + QUOTATION + "scn_block_socket" + QUOTATION + "",
" socket_open(" + QUOTATION + "127.0.0.1" + QUOTATION + ", 63352, gripper_socket)",
" socket_set_var(" + QUOTATION + "SCN_BLOCK" + QUOTATION + ", 1, gripper_socket)",
" sync()",
" ack_test = socket_read_byte_list(3, gripper_socket)",
"",
" retry_counter = 0",
"",
" while(not is_ack(ack_test) and retry_counter < 5):",
" socket_set_var(" + QUOTATION + "SCN_BLOCK" + QUOTATION + ", 1, gripper_socket)",
" sync()",
" ack_test = socket_read_byte_list(3, gripper_socket)",
" retry_counter = retry_counter + 1",
" end",
"",
" socket_close(" + QUOTATION + "scn_block_socket" + QUOTATION + ")",
"end",
"",
"def rq_reset(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_gripper_act = 0",
" rq_obj_detect = 0",
" rq_mov_complete = 0",
"",
" rq_set_var(ACT,0, gripper_socket)",
" rq_set_var(ATR,0, gripper_socket)",
"end",
"",
"def rq_auto_release_open_and_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(ARD,0, gripper_socket)",
" rq_set_var(ACT,1, gripper_socket)",
" rq_set_var(ATR,0, gripper_socket)",
" sleep(0.1)",
" rq_set_var(ATR,1, gripper_socket)",
"",
" rq_wait_autorelease_completed(gripper_socket)",
"end",
"",
"def rq_auto_release_close_and_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(ARD,1, gripper_socket)",
" rq_set_var(ACT,1, gripper_socket)",
" rq_set_var(ATR,0, gripper_socket)",
" sleep(0.1)",
" rq_set_var(ATR,1, gripper_socket)",
"",
" rq_wait_autorelease_completed(gripper_socket)",
"end",
"",
"def rq_wait_autorelease_completed(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" retryCounter = 1",
" gFLT = rq_get_var(FLT, 2, gripper_socket)",
"",
" while(not is_FLT_autorelease_in_progress(gFLT) and retryCounter <= 20):",
" retryCounter = retryCounter + 1",
" gFLT = rq_get_var(FLT, 2, gripper_socket)",
" sleep(0.1)",
" end",
"",
" retryCounter = 1",
" gFLT = rq_get_var(FLT, 2, gripper_socket)",
"",
" while(not is_FLT_autorelease_completed(gFLT) and retryCounter <= 100):",
" retryCounter = retryCounter + 1",
" gFLT = rq_get_var(FLT, 2, gripper_socket)",
" sleep(0.1)",
" end",
"end",
"",
"def rq_set_force(force, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" force = floor(scale(force, [0, 255], [0,255]))",
" rq_set_var(FOR, force, gripper_socket)",
"end",
"",
"def rq_set_speed(speed, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" speed = floor(scale(speed, [0, 255], [0,255]))",
" rq_set_var(SPE, speed, gripper_socket)",
"end",
"",
"def rq_open(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_move(0, gripper_socket)",
"end",
"",
"def rq_close(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_move(255, gripper_socket)",
"end",
"",
"def rq_open_and_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_move_and_wait(0, gripper_socket)",
"end",
"",
"def rq_close_and_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_move_and_wait(255, gripper_socket)",
"end",
"",
"def rq_move(pos, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_mov_complete = 0",
" rq_obj_detect = 0",
"",
" rq_set_pos(pos, gripper_socket)",
" rq_go_to(gripper_socket)",
"end",
"",
"def rq_move_and_wait(pos, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_move(pos, gripper_socket)",
"",
" while (not rq_is_motion_complete(gripper_socket)):",
" # wait for motion completed",
" sleep(0.01)",
" sync()",
" end",
"",
" # following code used for compatibility with previous versions",
" rq_is_object_detected(gripper_socket)",
"",
" if (rq_obj_detect != 1):",
" rq_mov_complete = 1",
" end",
"end",
"",
"def rq_wait_for_pos_request(pos, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" gPRE = rq_get_var(PRE, 3, gripper_socket)",
" pre = (gPRE[1] - 48)*100 + (gPRE[2] -48)*10 + gPRE[3] - 48",
"",
" while (pre != pos):",
" rq_set_var(POS, pos, gripper_socket)",
" gPRE = rq_get_var(PRE, 3, gripper_socket)",
" pre = (gPRE[1] - 48)*100 + (gPRE[2] -48)*10 + gPRE[3] - 48",
" sync()",
" end",
"end",
"",
"def rq_wait_for_pos(pos, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_wait_for_pos_request(pos, gripper_socket)",
"",
" # Wait for the gripper motion to complete",
" while (not rq_is_motion_complete(gripper_socket)):",
" # wait for motion completed",
" sleep(0.01)",
" sync()",
" rq_go_to(gripper_socket)",
" end",
"",
" # following code used for compatibility with previous versions",
" rq_is_object_detected(gripper_socket)",
"",
" if (rq_obj_detect != 1):",
" rq_mov_complete = 1",
" end",
"end",
"",
"def rq_wait(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" # Wait for the gripper motion to complete",
" while (not rq_is_motion_complete(gripper_socket)):",
" # wait for motion completed",
" sleep(0.01)",
" sync()",
" end",
"",
" # following code used for compatibility with previous versions",
" rq_is_object_detected(gripper_socket)",
"",
" if (rq_obj_detect != 1):",
" rq_mov_complete = 1",
" end",
"end",
"",
"def rq_wait_for_object_detected(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" # Wait the object detection",
" while (not rq_is_object_detected(gripper_socket)):",
" # wait for motion completed",
" sleep(0.01)",
" sync()",
" end",
"end",
"",
"# set the position",
"def rq_set_pos(pos, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" pos = floor(scale(pos, [0, 255], [0, 255]))",
" rq_set_var(POS, pos, gripper_socket)",
" rq_wait_for_pos_request(pos, gripper_socket)",
"end",
"",
"# set the position, speed and force",
"def rq_set_pos_spd_for(pos, speed, force, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" enter_critical",
" rq_send_pos_spd_for(pos, speed, force, gripper_socket)",
" ack = socket_read_byte_list(3, gripper_socket)",
" exit_critical",
"",
" sync()",
"",
" while(is_not_ack(ack)):",
" enter_critical",
" rq_send_pos_spd_for(pos, speed, force, gripper_socket)",
" ack = socket_read_byte_list(3, gripper_socket)",
" exit_critical",
"",
" sync()",
" end",
"",
" rq_wait_for_pos_request(pos, gripper_socket)",
"end",
"",
"def rq_set_gripper_max_current_mA(current_mA, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" current = floor(current_mA / 10)",
" rq_set_var(MSC, current, gripper_socket)",
" sleep(1.5)",
"end",
"",
"def rq_set_gripper_mode(mode, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(MOD, mode, gripper_socket)",
"end",
"",
"def rq_set_gripper_max_cur(current_mA, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_gripper_max_current_mA(current_mA, gripper_socket)",
"end",
"",
"def rq_get_gripper_max_current_mA(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET MSC" + QUOTATION + ",gripper_socket)",
" sync()",
" var_value = socket_read_byte_list(3, gripper_socket)",
"",
" current = rq_list_of_bytes_to_value(var_value)",
"",
" if(current == -1):",
" current_mA = current",
" else:",
" current_mA = current * 10",
" end",
"",
" return current_mA",
"end",
"",
"def rq_get_gripper_max_cur(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" return rq_get_gripper_max_current_mA(gripper_socket)",
"end",
"",
"def rq_list_of_bytes_to_value(list_of_bytes):",
" value = -1",
"",
" # response list length",
" if (list_of_bytes[0] == 1):",
" value = list_of_bytes[1] - 48",
" elif (list_of_bytes[0] == 2):",
" value = (list_of_bytes[1] - 48) * 10 + (list_of_bytes[2] - 48)",
" elif (list_of_bytes[0] == 3):",
" value = (list_of_bytes[1] - 48) * 100 + (list_of_bytes[2] - 48) * 10 + (list_of_bytes[3] - 48)",
" end",
"",
" return value",
"end",
"",
"# send the position, speed and force",
"def rq_send_pos_spd_for(pos, speed, force, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" pos = floor(scale(pos, [0, 255], [0, 255]))",
" speed = floor(scale(speed, [0, 255], [0, 255]))",
" force = floor(scale(force, [0, 255], [0, 255]))",
"",
" socket_send_string(" + QUOTATION + "SET POS" + QUOTATION + ", gripper_socket)",
" socket_send_byte(32, gripper_socket)",
" socket_send_string(pos, gripper_socket)",
" socket_send_byte(32, gripper_socket)",
" socket_send_string(" + QUOTATION + "SPE" + QUOTATION + ", gripper_socket)",
" socket_send_byte(32, gripper_socket)",
" socket_send_string(speed, gripper_socket)",
" socket_send_byte(32, gripper_socket)",
" socket_send_string(" + QUOTATION + "FOR" + QUOTATION + ", gripper_socket)",
" socket_send_byte(32, gripper_socket)",
" socket_send_string(force, gripper_socket)",
" socket_send_byte(10, gripper_socket)",
"end",
"",
"def rq_is_motion_complete(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_mov_complete = 0",
"",
" gOBJ = rq_get_var(OBJ, 1, gripper_socket)",
" sleep(0.01)",
"",
" if (is_OBJ_gripper_at_position(gOBJ)):",
" rq_mov_complete = 1",
" return True",
" end",
"",
" if (is_OBJ_object_detected(gOBJ)):",
" rq_mov_complete = 1",
" return True",
" end",
"",
" return False",
"",
"end",
"",
"def rq_is_gripper_activated(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" gSTA = rq_get_var(STA, 1, gripper_socket)",
"",
" if(is_STA_gripper_activated(gSTA)):",
" rq_gripper_act = 1",
" return True",
" else:",
" rq_gripper_act = 0",
" return False",
" end",
"end",
"",
"def rq_is_object_detected(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" gOBJ = rq_get_var(OBJ, 1, gripper_socket)",
"",
" if(is_OBJ_object_detected(gOBJ)):",
" rq_obj_detect = 1",
" return True",
" else:",
" rq_obj_detect = 0",
" return False",
" end",
"end",
"",
"def rq_current_pos(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" enter_critical",
" rq_pos = socket_get_var(" + QUOTATION + "POS" + QUOTATION + ",gripper_socket)",
" exit_critical",
" sync()",
" return rq_pos",
"end",
"",
"def rq_motor_current(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" enter_critical",
" rq_current = socket_get_var(" + QUOTATION + "COU" + QUOTATION + ",gripper_socket)",
" exit_critical",
" sync()",
" return rq_current * 10",
"end",
"",
"def rq_print_connected_grippers():",
" if(gripper_1_connected):",
" textmsg(" + QUOTATION + "Gripper 1 : " + QUOTATION + ", " + QUOTATION + "connected and socket open." + QUOTATION + ")",
" end",
"",
" if (gripper_2_connected):",
" textmsg(" + QUOTATION + "Gripper 2 : " + QUOTATION + ", " + QUOTATION + "connected and socket open." + QUOTATION + ")",
" end",
"",
" if (gripper_3_connected):",
" textmsg(" + QUOTATION + "Gripper 3 : " + QUOTATION + ", " + QUOTATION + "connected and socket open." + QUOTATION + ")",
" end",
"",
" if (gripper_4_connected):",
" textmsg(" + QUOTATION + "Gripper 4 : " + QUOTATION + ", " + QUOTATION + "connected and socket open." + QUOTATION + ")",
" end",
"end",
"",
"def rq_print_gripper_fault_code(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" gFLT = rq_get_var(FLT, 2, gripper_socket)",
"",
" if(is_FLT_no_fault(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "No Fault (0x00)" + QUOTATION + ")",
" elif (is_FLT_action_delayed(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Priority Fault: Action delayed, initialization must be completed prior to action (0x05)" + QUOTATION + ")",
" elif (is_FLT_not_activated(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Priority Fault: The activation must be set prior to action (0x07)" + QUOTATION + ")",
" elif (is_FLT_autorelease_in_progress(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Minor Fault: Automatic release in progress (0x0B)" + QUOTATION + ")",
" elif (is_FLT_overcurrent(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Minor Fault: Overcurrent protection triggered (0x0E)" + QUOTATION + ")",
" elif (is_FLT_autorelease_completed(gFLT)):",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Major Fault: Automatic release completed (0x0F)" + QUOTATION + ")",
" else:",
" textmsg(" + QUOTATION + "Gripper Fault : " + QUOTATION + ", " + QUOTATION + "Unknown Fault" + QUOTATION + ")",
" end",
"end",
"",
"def rq_print_gripper_num_cycles(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET NCY" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
"",
" if(string_from_server == " + QUOTATION + "0" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Cycle Number : " + QUOTATION + ", " + QUOTATION + "Number of cycles is unreachable." + QUOTATION + ")",
" else:",
" textmsg(" + QUOTATION + "Gripper Cycle Number : " + QUOTATION + ", string_from_server)",
" end",
"end",
"",
"def rq_print_gripper_driver_state(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET DST" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
"",
" if(string_from_server == " + QUOTATION + "0" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Driver State : " + QUOTATION + ", " + QUOTATION + "RQ_STATE_INIT" + QUOTATION + ")",
" elif(string_from_server == " + QUOTATION + "1" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Driver State : " + QUOTATION + ", " + QUOTATION + "RQ_STATE_LISTEN" + QUOTATION + ")",
" elif(string_from_server == " + QUOTATION + "2" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Driver State : " + QUOTATION + ", " + QUOTATION + "RQ_STATE_READ_INFO" + QUOTATION + ")",
" elif(string_from_server == " + QUOTATION + "3" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Driver State : " + QUOTATION + ", " + QUOTATION + "RQ_STATE_ACTIVATION" + QUOTATION + ")",
" else:",
" textmsg(" + QUOTATION + "Gripper Driver State : " + QUOTATION + ", " + QUOTATION + "RQ_STATE_RUN" + QUOTATION + ")",
" end",
"end",
"",
"def rq_print_gripper_serial_number(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET SNU" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
" textmsg(" + QUOTATION + "Gripper Serial Number : " + QUOTATION + ", string_from_server)",
"end",
"",
"def rq_print_gripper_firmware_version(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET FWV" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
" textmsg(" + QUOTATION + "Gripper Firmware Version : " + QUOTATION + ", string_from_server)",
"end",
"",
"def rq_print_gripper_driver_version(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET VER" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
" textmsg(" + QUOTATION + "Gripper Driver Version : " + QUOTATION + ", string_from_server)",
"end",
"",
"def rq_print_gripper_probleme_connection(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" socket_send_string(" + QUOTATION + "GET PCO" + QUOTATION + ",gripper_socket)",
" sync()",
" string_from_server = socket_read_string(gripper_socket)",
" sync()",
" if (string_from_server == " + QUOTATION + "0" + QUOTATION + "):",
" textmsg(" + QUOTATION + "Gripper Connection State : " + QUOTATION + ", " + QUOTATION + "No connection problem detected" + QUOTATION + ")",
" else:",
" textmsg(" + QUOTATION + "Gripper Connection State : " + QUOTATION + ", " + QUOTATION + "Connection problem detected" + QUOTATION + ")",
" end",
"end",
"",
"# Returns True if list_of_bytes is [3, 'a', 'c', 'k']",
"def is_ack(list_of_bytes):",
"",
" # list length is not 3",
" if (list_of_bytes[0] != 3):",
" return False",
" end",
"",
" # first byte not is 'a'?",
" if (list_of_bytes[1] != 97):",
" return False",
" end",
"",
" # first byte not is 'c'?",
" if (list_of_bytes[2] != 99):",
" return False",
" end",
"",
" # first byte not is 'k'?",
" if (list_of_bytes[3] != 107):",
" return False",
" end",
"",
" return True",
"end",
"",
"# Returns True if list_of_bytes is not [3, 'a', 'c', 'k']",
"def is_not_ack(list_of_bytes):",
" if (is_ack(list_of_bytes)):",
" return False",
" else:",
" return True",
" end",
"end",
"",
"def is_STA_gripper_activated (list_of_bytes):",
"",
" # list length is not 1",
" if (list_of_bytes[0] != 1):",
" return False",
" end",
"",
" # byte is '3'?",
" if (list_of_bytes[1] == 51):",
" return True",
" end",
"",
" return False",
"end",
"",
"# Returns True if list_of_byte is [1, '1'] or [1, '2']",
"# Used to test OBJ = 0x1 or OBJ = 0x2",
"def is_OBJ_object_detected (list_of_bytes):",
"",
" # list length is not 1",
" if (list_of_bytes[0] != 1):",
" return False",
" end",
"",
" # byte is '2'?",
" if (list_of_bytes[1] == 50):",
" return True",
" end",
"",
" # byte is '1'?",
" if (list_of_bytes[1] == 49):",
" return True",
" end",
"",
" return False",
"",
"end",
"",
"# Returns True if list_of_byte is [1, '3']",
"# Used to test OBJ = 0x3",
"def is_OBJ_gripper_at_position (list_of_bytes):",
"",
" # list length is not 1",
" if (list_of_bytes[0] != 1):",
" return False",
" end",
"",
" # byte is '3'?",
" if (list_of_bytes[1] == 51):",
" return True",
" end",
"",
" return False",
"end",
"",
"def is_not_OBJ_gripper_at_position (list_of_bytes):",
"",
" if (is_OBJ_gripper_at_position(list_of_bytes)):",
" return False",
" else:",
" return True",
" end",
"end",
"",
"#### GTO Section ####",
"def rq_stop(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(GTO, 0, gripper_socket)",
"end",
"",
"def rq_set_GTO_and_wait(value, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(GTO ,value, gripper_socket)",
" while(not is_GTO(value, rq_get_var(GTO, 1, gripper_socket))):",
" sync()",
" end",
"end",
"",
"def rq_go_to(gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" rq_set_var(GTO, 1, gripper_socket)",
"end",
"",
"",
"def is_GTO(goto_value, list_of_bytes):",
" zero_ascii = 48",
" if (list_of_bytes[0] != 1):",
" return False",
" end",
"",
" if (list_of_bytes[1] == zero_ascii + goto_value):",
" return True",
" else:",
" return False",
" end",
"end",
"#### GTO Section ####",
"",
"def is_FLT_no_fault(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '0'?",
" if (list_of_bytes[1] != 48):",
" return False",
" end",
"",
" # second byte is '0'?",
" if (list_of_bytes[2] != 48):",
" return False",
" end",
"",
" return True",
"",
"end",
"",
"def is_FLT_action_delayed(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '0'?",
" if (list_of_bytes[1] != 48):",
" return False",
" end",
"",
" # second byte is '5'?",
" if (list_of_bytes[2] != 53):",
" return False",
" end",
"",
" return True",
"end",
"",
"def is_FLT_not_activated(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '0'?",
" if (list_of_bytes[1] != 48):",
" return False",
" end",
"",
" # second byte is '7'?",
" if (list_of_bytes[2] != 55):",
" return False",
" end",
"",
" return True",
"end",
"",
"def is_FLT_autorelease_in_progress(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '1'?",
" if (list_of_bytes[1] != 49):",
" return False",
" end",
"",
" # second byte is '1'?",
" if (list_of_bytes[2] != 49):",
" return False",
" end",
"",
" return True",
"",
"end",
"",
"def is_FLT_overcurrent(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '1'?",
" if (list_of_bytes[1] != 49):",
" return False",
" end",
"",
" # second byte is '4'?",
" if (list_of_bytes[2] != 52):",
" return False",
" end",
"",
" return True",
"",
"end",
"",
"def is_FLT_autorelease_completed(list_of_bytes):",
"",
" # list length is not 2",
" if (list_of_bytes[0] != 2):",
" return False",
" end",
"",
" # first byte is '1'?",
" if (list_of_bytes[1] != 49):",
" return False",
" end",
"",
" # second byte is '5'?",
" if (list_of_bytes[2] != 53):",
" return False",
" end",
"",
" return True",
"",
"end",
"",
"def rq_set_var(var_name, var_value, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
"",
" var_name_string = " + QUOTATION + "" + QUOTATION + "",
"",
" if (var_name == ACT):",
" var_name_string = " + QUOTATION + "ACT" + QUOTATION + "",
" elif (var_name == GTO):",
" var_name_string = " + QUOTATION + "GTO" + QUOTATION + "",
" elif (var_name == ATR):",
" var_name_string = " + QUOTATION + "ATR" + QUOTATION + "",
" elif (var_name == ARD):",
" var_name_string = " + QUOTATION + "ARD" + QUOTATION + "",
" elif (var_name == FOR):",
" var_name_string = " + QUOTATION + "FOR" + QUOTATION + "",
" elif (var_name == SPE):",
" var_name_string = " + QUOTATION + "SPE" + QUOTATION + "",
" elif (var_name == POS):",
" var_name_string = " + QUOTATION + "POS" + QUOTATION + "",
" elif (var_name == LBP):",
" var_name_string = " + QUOTATION + "LBP" + QUOTATION + "",
" elif (var_name == LRD):",
" var_name_string = " + QUOTATION + "LRD" + QUOTATION + "",
" elif (var_name == LBL):",
" var_name_string = " + QUOTATION + "LBL" + QUOTATION + "",
" elif (var_name == LGN):",
" var_name_string = " + QUOTATION + "LGN" + QUOTATION + "",
" elif (var_name == MSC):",
" var_name_string = " + QUOTATION + "MSC" + QUOTATION + "",
" elif (var_name == MOD):",
" var_name_string = " + QUOTATION + "MOD" + QUOTATION + "",
" end",
"",
" enter_critical",
" socket_set_var(var_name_string, var_value, gripper_socket)",
" ack = socket_read_byte_list(3, gripper_socket)",
" exit_critical",
"",
" sync()",
"",
" while(is_not_ack(ack)):",
" enter_critical",
" socket_set_var(var_name_string , var_value, gripper_socket)",
" sync()",
" ack = socket_read_byte_list(3, gripper_socket)",
" exit_critical",
"",
" sync()",
" end",
"end",
"",
"",
"def rq_get_var(var_name, nbr_bytes, gripper_socket=" + QUOTATION + "1" + QUOTATION + "):",
" enter_critical",
"",
" if (var_name == FLT):",
" socket_send_string(" + QUOTATION + "GET FLT" + QUOTATION + ", gripper_socket)",
" elif (var_name == OBJ):",
" socket_send_string(" + QUOTATION + "GET OBJ" + QUOTATION + ", gripper_socket)",
" elif (var_name == STA):",
" socket_send_string(" + QUOTATION + "GET STA" + QUOTATION + ", gripper_socket)",
" elif (var_name == PRE):",
" socket_send_string(" + QUOTATION + "GET PRE" + QUOTATION + ", gripper_socket)",
" elif (var_name == GTO):",
" socket_send_string(" + QUOTATION + "GET GTO" + QUOTATION + ", gripper_socket)",
" else:",
" end",
"",