-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_trajectory_no_pedestal.py
2941 lines (2572 loc) · 103 KB
/
test_trajectory_no_pedestal.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
#! /usr/bin/env python
# coding=utf-8
import time
import libpyauboi5
import logging
from logging.handlers import RotatingFileHandler
import os
from math import pi
import numpy as np
import cloudprocpy,trajoptpy
import json
import trajoptpy.make_kinbodies as mk
from trajoptpy.check_traj import traj_is_safe
from openravepy import *
import argparse
parser = argparse.ArgumentParser(description="e.g. python --interactive")
parser.add_argument("--interactive", action="store_true")
args = parser.parse_args()
# 创建一个logger
logger = logging.getLogger()
def logger_init():
# Log等级总开关
logger.setLevel(logging.INFO)
# 创建log目录
if not os.path.exists('./logfiles'):
os.mkdir('./logfiles')
# 创建一个handler,用于写入日志文件
logfile = './logfiles/robot-ctl-python.log'
# 以append模式打开日志文件
# fh = logging.FileHandler(logfile, mode='a')
fh = RotatingFileHandler(logfile, mode='a', maxBytes=1024*1024*50, backupCount=30)
# 输出到file的log等级的开关
fh.setLevel(logging.INFO)
# 再创建一个handler,用于输出到控制台
ch = logging.StreamHandler()
# 输出到console的log等级的开关
ch.setLevel(logging.INFO)
# 定义handler的输出格式
# formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
formatter = logging.Formatter("%(asctime)s [%(thread)u] %(levelname)s: %(message)s")
# 为文件输出设定格式
fh.setFormatter(formatter)
# 控制台输出设定格式
ch.setFormatter(formatter)
# 设置文件输出到logger
logger.addHandler(fh)
# 设置控制台输出到logger
logger.addHandler(ch)
class RobotEventType:
RobotEvent_armCanbusError = 0 # 机械臂CAN总线错误
RobotEvent_remoteHalt = 1 # 机械臂停止
RobotEvent_remoteEmergencyStop = 2 # 机械臂远程急停
RobotEvent_jointError = 3 # 关节错误
RobotEvent_forceControl = 4 # 力控制
RobotEvent_exitForceControl = 5 # 退出力控制
RobotEvent_softEmergency = 6 # 软急停
RobotEvent_exitSoftEmergency = 7 # 退出软急停
RobotEvent_collision = 8 # 碰撞
RobotEvent_collisionStatusChanged = 9 # 碰撞状态改变
RobotEvent_tcpParametersSucc = 10 # 工具动力学参数设置成功
RobotEvent_powerChanged = 11 # 机械臂电源开关状态改变
RobotEvent_ArmPowerOff = 12 # 机械臂电源关闭
RobotEvent_mountingPoseChanged = 13 # 安装位置发生改变
RobotEvent_encoderError = 14 # 编码器错误
RobotEvent_encoderLinesError = 15 # 编码器线数不一致
RobotEvent_singularityOverspeed = 16 # 奇异点超速
RobotEvent_currentAlarm = 17 # 机械臂电流异常
RobotEvent_toolioError = 18 # 机械臂工具端错误
RobotEvent_robotStartupPhase = 19 # 机械臂启动阶段
RobotEvent_robotStartupDoneResult = 20 # 机械臂启动完成结果
RobotEvent_robotShutdownDone = 21 # 机械臂关机结果
RobotEvent_atTrackTargetPos = 22 # 机械臂轨迹运动到位信号通知
RobotEvent_SetPowerOnDone = 23 # 设置电源状态完成
RobotEvent_ReleaseBrakeDone = 24 # 机械臂刹车释放完成
RobotEvent_robotControllerStateChaned = 25 # 机械臂控制状态改变
RobotEvent_robotControllerError = 26 # 机械臂控制错误----一般是算法规划出现问题时返回
RobotEvent_socketDisconnected = 27 # socket断开连接
RobotEvent_overSpeed = 28 # 超速
RobotEvent_algorithmException = 29 # 机械臂算法异常
RobotEvent_boardIoPoweron = 30 # 外部上电信号
RobotEvent_boardIoRunmode = 31 # 联动/手动
RobotEvent_boardIoPause = 32 # 外部暂停信号
RobotEvent_boardIoStop = 33 # 外部停止信号
RobotEvent_boardIoHalt = 34 # 外部关机信号
RobotEvent_boardIoEmergency = 35 # 外部急停信号
RobotEvent_boardIoRelease_alarm = 36 # 外部报警解除信号
RobotEvent_boardIoOrigin_pose = 37 # 外部回原点信号
RobotEvent_boardIoAutorun = 38 # 外部自动运行信号
RobotEvent_safetyIoExternalEmergencyStope = 39 # 外部急停输入01
RobotEvent_safetyIoExternalSafeguardStope = 40 # 外部保护停止输入02
RobotEvent_safetyIoReduced_mode = 41 # 缩减模式输入
RobotEvent_safetyIoSafeguard_reset = 42 # 防护重置
RobotEvent_safetyIo3PositionSwitch = 43 # 三态开关1
RobotEvent_safetyIoOperationalMode = 44 # 操作模式
RobotEvent_safetyIoManualEmergencyStop = 45 # 示教器急停01
RobotEvent_safetyIoSystemStop = 46 # 系统停止输入
RobotEvent_alreadySuspended = 47 # 机械臂暂停
RobotEvent_alreadyStopped = 48 # 机械臂停止
RobotEvent_alreadyRunning = 49 # 机械臂运行
RobotEvent_None = 999999
# 非错误事件
NoError = (RobotEvent_forceControl,
RobotEvent_exitForceControl,
RobotEvent_tcpParametersSucc,
RobotEvent_powerChanged,
RobotEvent_mountingPoseChanged,
RobotEvent_robotStartupPhase,
RobotEvent_robotStartupDoneResult,
RobotEvent_robotShutdownDone,
RobotEvent_SetPowerOnDone,
RobotEvent_ReleaseBrakeDone,
RobotEvent_atTrackTargetPos,
RobotEvent_robotControllerStateChaned,
RobotEvent_alreadyStopped,
RobotEvent_alreadyRunning,
RobotEvent_boardIoPoweron,
RobotEvent_boardIoRunmode,
RobotEvent_boardIoPause,
RobotEvent_boardIoStop,
RobotEvent_boardIoHalt,
RobotEvent_boardIoEmergency,
RobotEvent_boardIoRelease_alarm,
RobotEvent_boardIoOrigin_pose,
RobotEvent_boardIoAutorun,
RobotEvent_safetyIoExternalEmergencyStope,
RobotEvent_safetyIoExternalSafeguardStope,
RobotEvent_safetyIoReduced_mode,
RobotEvent_safetyIoSafeguard_reset,
RobotEvent_safetyIo3PositionSwitch,
RobotEvent_safetyIoOperationalMode,
RobotEvent_safetyIoManualEmergencyStop,
RobotEvent_safetyIoSystemStop,
RobotEvent_alreadySuspended,
RobotEvent_alreadyStopped,
RobotEvent_alreadyRunning
)
def __init__(self):
pass
class RobotErrorType:
RobotError_SUCC = 0 # 无错误
RobotError_Base = 2000
RobotError_RSHD_INIT_FAILED = RobotError_Base + 1 # 库初始化失败
RobotError_RSHD_UNINIT = RobotError_Base + 2 # 库未初始化
RobotError_NoLink = RobotError_Base + 3 # 无链接
RobotError_Move = RobotError_Base + 4 # 机械臂移动错误
RobotError_LOGIN_FAILED = RobotError_Base + 5 # 机械臂登录失败
RobotError_NotLogin = RobotError_Base + 6 # 机械臂未登录
RobotError_ERROR_ARGS = RobotError_Base + 7 # 参数错误
def __init__(self):
pass
class RobotEvent:
def __init__(self, event_type=RobotEventType.RobotEvent_None, event_code=0, event_msg=''):
self.event_type = event_type
self.event_code = event_code
self.event_msg = event_msg
# noinspection SpellCheckingInspection
class RobotError:
def __init__(self, error_type=RobotErrorType.RobotError_SUCC, error_code=0, error_msg=''):
self.error_type = error_type
self.error_cdoe = error_code
self.error_msg = error_msg
def __str__(self):
return "RobotError type{0} code={1} msg={2}".format(self.error_type, self.error_cdoe, self.error_msg)
class RobotDefaultParameters:
# 缺省的动力学参数
tool_dynamics = {"position": (0.0, 0.0, 0.0), "payload": 1.0, "inertia": (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)}
# 缺省碰撞等级
collision_grade = 6
def __init__(self):
pass
def __str__(self):
return "Robot Default parameters, tool_dynamics:{0}, collision_grade:{1}".format(self.tool_dynamics,
self.collision_grade)
class RobotMoveTrackType:
# 圆弧
ARC_CIR = 2
# 轨迹
CARTESIAN_MOVEP = 3
# 以下四种三阶样条插值曲线都有起始和结束点加速度不连续的情况,不适合与新关节驱动版本
# 三次样条插值(过控制点),自动优化轨迹运行时间,目前不支持姿态变化
CARTESIAN_CUBICSPLINE = 4
# 需要设定三次均匀B样条插值(过控制点)的时间间隔,目前不支持姿态变化
CARTESIAN_UBSPLINEINTP = 5
# 三阶样条插值曲线
JIONT_CUBICSPLINE = 6
# 可用于轨迹回放
JOINT_UBSPLINEINTP = 7
def __init__(self):
pass
class RobotIOType:
# 控制柜IO
ControlBox_DI = 0
ControlBox_DO = 1
ControlBox_AI = 2
ControlBox_AO = 3
# 用户IO
User_DI = 4
User_DO = 5
User_AI = 6
User_AO = 7
def __init__(self):
pass
class RobotToolIoName:
tool_io_0 = "T_DI/O_00"
tool_io_1 = "T_DI/O_01"
tool_io_2 = "T_DI/O_02"
tool_io_3 = "T_DI/O_03"
tool_ai_0 = "T_AI_00"
tool_ai_1 = "T_AI_01"
def __init__(self):
pass
class RobotUserIoName:
# 控制柜用户DI
user_di_00 = "U_DI_00"
user_di_01 = "U_DI_01"
user_di_02 = "U_DI_02"
user_di_03 = "U_DI_03"
user_di_04 = "U_DI_04"
user_di_05 = "U_DI_05"
user_di_06 = "U_DI_06"
user_di_07 = "U_DI_07"
user_di_10 = "U_DI_10"
user_di_11 = "U_DI_11"
user_di_12 = "U_DI_12"
user_di_13 = "U_DI_13"
user_di_14 = "U_DI_14"
user_di_15 = "U_DI_15"
user_di_16 = "U_DI_16"
user_di_17 = "U_DI_17"
# 控制柜用户DO
user_do_00 = "U_DO_00"
user_do_01 = "U_DO_01"
user_do_02 = "U_DO_02"
user_do_03 = "U_DO_03"
user_do_04 = "U_DO_04"
user_do_05 = "U_DO_05"
user_do_06 = "U_DO_06"
user_do_07 = "U_DO_07"
user_do_10 = "U_DO_10"
user_do_11 = "U_DO_11"
user_do_12 = "U_DO_12"
user_do_13 = "U_DO_13"
user_do_14 = "U_DO_14"
user_do_15 = "U_DO_15"
user_do_16 = "U_DO_16"
user_do_17 = "U_DO_17"
# 控制柜模拟量IO
user_ai_00 = "VI0"
user_ai_01 = "VI1"
user_ai_02 = "VI2"
user_ai_03 = "VI3"
user_ao_00 = "VO0"
user_ao_01 = "VO1"
user_ao_02 = "VO2"
user_ao_03 = "VO3"
def __init__(self):
pass
class RobotStatus:
# 机械臂当前停止
Stopped = 0
# 机械臂当前运行
Running = 1
# 机械臂当前暂停
Paused = 2
# 机械臂当前恢复
Resumed = 3
def __init__(self):
pass
class RobotRunningMode:
# 机械臂仿真模式
RobotModeSimulator = 0
# 机械臂真实模式
RobotModeReal = 1
def __init__(self):
pass
class RobotToolPowerType:
OUT_0V = 0
OUT_12V = 1
OUT_24V = 2
def __init__(self):
pass
class RobotToolIoAddr:
TOOL_DIGITAL_IO_0 = 0
TOOL_DIGITAL_IO_1 = 1
TOOL_DIGITAL_IO_2 = 2
TOOL_DIGITAL_IO_3 = 3
def __init__(self):
pass
class RobotCoordType:
# 基座坐标系
Robot_Base_Coordinate = 0
# 末端坐标系
Robot_End_Coordinate = 1
# 用户坐标系
Robot_World_Coordinate = 2
def __init__(self):
pass
class RobotCoordCalMethod:
CoordCalMethod_xOy = 0
CoordCalMethod_yOz = 1
CoordCalMethod_zOx = 2
CoordCalMethod_xOxy = 3
CoordCalMethod_xOxz = 4
CoordCalMethod_yOyx = 5
CoordCalMethod_yOyz = 6
CoordCalMethod_zOzx = 7
CoordCalMethod_zOzy = 8
def __init__(self):
pass
class RobotToolDigitalIoDir:
# 输入
IO_IN = 0
# 输出
IO_OUT = 1
def __init__(self):
pass
class Auboi5Robot:
# 客户端个数
__client_count = 0
def __init__(self):
self.rshd = -1
self.connected = False
self.last_error = RobotError()
self.last_event = RobotEvent()
Auboi5Robot.__client_count += 1
def __del__(self):
Auboi5Robot.__client_count -= 1
self.uninitialize()
logger.info("client_count={0}".format(Auboi5Robot.__client_count))
def __str__(self):
return "RSHD={0}, connected={1}".format(self.rshd, self.connected)
@staticmethod
def get_local_time():
""""
* FUNCTION: get_local_time
* DESCRIPTION: 获取系统当前时间
* INPUTS: 无输入
* OUTPUTS:
* RETURNS: 输出系统当前时间字符串
* NOTES:
"""
return time.strftime("%b %d %Y %H:%M:%S", time.localtime(time.time()))
def robot_event_callback(self, event):
""""
* FUNCTION: robot_event_callback
* DESCRIPTION: 机械臂事件
* INPUTS: 无输入
* OUTPUTS:
* RETURNS: 系统事件回调函数
* NOTES:
"""
if event['type'] not in RobotEventType.NoError:
self.last_error = RobotError(event['type'], event['code'], event['content'])
else:
self.last_event = RobotEvent(event['type'], event['code'], event['content'])
@staticmethod
def raise_error(error_type, error_code, error_msg):
""""
* FUNCTION: raise_error
* DESCRIPTION: 抛出异常事件
* INPUTS: 无输入
* OUTPUTS:
* RETURNS: 无
* NOTES:
"""
raise RobotError(error_type, error_code, error_msg)
def check_event(self):
""""
* FUNCTION: check_event
* DESCRIPTION: 检查机械臂是否发生异常事件
* INPUTS: input
* OUTPUTS: output
* RETURNS: void
* NOTES: 如果接收到的是异常事件,则函数抛出异常事件
"""
if self.last_error.error_type != RobotErrorType.RobotError_SUCC:
raise self.last_error
if self.rshd == -1 or not self.connected:
self.raise_error(RobotErrorType.RobotError_NoLink, 0, "no socket link")
@staticmethod
def initialize():
""""
* FUNCTION: initialize
* DESCRIPTION: 初始化机械臂控制库
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
result = libpyauboi5.initialize()
if result == RobotErrorType.RobotError_SUCC:
return RobotErrorType.RobotError_SUCC
else:
return RobotErrorType.RobotError_RSHD_INIT_FAILED
@staticmethod
def uninitialize():
""""
* FUNCTION: uninitialize
* DESCRIPTION: 反初始化机械臂控制库
* INPUTS: input
* OUTPUTS: output
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
return libpyauboi5.uninitialize()
def create_context(self):
""""
* FUNCTION: create_context
* DESCRIPTION: 创建机械臂控制上下文句柄
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RSHD
* NOTES:
"""
self.rshd = libpyauboi5.create_context()
return self.rshd
def get_context(self):
""""
* FUNCTION: get_context
* DESCRIPTION: 获取机械臂当前控制上下文
* INPUTS:
* OUTPUTS:
* RETURNS: 上下文句柄RSHD
* NOTES:
"""
return self.rshd
def connect(self, ip='localhost', port=8899):
""""
* FUNCTION: connect
* DESCRIPTION: 链接机械臂服务器
* INPUTS: ip 机械臂服务器地址
* port 端口号
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
*
* NOTES:
"""
logger.info("ip={0}, port={1}".format(ip, port))
if self.rshd >= 0:
if not self.connected:
if libpyauboi5.login(self.rshd, ip, port) == 0:
self.connected = True
time.sleep(0.5)
return RobotErrorType.RobotError_SUCC
else:
logger.error("login failed!")
return RobotErrorType.RobotError_LOGIN_FAILED
else:
logger.info("already connected.")
return RobotErrorType.RobotError_SUCC
else:
logger.error("RSHD uninitialized!!!")
return RobotErrorType.RobotError_RSHD_UNINIT
def disconnect(self):
""""
* FUNCTION: disconnect
* DESCRIPTION: 断开机械臂服务器链接
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
if self.rshd >= 0 and self.connected:
libpyauboi5.logout(self.rshd)
self.connected = False
time.sleep(0.5)
return RobotErrorType.RobotError_SUCC
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def robot_startup(self, collision=RobotDefaultParameters.collision_grade,
tool_dynamics=RobotDefaultParameters.tool_dynamics):
"""
* FUNCTION: robot_startup
* DESCRIPTION: 启动机械臂
* INPUTS: collision:碰撞等级范围(0~10) 缺省:6
* tool_dynamics:运动学参数
* tool_dynamics = 位置,单位(m) :{"position": (0.0, 0.0, 0.0),
* 负载,单位(kg): "payload": 1.0,
* 惯量: "inertia": (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)}
*
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
result = libpyauboi5.robot_startup(self.rshd, collision, tool_dynamics)
time.sleep(0.5)
self.set_robot_event_callback(self.robot_event_callback)
return result
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def robot_shutdown(self):
"""
* FUNCTION: robot_shutdown
* DESCRIPTION: 关闭机械臂
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
if self.rshd >= 0 and self.connected:
result = libpyauboi5.robot_shutdown(self.rshd)
time.sleep(0.5)
return result
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def enable_robot_event(self):
self.check_event()
if self.rshd >= 0 and self.connected:
self.set_robot_event_callback(self.robot_event_callback)
return RobotErrorType.RobotError_SUCC
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def init_profile(self):
""""
* FUNCTION: init_profile
* DESCRIPTION: 初始化机械臂控制全局属性
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
*
* NOTES: 调用成功后,系统会自动清理掉之前设置的用户坐标系,
* 速度,加速度等等属性
"""
if self.rshd >= 0 and self.connected:
return libpyauboi5.init_global_move_profile(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def set_joint_maxacc(self, joint_maxacc=(1.0, 1.0, 1.0, 1.0, 1.0, 1.0)):
"""
* FUNCTION: set_joint_maxacc
* DESCRIPTION: 设置六个关节的最大加速度
* INPUTS: joint_maxacc:六个关节的最大加速度,单位(rad/s)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_joint_maxacc(self.rshd, joint_maxacc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_joint_maxacc(self):
"""
* FUNCTION: get_joint_maxacc
* DESCRIPTION: 获取六个关节的最大加速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 六个关节的最大加速度单位(rad/s^2)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_joint_maxacc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def set_joint_maxvelc(self, joint_maxvelc=(1.0, 1.0, 1.0, 1.0, 1.0, 1.0)):
"""
* FUNCTION: set_joint_maxvelc
* DESCRIPTION: 设置六个关节的最大速度
* INPUTS: joint_maxvelc:六个关节的最大速度,单位(rad/s)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_joint_maxvelc(self.rshd, joint_maxvelc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_joint_maxvelc(self):
"""
* FUNCTION: get_joint_maxvelc
* DESCRIPTION: 获取六个关节的最大速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 六个关节的最大速度(rad/s)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_joint_maxvelc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def set_end_max_line_acc(self, end_maxacc=0.1):
"""
* FUNCTION: set_end_max_line_acc
* DESCRIPTION: 设置机械臂末端最大线加速度
* INPUTS: end_maxacc:末端最大加线速度,单位(m/s^2)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_end_max_line_acc(self.rshd, end_maxacc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_end_max_line_acc(self):
"""
* FUNCTION: get_end_max_line_acc
* DESCRIPTION: 获取机械臂末端最大线加速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 机械臂末端最大加速度,单位(m/s^2)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_end_max_line_acc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def set_end_max_line_velc(self, end_maxvelc=0.1):
"""
* FUNCTION: set_end_max_line_velc
* DESCRIPTION: 设置机械臂末端最大线速度
* INPUTS: end_maxacc:末端最大线速度,单位(m/s)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_end_max_line_velc(self.rshd, end_maxvelc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_end_max_line_velc(self):
"""
* FUNCTION: get_end_max_line_velc
* DESCRIPTION: 获取机械臂末端最大线速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 机械臂末端最大速度,单位(m/s)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_end_max_line_velc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def set_end_max_angle_acc(self, end_maxacc=0.1):
"""
* FUNCTION: set_end_max_angle_acc
* DESCRIPTION: 设置机械臂末端最大角加速度
* INPUTS: end_maxacc:末端最大加速度,单位(rad/s^2)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_end_max_angle_acc(self.rshd, end_maxacc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_end_max_angle_acc(self):
"""
* FUNCTION: get_end_max_angle_acc
* DESCRIPTION: 获取机械臂末端最大角加速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 机械臂末端最大角加速度,单位(m/s^2)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_end_max_angle_acc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def set_end_max_angle_velc(self, end_maxvelc=0.1):
"""
* FUNCTION: set_end_max_angle_velc
* DESCRIPTION: 设置机械臂末端最大角速度
* INPUTS: end_maxacc:末端最大速度,单位(rad/s)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.set_end_max_line_velc(self.rshd, end_maxvelc)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def get_end_max_angle_velc(self):
"""
* FUNCTION: get_end_max_angle_velc
* DESCRIPTION: 获取机械臂末端最大角速度
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: 机械臂末端最大速度,单位(rad/s)
* 失败返回: None
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.get_end_max_line_velc(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return None
def move_to_target_in_cartesian(self, pos, rpy_xyz):
"""
* FUNCTION: move_to_target_in_cartesian
* DESCRIPTION: 给出笛卡尔坐标值和欧拉角,机械臂轴动到目标位置和姿态
* INPUTS: pos:位置坐标(x,y,z),单位(m)
* rpy:欧拉角(rx,ry,rz),单位(度)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
# 度 -> 弧度
rpy_xyz = [i / 180.0 * pi for i in rpy_xyz]
# 欧拉角转四元数
ori = libpyauboi5.rpy_to_quaternion(self.rshd, rpy_xyz)
logger.info("rpy=========={0}".format(rpy_xyz))
logger.info("rpy--->ori=========={0}".format(ori))
ppp = libpyauboi5.quaternion_to_rpy(self.rshd, ori)
logger.info("ori---->rpy=========={0}".format(ppp))
# 逆运算得关节角
joint_radian = libpyauboi5.get_current_waypoint(self.rshd)
# joint_radian = [0, 0, 0, 0, 0, 0]
logger.info(joint_radian)
ik_result = libpyauboi5.inverse_kin(self.rshd, joint_radian['joint'], pos, ori)
logging.info("ik_result====>{0}".format(ik_result))
# 轴动到目标位置
result = libpyauboi5.move_joint(self.rshd, ik_result["joint"])
if result != RobotErrorType.RobotError_SUCC:
self.raise_error(RobotErrorType.RobotError_Move, result, "move error")
else:
return RobotErrorType.RobotError_SUCC
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def move_joint(self, joint_radian=(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)):
"""
* FUNCTION: move_joint
* DESCRIPTION: 机械臂轴动
* INPUTS: joint_radian:六个关节的关节角,单位(rad)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
result = libpyauboi5.move_joint(self.rshd, joint_radian)
if result != RobotErrorType.RobotError_SUCC:
self.raise_error(RobotErrorType.RobotError_Move, result, "move error")
else:
return RobotErrorType.RobotError_SUCC
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def move_line(self, joint_radian=(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)):
"""
* FUNCTION: move_line
* DESCRIPTION: 机械臂保持当前姿态直线运动
* INPUTS: joint_radian:六个关节的关节角,单位(rad)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
result = libpyauboi5.move_line(self.rshd, joint_radian)
if result != RobotErrorType.RobotError_SUCC:
self.raise_error(RobotErrorType.RobotError_Move, result, "move error")
else:
return RobotErrorType.RobotError_SUCC
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def move_rotate(self, user_coord, rotate_axis, rotate_angle):
"""
* FUNCTION: move_rotate
* DESCRIPTION: 保持当前位置变换姿态做旋转运动
* INPUTS: user_coord:用户坐标系
* user_coord = {'coord_type': 2,
* 'calibrate_method': 0,
* 'calibrate_points':
* {"point1": (0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
* "point2": (0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
* "point3": (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)},
* 'tool_desc':
* {"pos": (0.0, 0.0, 0.0),
* "ori": (1.0, 0.0, 0.0, 0.0)}
* }
* rotate_axis:转轴(x,y,z) 例如:(1,0,0)表示沿Y轴转动
* rotate_angle:旋转角度 单位(rad)
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.move_rotate(self.rshd, user_coord, rotate_axis, rotate_angle)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def clear_offline_track(self):
"""
* FUNCTION: clear_offline_track
* DESCRIPTION: 清理服务器上的非在线轨迹运动数据
* INPUTS:
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.clear_offline_track(self.rshd)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def append_offline_track_waypoint(self, waypoints):
"""
* FUNCTION: append_offline_track_waypoint
* DESCRIPTION: 向服务器添加非在线轨迹运动路点
* INPUTS: waypoints 非在线轨迹运动路点元祖(可包含小于3000个路点), 单位:弧度
* 例如:((0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
* (0.0,-0.000001,-0.000001,0.000001,-0.000001, 0.0))
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.append_offline_track_waypoint(self.rshd, waypoints)
else:
logger.warn("RSHD uninitialized or not login!!!")
return RobotErrorType.RobotError_NotLogin
def append_offline_track_file(self, track_file):
"""
* FUNCTION: append_offline_track_file
* DESCRIPTION: 向服务器添加非在线轨迹运动路点文件
* INPUTS: 路点文件全路径,路点文件的每一行包含六个关节的关节角(弧度),用逗号隔开
* OUTPUTS:
* RETURNS: 成功返回: RobotError.RobotError_SUCC
* 失败返回: 其他
* NOTES:
"""
self.check_event()
if self.rshd >= 0 and self.connected:
return libpyauboi5.append_offline_track_file(self.rshd, track_file)
else:
logger.warn("RSHD uninitialized or not login!!!")