JAKABean-Functions.cs
33.4 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
using System.Text;
using System.Windows.Forms;
namespace JAKA
{
public partial class JAKABean
{
/// <summary>
/// 创建机器人控制句柄
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
bool CreateHandler(string ip)
{
//int rtn = jakaAPI.create_handler(ip.ToCharArray(),ref _handle);
//if (rtn == RtnCode.ERR_SUCC)
//{
// InfoLog($"CreateHandler OK");
// SetErrorHandler();
// SetErrorCodeFilePath(Application.StartupPath+ @"\jaka_files\JAKA_ERROR_CODE.csv");
//SetStatusDataUpdateTimeInterval(100);
// return true;
//}
//else
//{
// ErrorLog($"CreateHandler Fail:{RtnCode.GetStrByCode(rtn)}");
//}
return false;
}
/// <summary>
/// 注册机器人出错时的回调函数
/// </summary>
/// <returns></returns>
bool SetErrorHandler()
{
int rtn = jakaAPI.set_error_handler(ref _handle, user_error_handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"SetErrorHandler OK");
return true;
}
else
{
ErrorLog($"SetErrorHandler Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 销毁机器人控制句柄
/// </summary>
/// <returns></returns>
bool DestroyHandler()
{
int rtn = jakaAPI.destory_handler(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"DestroyHandler OK");
return true;
}
else
{
ErrorLog($"DestroyHandler Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人上电
/// </summary>
public bool PowerOn()
{
int rtn = jakaAPI.power_on(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"PowerOn OK");
return true;
}
else
{
ErrorLog($"PowerOn Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人下电
/// </summary>
public bool PowerOff()
{
int rtn = jakaAPI.power_off(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"PowerOff OK");
return true;
}
else
{
ErrorLog($"PowerOff Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关机
/// </summary>
public bool ShutDown()
{
int rtn = jakaAPI.shut_down(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"ShutDown OK");
return true;
}
else
{
ErrorLog($"ShutDown Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人上使能
/// </summary>
public bool EnableRobot()
{
int rtn = jakaAPI.enable_robot(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"EnableRobot OK");
return true;
}
else
{
ErrorLog($"EnableRobot Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人下使能
/// </summary>
public bool DisableRobot()
{
int rtn = jakaAPI.disable_robot(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"DisableRobot OK");
return true;
}
else
{
ErrorLog($"DisableRobot Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人手动模式下运动
/// </summary>
/// <param name="aj_num">关节空间下代表关节号[0-5],笛卡尔下依次为轴 x,y,z,rx,ry,rz</param>
/// <param name="move_mode">机器人运动模式,增量运动或者绝对运动(即持续 jog 运动)</param>
/// <param name="coordType">机器人运动坐标系,工具坐标系,基坐标系(当前的世界/用户坐标系)或关节空间</param>
/// <param name="vel_cmd">指令速度,旋转轴或关节运动单位为 rad/s,移动轴单位为 mm/</param>
/// <param name="pos_cmd">指令位置,旋转轴或关节运动单位为 rad,移动轴单位为 m</param>
/// <returns></returns>
bool Jog(int aj_num,JKTYPE.MoveMode move_mode,JKTYPE.CoordType coordType,double vel_cmd,double pos_cmd)
{
int rtn = jakaAPI.jog(ref _handle,aj_num,move_mode,coordType,vel_cmd,pos_cmd);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"Jog OK");
return true;
}
else
{
ErrorLog($"Jog Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人手动模式下运动停止
/// </summary>
/// <param name="num">机械臂轴号 0-5,num为-1时,停止所有轴 </param>
/// <returns></returns>
public bool JogStop(int num=-1)
{
int rtn = jakaAPI.jog_stop(ref _handle,ref num);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"JogStop OK");
return true;
}
else
{
ErrorLog($"JogStop Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关节运动
/// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人关节运动速度,单位:rad/s</param>
/// <returns></returns>
bool JointMove(JKTYPE.JointValue jointPos,JKTYPE.MoveMode moveMode,bool isBlock,double speed)
{
int rtn = jakaAPI.joint_move(ref _handle,ref jointPos,moveMode,isBlock,speed);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"JointMove OK");
return true;
}
else
{
ErrorLog($"JointMove Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人末端直线运动
/// </summary>
/// <param name="endPos">机器人末端运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人直线运动速度,单位:mm/s</param>
/// <returns></returns>
bool LinaerMove(JKTYPE.CartesianPose endPos, JKTYPE.MoveMode moveMode, bool isBlock, double speed)
{
int rtn = jakaAPI.linear_move(ref _handle, ref endPos, moveMode, isBlock, speed);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"LinaerMove OK");
return true;
}
else
{
ErrorLog($"LinaerMove Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人伺服位置控制模式使能
/// </summary>
/// <param name="enable">TRUE 为进入伺服位置控制模式,FALSE 表示退出该模式</param>
/// <returns></returns>
public bool ServoMoveEnable(bool enable)
{
int rtn = jakaAPI.servo_move_enable(ref _handle,enable);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoMoveEnable OK");
return true;
}
else
{
ErrorLog($"ServoMoveEnable Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关节空间伺服模式运动
/// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:绝对运动或相对运动</param>
/// <returns></returns>
bool ServoJ(JKTYPE.JointValue jointPos,JKTYPE.MoveMode moveMode)
{
int rtn = jakaAPI.servo_j(ref _handle,ref jointPos,moveMode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoJ OK");
return true;
}
else
{
ErrorLog($"ServoJ Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关节空间伺服模式运动扩展
/// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_j 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns>
bool ServoJExtend(JKTYPE.JointValue jointPos, JKTYPE.MoveMode moveMode,int stepNum)
{
int rtn = jakaAPI.servo_j_extend(ref _handle, ref jointPos, moveMode,stepNum);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoJExtend OK");
return true;
}
else
{
ErrorLog($"ServoJExtend Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人笛卡尔空间伺服模式运动
/// </summary>
/// <param name="cartesianPose">机器人笛卡尔空间运动目标位置</param>
/// <param name="moveMode">指定运动模式:ABS 代表绝对运动,INCR 代表相对运动</param>
/// <returns></returns>
bool ServoP(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode)
{
int rtn = jakaAPI.servo_p(ref _handle, ref cartesianPose, moveMode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoP OK");
return true;
}
else
{
ErrorLog($"ServoP Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人笛卡尔空间伺服模式运动扩展
/// </summary>
/// <param name="jointPos">机器人笛卡尔空间运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_p 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns>
bool ServoPExtend(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode, int stepNum)
{
int rtn = jakaAPI.servo_p_extend(ref _handle, ref cartesianPose, moveMode, stepNum);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoPExtend OK");
return true;
}
else
{
ErrorLog($"ServoPExtend Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置数字输出变量
/// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns>
bool SetDigitalOutput(JKTYPE.IOType iOType,int index,bool value)
{
int rtn = jakaAPI.set_digital_output(ref _handle, iOType, index,value);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetDigitalOutput [{iOType}][{index}={value}] OK");
return true;
}
else
{
ErrorLog($"SetDigitalOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置模拟输出变量
/// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns>
bool SetAnalogOutput(JKTYPE.IOType iOType, int index, float value)
{
int rtn = jakaAPI.set_analog_output(ref _handle, iOType, index, value);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetAnalogOutput [{iOType}][{index}={value}] OK");
return true;
}
else
{
ErrorLog($"SetAnalogOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询数字输入状态
/// </summary>
/// <param name="iOType"> DI 类型</param>
/// <param name="index">DI 索引(从 0 开始)</param>
/// <param name="value">DI 状态查询结果</param>
/// <returns></returns>
public bool GetDigitalInput(JKTYPE.IOType iOType, int index,out bool result)
{
result = false;
int rtn = jakaAPI.get_digital_input(ref _handle, iOType, index,ref result);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetDigitalInput [{iOType}][{index}={result}] OK");
return true;
}
else
{
ErrorLog($"GetDigitalInput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询数字输出状态
/// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 状态查询结果</param>
/// <returns></returns>
public bool GetDigitalOutput(JKTYPE.IOType iOType, int index, out bool result)
{
result = false;
int rtn = jakaAPI.get_digital_output(ref _handle, iOType, index, ref result);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetDigitalOutput [{iOType}][{index}={result}] OK");
return true;
}
else
{
ErrorLog($"GetDigitalOutput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 运行当前加载的作业程序
/// </summary>
public bool Run()
{
int rtn = jakaAPI.program_run(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Run OK");
return false;
}
else
{
ErrorLog($"Run Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 暂停当前运行的作业程序
/// </summary>
public bool Pause()
{
int rtn = jakaAPI.program_pause(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Pause OK");
return false;
}
else
{
ErrorLog($"Pause Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 继续运行当前暂停的作业程序
/// </summary>
public bool Resume()
{
int rtn = jakaAPI.program_resume(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Resume OK");
return false;
}
else
{
ErrorLog($"Resume Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 终止当前执行的作业程序
/// </summary>
public bool Abort()
{
int rtn = jakaAPI.program_abort(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Abort OK");
return true;
}
else
{
ErrorLog($"Abort Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 加载指定的作业程序
/// </summary>
/// <param name="file">加载指定的作业程序 (加载轨迹复现数据,轨迹复现数据的加载需要在文件夹名字前加上 track/)</param>
/// <returns></returns>
public bool Load(string file)
{
int rtn = jakaAPI.program_load(ref _handle,file.ToCharArray());
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Load OK");
return true;
}
else
{
ErrorLog($"Load Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取已加载的作业程序的名字
/// </summary>
/// <param name="file">程序文件路径</param>
/// <returns></returns>
public bool GetLoadedProgram(StringBuilder file)
{
int rtn = jakaAPI.get_loaded_program(ref _handle,file);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetLoadedProgram OK");
return true;
}
else
{
ErrorLog($"GetLoadedProgram Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人作业程序的执行状态
/// </summary>
/// <param name="status">作业程序执行状态查询结果</param>
/// <returns></returns>
public bool GetProgramState(out JKTYPE.ProgramState status)
{
status = new JKTYPE.ProgramState();
int rtn = jakaAPI.get_program_state(ref _handle,ref status);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetProgramState OK");
return false;
}
else
{
ErrorLog($"GetProgramState Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置机器人运行倍率
/// </summary>
/// <param name="rate"></param>
public bool SetRapidRate(double rate)
{
int rtn = jakaAPI.set_rapidrate(ref _handle, rate);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetRapidRate {rate} OK");
return true;
}
else
{
ErrorLog($"SetRapidRate {rate} Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人运行倍率
/// </summary>
/// <param name="rate"></param>
public bool GetRapidRate(out double rate)
{
rate = 0;
int rtn = jakaAPI.get_rapidrate(ref _handle,ref rate);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetRapidRate OK");
return true;
}
else
{
ErrorLog($"GetRapidRate Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 控制机器人进入或退出拖拽模式
/// </summary>
/// <param name="enable"></param>
/// <returns></returns>
public bool DragModeEnable(bool enable)
{
int rtn = jakaAPI.drag_mode_enable(ref _handle, enable);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"DragModeEnable OK");
return true;
}
else
{
ErrorLog($"DragModeEnable Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询机器人是否处于拖拽模式
/// </summary>
/// <returns></returns>
public bool IsInDragMode(out bool inDrag)
{
inDrag = false;
int rtn = jakaAPI.is_in_drag_mode(ref _handle,ref inDrag);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"IsInDragMode OK");
return true;
}
else
{
ErrorLog($"IsInDragMode Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人状态:急停,电源,使能
/// </summary>
public bool GetRobotState(out JKTYPE.RobotState robotState)
{
robotState = new JKTYPE.RobotState();
int rtn = jakaAPI.get_robot_state(ref _handle, ref robotState);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetRobotState OK");
return true;
}
else
{
ErrorLog($"GetRobotState Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询机器人是否处于碰撞保护模式
/// </summary>
/// <returns></returns>
public bool IsInCollision(out bool inCollision)
{
inCollision = false;
int rtn = jakaAPI.is_in_collision(ref _handle, ref inCollision);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"IsInCollision OK");
return true;
}
else
{
ErrorLog($"IsInCollision Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询机器人是否超出限位
/// </summary>
/// <returns></returns>
public bool IsOnLimit(out bool onlimit)
{
onlimit = false;
int rtn = jakaAPI.is_on_limit(ref _handle, ref onlimit);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"IsOnLimit OK");
return true;
}
else
{
ErrorLog($"IsOnLimit Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询机器人运动是否停止/到位
/// </summary>
/// <returns></returns>
public bool IsInPos(out bool inPos)
{
inPos = false;
int rtn = jakaAPI.is_in_pos(ref _handle, ref inPos);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"IsInPos OK");
return true;
}
else
{
ErrorLog($"IsInPos Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 碰撞之后从碰撞保护模式恢复
/// </summary>
/// <returns></returns>
public bool CollisionRecover()
{
int rtn = jakaAPI.collision_recover(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"CollisionRecover OK");
return true;
}
else
{
ErrorLog($"CollisionRecover Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置机器人碰撞等级
/// </summary>
/// <param name="level">碰撞等级,取值范围[0,5] ,
/// 其中 0 为关闭碰撞,1 为碰撞阈值 25N,2 为碰撞阈值 50N,
/// 3为碰撞阈值 75N,4 为碰撞阈值 100N,5 为碰撞阈值 125N</param>
/// <returns></returns>
public bool SetCollisionLevel(int level)
{
int rtn = jakaAPI.set_collision_level(ref _handle,level);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetCollisionLevel OK");
return true;
}
else
{
ErrorLog($"SetCollisionLevel Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器设置的碰撞等级
/// </summary>
/// <param name="level"></param>
/// <returns></returns>
public bool GetCollisionLevel(out int level)
{
level = 0;
int rtn = jakaAPI.get_collision_level(ref _handle,ref level);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetCollisionLevel OK");
return true;
}
else
{
ErrorLog($"GetCollisionLevel Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人负载设置
/// </summary>
/// <param name="payload"></param>
/// <returns></returns>
public bool SetPayload(JKTYPE.PayLoad payload)
{
int rtn = jakaAPI.set_payload(ref _handle,ref payload);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetPayload OK");
return true;
}
else
{
ErrorLog($"SetPayload Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人负载数据
/// </summary>
/// <param name="payload"></param>
/// <returns></returns>
public bool GetPayload(out JKTYPE.PayLoad payload)
{
payload = new JKTYPE.PayLoad();
int rtn = jakaAPI.get_payload(ref _handle, ref payload);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetPayload OK");
return true;
}
else
{
ErrorLog($"GetPayload Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取SDK版本号
/// </summary>
/// <param name="version"></param>
/// <returns></returns>
public bool GetSDKVersion(StringBuilder version)
{
int rtn = jakaAPI.get_sdk_version(ref _handle,version);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetSDKVersion OK");
return true;
}
else
{
ErrorLog($"GetSDKVersion Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人状态监测数据
/// </summary>
/// <param name="robotStatus"></param>
/// <returns></returns>
public bool GetRobotStatus(out JKTYPE.RobotStatus robotStatus)
{
robotStatus = new JKTYPE.RobotStatus();
int rtn = jakaAPI.get_robot_status(ref _handle,ref robotStatus);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetRobotDtatus OK");
return true;
}
else
{
ErrorLog($"GetRobotDtatus Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置 SDK 是否开启调试模式
/// </summary>
/// <param name="mode"></param>
/// <returns></returns>
public bool SetDebugMode(bool mode)
{
int rtn = jakaAPI.set_debug_mode(ref _handle,mode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetDebugMode OK");
return true;
}
else
{
ErrorLog($"SetDebugMode Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人运动终止
/// </summary>
/// <returns></returns>
public bool MotionAbort()
{
int rtn = jakaAPI.motion_abort(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"MotionAbort OK");
return true;
}
else
{
ErrorLog($"MotionAbort Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置机器人错误码文件存放路径,
/// 需要使用 get_last_error 接口时需要设置错误码文件路径,如果不使用
///get_last_error 接口,则不需要设置该接口
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
bool SetErrorCodeFilePath(string path)
{
StringBuilder sb = new StringBuilder(path);
int rtn = jakaAPI.set_errorcode_file_path(ref _handle,sb);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetErrorCodeFilePath OK");
return true;
}
else
{
ErrorLog($"SetErrorCodeFilePath Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 获取机器人运行过程中最后一个错误码,当调用 clear_error 时,最后一个错误码会清零
/// </summary>
/// <param name="errorCode"></param>
/// <returns></returns>
public bool GetLastError(ref JKTYPE.ErrorCode errorCode)
{
int rtn = jakaAPI.get_last_error(ref _handle,ref errorCode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetLastError OK");
return true;
}
else
{
ErrorLog($"GetLastError Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 清除错误,最后一个错误码会清零
/// </summary>
/// <returns></returns>
public bool ClearError()
{
int rtn = jakaAPI.clear_error(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"ClearError OK");
return true;
}
else
{
ErrorLog($"ClearError Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置 SDK 日志路径
/// </summary>
/// <param name="filepath">SDK 日志路径</param>
/// <returns></returns>
public bool SetSDKFilePath(string filepath)
{
char[] chars = filepath.ToCharArray();
int rtn = jakaAPI.set_SDK_filepath(ref _handle, ref chars);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetSDKFilePath OK");
return true;
}
else
{
ErrorLog($"SetSDKFilePath Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置网络异常,机器人终止运动等待时间
/// </summary>
/// <param name="ms">时间参数,单位毫秒</param>
/// <param name="mnt">网络异常时机器人需要进行的动作类型</param>
/// <returns></returns>
public bool SetNetworkExceptionHandle(float ms,JKTYPE.ProcessType mnt)
{
int rtn = jakaAPI.set_network_exception_handle(ref _handle,ms,mnt);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetNetworkExceptionHandle OK");
return true;
}
else
{
ErrorLog($"SetNetworkExceptionHandle Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置机器人状态数据自动更新时间间隔
/// </summary>
/// <param name="ms"> 时间参数,单位毫秒</param>
/// <returns></returns>
public bool SetStatusDataUpdateTimeInterval(float ms)
{
int rtn = jakaAPI.set_status_data_update_time_interval(ref _handle, ms);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetStatusDataUpdateTimeInterval OK");
return true;
}
else
{
ErrorLog($"SetStatusDataUpdateTimeInterval Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
void user_error_handle(int error_code)
{
ErrorLog($"机械臂发生异常,异常码:{error_code}");
}
}
}