1- _MINANGLE = - 190.0
2- _MAXANGLE = 190.0
1+ # coding=utf-8
2+
3+ # In order to adapt to the atom side, ID of 0-5 or 1-6 are allowed.
4+ # In order to support end control, ID 7 is allowed.
5+ MIN_ID = 0
6+ MAX_ID = 7
7+
8+ # In fact, most joints cannot reach plus or minus 180 degrees.
9+ # There may be a value greater than 180 when reading the angle,
10+ # and the maximum and minimum values are expanded for compatibility.
11+ MIN_ANGLE = - 190.0
12+ MAX_ANGLE = 190.0
313
414
515class MyCobotDataException (Exception ):
@@ -11,65 +21,55 @@ def check_boolean(b):
1121 raise MyCobotDataException ("This parameter needs to be 0 or 1" )
1222
1323
14- def check_range (v , ra ):
15- min , max = ra
16- if min <= v <= max :
17- return True
18- else :
19- return False
20-
21-
22- def check_coord (id , v ):
23- coords = ["x" , "y" , "z" , "rx" , "ry" , "rz" ]
24- if id < 3 :
25- pass
26- else :
27- if not check_range (v , [- 180 , 180 ]):
28- raise MyCobotDataException (
29- "{} value not right, should be -180 ~ 180" .format (coords [id ])
30- )
31-
32-
33- def check_rgb (args ):
34- rgb_str = ["r" , "g" , "b" ]
35- for i , v in enumerate (args ):
36- if not check_range (v , [0 , 255 ]):
37- raise MyCobotDataException (
38- "The RGB value needs be 0 ~ 255, but the %s is %s" % (rgb_str [i ], v )
39- )
40-
41-
42- def check_datas (** kwargs ):
43- if kwargs .get ("joint_id" , None ) is not None and not 0 < kwargs ["joint_id" ] < 7 :
24+ def calibration_parameters (** kwargs ):
25+ if kwargs .get ("id" , None ) is not None and not MIN_ID <= kwargs ["id" ] <= MAX_ID :
4426 raise MyCobotDataException (
45- "The joint id not right, should be 1 ~ 6, but received %s."
46- % kwargs ["joint_id" ]
27+ "The id not right, should be {0} ~ {1}, but received {2}." .format (
28+ MIN_ID , MAX_ID , kwargs ["id" ]
29+ )
4730 )
31+
4832 if (
4933 kwargs .get ("degree" , None ) is not None
50- and not _MINANGLE <= kwargs ["degree" ] <= _MAXANGLE
34+ and not MIN_ANGLE <= kwargs ["degree" ] <= MAX_ANGLE
5135 ):
5236 raise MyCobotDataException (
53- "degree value not right, should be -180 ~ 180, but received %s"
54- % kwargs ["degree" ]
55- )
56- if kwargs .get ("len6" , None ) is not None :
57- len_ = len (kwargs ["len6" ])
58- if len_ != 6 :
59- raise MyCobotDataException (
60- "The length of data should be 6, the truth is %s" % len_
37+ "degree value not right, should be {0} ~ {1}, but received {2}" .format (
38+ MIN_ANGLE , MAX_ANGLE , kwargs ["degree" ]
6139 )
40+ )
41+
6242 if kwargs .get ("degrees" , None ) is not None :
63- for idx , angle in enumerate (kwargs ["degrees" ]):
64- if not _MINANGLE <= angle <= _MAXANGLE :
43+ degrees = kwargs ["degrees" ]
44+ if not isinstance (degrees , list ):
45+ raise MyCobotDataException ("`degrees` must be a list." )
46+ if len (degrees ) != 6 :
47+ raise MyCobotDataException ("The length of `degrees` must be 6." )
48+ for idx , angle in enumerate (degrees ):
49+ if not MIN_ANGLE <= angle <= MAX_ANGLE :
6550 raise MyCobotDataException (
66- "degree value not right, should be -180 ~ 180, the error index is %s"
67- % idx
51+ "Has invalid degree value, error on index {0}. Degree should be {1} ~ {2}." .format (
52+ idx , MIN_ANGLE , MAX_ANGLE
53+ )
6854 )
55+
56+ if kwargs .get ("coords" , None ) is not None :
57+ coords = kwargs ["coords" ]
58+ if not isinstance (coords , list ):
59+ raise MyCobotDataException ("`coords` must be a list." )
60+ if len (coords ) != 6 :
61+ raise MyCobotDataException ("The length of `coords` must be 6." )
62+
6963 if kwargs .get ("speed" , None ) is not None and not 0 <= kwargs ["speed" ] <= 100 :
7064 raise MyCobotDataException (
7165 "speed value not right, should be 0 ~ 100, the error speed is %s"
7266 % kwargs ["speed" ]
7367 )
68+
7469 if kwargs .get ("rgb" , None ) is not None :
75- check_rgb (kwargs ["rgb" ])
70+ rgb_str = ["r" , "g" , "b" ]
71+ for i , v in enumerate (kwargs ["rgb" ]):
72+ if not (0 <= v <= 255 ):
73+ raise MyCobotDataException (
74+ "The RGB value needs be 0 ~ 255, but the %s is %s" % (rgb_str [i ], v )
75+ )
0 commit comments