@@ -761,7 +761,6 @@ def calibration_parameters(**kwargs):
761761 check_0_or_1 (parameter , value , [1 , 2 , 3 ], value_type , MyCobot320DataException , int )
762762 elif parameter == "gripper_angle" :
763763 gripper_id , gripper_angle = value
764- print (type (gripper_id ), type (gripper_angle ))
765764 if not isinstance (gripper_id , int ) or not isinstance (gripper_angle , int ):
766765 raise MyCobot320DataException (
767766 "Both 'gripper_id' and 'gripper_angle' in {} must be integers" .format (parameter ))
@@ -806,76 +805,54 @@ def calibration_parameters(**kwargs):
806805 raise MyCobot320DataException (
807806 "The range of 'speed' in {} is 1 ~ 100, but the received value is {}" .format (parameter ,
808807 speed ))
809- elif parameter == "joint_id" :
810- check_value_type (parameter , value_type , MyCobot320DataException , int )
811- if not 0 <= value <= 6 :
812- raise MyCobot320DataException (
813- "speed value not right, should be 1 ~ 100, the received speed is %s"
814- % value
815- )
808+
816809 elif parameter == "set_gripper_args" :
810+ if len (value ) != 3 :
811+ raise ValueError (f"Expected 3 arguments, but got { len (value )} " )
817812 gripper_id , address , data = value
818- if not isinstance (gripper_id , int ) or not isinstance (address , int ):
813+ if not isinstance (gripper_id , int ) or not isinstance (address , int ) or not isinstance ( data , int ) :
819814 raise MyCobot320DataException (
820815 "All arguments in {} must be integers" .format (parameter ))
821816 if gripper_id < 1 or gripper_id > 254 :
822817 raise MyCobot320DataException (
823818 "The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}" .format (parameter ,
824819 gripper_id ))
825- invalid_addresses = [1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 22 , 24 , 26 , 27 , 28 , 32 , 33 ,
826- 36 ,
827- 37 , 38 , 39 , 40 , 42 , 44 ]
828- if address < 1 or address > 48 :
820+ invalid_addresses = [1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 12 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 22 , 24 , 26 , 28 , 33 , 34 , 35 ,
821+ 40 , 42 , 44 ]
822+ if address < 1 or address > 44 :
829823 raise MyCobot320DataException (
830- "The range of 'address' in {} is 1 ~ 48 , but the received value is {}" .format (parameter ,
824+ "The range of 'address' in {} is 1 ~ 44 , but the received value is {}" .format (parameter ,
831825 address ))
832826 if address in invalid_addresses :
833827 raise MyCobot320DataException (
834828 "'address' in {} cannot be one of the following values: {}, but the received value is {}" .format (
835829 parameter , invalid_addresses , address ))
836- print ('data:' , data )
837- if isinstance (data , list ):
838- # 处理 data 为列表的情况
839- if len (data ) != 6 :
830+ # 根据 address 来处理 value
831+ if address in [3 , 43 ]:
832+ if data < 1 or data > 254 :
840833 raise MyCobot320DataException (
841- "data must be a list of length 6。"
842- )
843- for index , value in enumerate (data ):
844- if not (0 <= value <= 100 ):
845- raise MyCobot320DataException (
846- "Each value in the data list must be between 0 and 100. Error index {}: The received value is {}" .format (index , value )
847- )
848- else :
849- if not isinstance (data , int ):
834+ "Error in parameter '{}': The range of 'value' for address={} is 1 ~ 254, but the received value is {}" .format (
835+ parameter , address , data ))
836+ elif address == 10 :
837+ if data not in [0 , 1 ]:
850838 raise MyCobot320DataException (
851- "The parameter {} must be an integer" .format (data )
852- )
853- # 根据 address 来处理 value
854- if address in [3 , 43 ]:
855- if data < 1 or data > 254 :
856- raise MyCobot320DataException (
857- "Error in parameter '{}': The range of 'value' for address={} is 1 ~ 254, but the received value is {}" .format (
858- parameter , address , data ))
859- elif address == 10 :
860- if data not in [0 , 1 ]:
861- raise MyCobot320DataException (
862- "Error in parameter '{}': Value for address={} must be 0 or 1, but the received value is {}" .format (
863- parameter , address , data ))
864- elif address in [25 ]:
865- if data < 0 or data > 254 :
866- raise MyCobot320DataException (
867- "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 254, but the received value is {}" .format (
868- parameter , address , data ))
869- elif address in [21 , 23 ]:
870- if data < 0 or data > 16 :
871- raise MyCobot320DataException (
872- "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 16, but the received value is {}" .format (
873- parameter , address , data ))
874- elif address == 41 :
875- if data < 0 or data > 100 :
876- raise MyCobot320DataException (
877- "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 100, but the received value is {}" .format (
878- parameter , address , data ))
839+ "Error in parameter '{}': Value for address={} must be 0 or 1, but the received value is {}" .format (
840+ parameter , address , data ))
841+ elif address in [25 ]:
842+ if data < 0 or data > 254 :
843+ raise MyCobot320DataException (
844+ "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 254, but the received value is {}" .format (
845+ parameter , address , data ))
846+ elif address in [21 , 23 ]:
847+ if data < 0 or data > 16 :
848+ raise MyCobot320DataException (
849+ "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 16, but the received value is {}" .format (
850+ parameter , address , data ))
851+ elif address == 41 :
852+ if data < 0 or data > 100 :
853+ raise MyCobot320DataException (
854+ "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 100, but the received value is {}" .format (
855+ parameter , address , data ))
879856
880857 elif parameter == "get_gripper_args" :
881858 gripper_id , address = value
@@ -886,7 +863,8 @@ def calibration_parameters(**kwargs):
886863 raise MyCobot320DataException (
887864 "The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}" .format (parameter ,
888865 gripper_id ))
889- invalid_addresses = [5 , 6 , 10 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 23 , 25 , 29 , 30 , 31 , 34 , 35 , 41 , 43 ]
866+ invalid_addresses = [3 , 5 , 6 , 10 , 11 , 13 , 15 , 17 , 19 , 21 , 23 , 25 , 27 , 29 , 30 , 31 , 32 , 36 , 37 ,
867+ 38 , 39 , 41 , 43 ]
890868 if address < 1 or address > 44 :
891869 raise MyCobot320DataException (
892870 "The range of 'address' in {} is 1 ~ 44, but the received value is {}" .format (parameter ,
@@ -1281,7 +1259,8 @@ def calibration_parameters(**kwargs):
12811259 elif parameter in ['servo_id_pdi' , 'encode_id' ]:
12821260 check_value_type (parameter , value_type , MyPalletizer260DataException , int )
12831261 if value < 1 or (value > 4 and value != 7 ):
1284- raise MyPalletizer260DataException ("The range of id is 1 ~ 4 or 7, but the received is {}" .format (value ))
1262+ raise MyPalletizer260DataException (
1263+ "The range of id is 1 ~ 4 or 7, but the received is {}" .format (value ))
12851264 elif parameter == "torque" :
12861265 torque_min = 150
12871266 torque_max = 980
0 commit comments