importjsonclassCheck_Info():
""" 该类用于校验数据: check_msg校验自己定义的msg结果 check_robot_status校验机器人当前状态 check_coordinate#校验机器人坐标数据 """defcheck_msg(self,msg):
""" 通过校验返回参数中的msg,msg参数是脚本中自定义的 :param msg: bool判断增加的msg参数是否正确 :return: """ifmsg["msg"] =="pass":
returnTrueelifmsg["msg"] =="fail":
print("错误信息:",msg["error"])
returnFalseelifmsg["msg"] ==None:
print("msg中没有数据")
returnNoneelse:
return"参数中未包含result"defcheck_result(self,result):
""" 通过校验返回值参数,此处是第一步校验,分两种校验方式,第一种校验bool类型, 第二种校验非bool类型,如果是第二种直接将数据抛出通过其他自定义校验 :param result: :return: """try:
ifresult["result"] =="true":
returnTrueelifresult["result"] =="false":
returnFalseelse:
returnNoneexcept:
ifresult["msg"] =="fail":
print("没有拿到返回值result",result)
returnFalseelse:
print("msg为空该返回数据存在问题")
returnNonedefcheck_robot_status(self,robot_status):
""" 获取机器人当前状态 :param robot_status: result拿到的参数 :return: """try:
ifrobot_status["result"] =="0":
return"停止状态"elifrobot_status["result"] =="1":
return"暂停状态"elifrobot_status["result"] =="2":
return"急停状态"elifrobot_status["result"] =="3":
return"运行状态"elifrobot_status["result"] =="4":
return"错误状态"elifrobot_status["result"] =="5":
return"碰撞状态"else:
return"状态错误码不包含在文档里:"+str(robot_status["result"])
except:
print("没有拿到返回值result")
returnFalsedefcheck_robot_mode(self,robot_mode):
""" 获取机器人当前模式 :param robot_mode: result拿到的参数区间0-2 :return: """try:
robot_mode_data=robot_mode["result"]
if0<=int(robot_mode_data) <=2:
print("0:示教模式,1:自动模式,2:远程模式")
returnint(robot_mode_data)
else:
return"机器人当前模式错误:"+robot_modeexcept:
print("没有拿到返回值result")
returnFalsedefcheck_payload(self,result):
""" 校验设置机械臂的负载结果 :param result: :return: """try:
payload_data=result["result"]
if0<=float(payload_data) <=7.2:
returnfloat(payload_data)
else:
return"返回数据错误",resultexcept:
print("没有拿到返回值result",result)
returnFalsedefcheck_focus(self,result):
""" 校验设置机械臂的重量结果 :param result: :return: """try:
focus_data=json.loads(result["result"])
iftype(focus_data) ==list:
returnfocus_dataelse:
print("result返回错误类型数据",result)
returnresultexcept:
returnFalsedefcheck_coordinate(self,expected_results, actual_results, error=0.005, isPos=True):
""" 验证机器人坐标:通过发送坐标的坐标位置和返回的坐标位置做数据校验,通过截取到小数点后三位,保证最后一位误差大于或者小于等于0.001 该方法同时用于验证位姿,验证位姿调用时,isPos参数设为false :param expected_results: 发送的坐标参数 :param actual_results: 返回的坐标参数 :param isPos: True为校验关节坐标,False为校验位姿坐标 :return: 返回bool类型用于pytest验证 """try:
ifisPos==True:
expected_results[6], expected_results[7] =0, 0check_data= []
try:
expected_lists= []
actual_lists= []
foriinrange(len(expected_results)):
expected_list=round(expected_results[i], 3)
actual_list=round(actual_results[i], 3)
expected_lists.append(round(expected_results[i], 4))
actual_lists.append(round(actual_results[i], 4))
if0<=abs(expected_list-actual_list) <=error:
check_data.append("pass")
else:
check_data.append("fail")
print("发送的坐标:", expected_lists)
print("返回的坐标:", actual_lists)
except:
return"暂无数据对比"try:
if"fail"incheck_data:
returnFalseelse:
returnTrueexcept:
return"校验结果中数据不全"except:
print("没有拿到返回值result")
returnFalsedefcheck_motor_speed(self,motor_speed_json):
""" 验证机器人马达速度不为0判断正确 :param motor_speed:传入参数 :return: """try:
motor_speed_json=json.loads(motor_speed_json["result"])
motor_speed_data=motor_speed_json[0:6]
ifmotor_speed_data!= [0,0,0,0,0,0]:
print("马达速度不为0:",motor_speed_data)
returnTrueelse:
print("马达速度等于0:",motor_speed_data)
returnFalseexcept:
print("没有拿到返回值result")
returnFalsedefcheck_currentcoord(self,currentcoord):
""" 验证机器人坐标系设置功能 :param currentcoord:传入参数区间0-4 :return: """try:
currentcoord_data=currentcoord["result"]
if0<=int(currentcoord_data) <=4:
print("0:关节,1:直角,2:工具,3:用户,4:圆柱")
returnint(currentcoord_data)
else:
return"指定坐标系错误:"+currentcoordexcept:
print("没有拿到返回值result")
returnFalsedefcheck_cyclemode(self,cyclemode):
""" 验证机器人循环模式 :param cyclemode:传入参数区间0-2 :return: """try:
cyclemode_data=cyclemode["result"]
if0<=int(cyclemode_data) <=2:
print("0:单步,1:单循环,2:连续循环")
returnint(cyclemode_data)
else:
return"机器人循环模式错误:"+cyclemodeexcept:
print("没有拿到返回值result")
returnFalsedefcheck_ToolNumber(self,toolnumber):
""" 验证机器人切换工具号 :param toolnumber:传入参数区间0-7 :return: """try:
tool_result=toolnumber["result"]
if0<=int(tool_result) <=7:
returnint(tool_result)
else:
return"工具号数据错误:"+toolnumberexcept:
print("没有拿到返回值result")
returnFalsedefcheck_UserNumber(self,UserNumber):
""" 验证机器人切换当前用户坐标 :param toolnumber:传入参数区间0-7 :return: """try:
tool_result=UserNumber["result"]
if0<=int(tool_result) <=7:
returnint(tool_result)
else:
return"当前用户坐标数据错误:"+UserNumberexcept:
print("没有拿到返回值result")
returnFalsedefcheck_VarB(self, currentVarB):
""" 验证机器人获取B变量 :param currentVarB: 传入B变量 :return: """try:
varB_result=json.loads(currentVarB["result"])
ifisinstance(varB_result, int) and0<=varB_result<=2147483647:
returnvarB_resultelse:
return"当前B变量错误"+json.dumps(currentVarB)
except:
print("没有拿到返回值result")
returnFalsedefcheck_VarI(self, currentVarI):
""" 验证机器人获取I变量 :param currentVarI: 传入I变量 :return: """try:
varI_result=json.loads(currentVarI["result"])
ifisinstance(varI_result, int) and-32768<=varI_result<=32767:
returnvarI_resultelse:
return"当前I变量错误"+json.dumps(currentVarI)
except:
print("没有拿到返回值result")
returnFalsedefcheck_VarD(self, currentVarD):
""" 验证机器人获取变量 :param currentVarD: 传入D变量 :return: """try:
varD_result=json.loads(currentVarD["result"])
ifisinstance(varD_result, int) orisinstance(varD_result, float):
if-1000000000<=varD_result<=1000000000:
returnvarD_resultelse:
return"当前D变量错误"+json.dumps(currentVarD)
else:
return"当前D变量错误"+json.dumps(currentVarD)
except:
print("没有拿到返回值result")
returnFalsedefcheck_VarP(self, currentVarP):
""" 验证机器人获取变量 :param currentVarP: 传入P变量 :return: """try:
varP_result=json.loads(currentVarP["result"])
ifnotisinstance(varP_result, list):
return"当前P变量错误"+json.dumps(currentVarP)
iflen(varP_result) !=8:
return"当前P变量错误"+json.dumps(currentVarP)
foriteminvarP_result:
ifnot (isinstance(item, int) orisinstance(item, float)):
return"当前P变量错误"+json.dumps(currentVarP)
ifitem<-360oritem>360:
return"当前P变量错误"+json.dumps(currentVarP)
returnvarP_resultexcept:
print("没有拿到返回值result")
returnFalsedefcheck_VarV(self, currentVarV):
""" 验证机器人获取变量 :param currentVarV: 传入V变量 :return: """try:
varV_result=json.loads(currentVarV["result"])
ifnotisinstance(varV_result, list):
return"当前V变量错误"+json.dumps(currentVarV)
iflen(varV_result) !=6:
return"当前V变量错误"+json.dumps(currentVarV)
forindexinrange(0, len(varV_result)):
ifnot (isinstance(varV_result[index], int) orisinstance(varV_result[index], float)):
return"当前V变量错误"+json.dumps(currentVarV)
ifindexin [3, 4, 5]:
ifvarV_result[index] <-3.141592653589794orvarV_result[index] >3.141592653589794:
return"当前V变量错误"+json.dumps(currentVarV)
returnvarV_resultexcept:
print("没有拿到返回值result")
returnFalsedefcheck_PState(self, currentPstate):
""" 验证机器人获取P变量是否启用 :param currentVarV: 传入P变量状态 :return: """try:
pState_result=json.loads(currentPstate["result"])
ifpState_result!=0orpState_result!=1:
returnpState_resultelse:
return"当前P变量状态获取错误"+json.dumps(currentPstate)
except:
print("没有拿到返回值result")
returnFalsedefcheck_UserFrame(self,set_UserFrame,result_UserFrame):
""" 用于校验用户坐标系数据,主要将result中数据提取并返回,校验则在yaml文件中,直接与发送数据做校验 :param UserFrame: :return: """try:
result_UserFrame=json.loads(result_UserFrame["result"])
check_data= []
try:
print("发送的坐标:", set_UserFrame)
print("返回的坐标:", result_UserFrame)
foriinrange(len(result_UserFrame)):
expected_list=round(result_UserFrame[i], 6)
actual_list=round(set_UserFrame[i], 6)
ifexpected_list==actual_list:
check_data.append("pass")
else:
check_data.append("fail")
except:
return"暂无数据对比"try:
if"fail"incheck_data:
returnFalseelse:
returnTrueexcept:
return"校验结果中数据不全"except:
print("没有拿到返回值result")
returnFalsedefcheck_jbiExist(self, currentJbiExist):
""" 用于校验jbi是否存在 :param currentJbiExist: :return: """try:
jbi_exist=json.loads(currentJbiExist["result"])
ifjbi_exist==0orjbi_exist==1:
returnjbi_existelse:
return"当前获取jbi是否存在错误"+json.dumps(currentJbiExist)
except:
print("没有拿到返回值result")
returnFalsedefcheck_jbi_state(self, currentJbiState):
""" 用于校验jbi运行状态 :param currentJbiState: :return: """try:
jbi_state=json.loads(currentJbiState["result"])
ifisinstance(jbi_state["jbiName"], str) ==True:
ifjbi_state["runState"] in [0,1,2,3,4]:
returnjbi_stateelse:
return"当前获取jbi状态错误"+json.dumps(currentJbiState)
else:
return"当前获取jbi状态错误"+json.dumps(currentJbiState)
except:
print("没有拿到返回值result")
returnFalsedefcheck_robot_type(self,result,robot_type_list):
""" 验证SDK和配置文件中的机器人类型是否正确 :param result: SDK获取到的机器人类型 :param robot_type_list: 配置文件中读取到的机器人类型 :return: """try:
result_type=result["result"]
ifresult_typeinrobot_type_list[0]:
print("SDK返回的机器人类型:",result_type)
print("SSH配置文件读取的机器人类型",robot_type_list[0])
returnTrueelifresult_typenotinrobot_type_list[0]:
print("SDK返回的机器人类型:", result_type)
print("SSH配置文件读取的机器人类型", robot_type_list[0])
returnFalseexcept:
print("未获取到机器人类型")
return"未获取到机器人类型"defcheck_robot_input_output(self,result):
try:
io_result=json.loads(result["result"])
ifio_result==0orio_result==1:
print("获取到IO状态为:",str(io_result))
returnTrueelse:
print("机器人IO状态错误:",json.dumps(result))
returnFalseexcept:
print("没有拿到返回值result")
return"未获得机器人IO状态"defcheck_get_linux(self,result,ssh_result,num):
""" :param result: SDK返回的数据 :param ssh_result: 配置文件中读取的数据 :param num: 读取list中一共多少个数据 :return: """try:
get_linux=result["result"]
ifget_linux==ssh_result[num]:
print("SDK返回的数据:",get_linux)
print("SSH配置文件读取的数据:",ssh_result[num])
returnTrueelse:
returnFalseexcept:
print("暂无数据对比")
returnFalsedefcheck_CollisionEnable(self,result):
""" 判断碰撞使能接口数据是否正确 :param result: :return: """try:
ifresult["result"] =="0"orresult["result"] =="1":
returnint(result["result"])
else:
returnFalseexcept:
print("暂无数据对比")
returnFalsedefcheck_CollisionSensitivity(self,result):
""" 校验SDK获取的碰撞灵敏度接口数据是否正确 :param result: :return: """try:
if10<=int(result["result"]) <=100:
returnint(result["result"])
else:
returnFalseexcept:
print("暂无数据校验")
returnFalsedefcheck_robot_registers(self, currentRegister, forwardLenth):
try:
registers=json.loads(currentRegister["result"])
current_lenth=len(registers)
ifcurrent_lenth!=forwardLenth:
print("机器人获取多个虚拟IO错误,返回列表长度不正确",json.dumps(currentRegister))
returncurrentRegisterforiteminregisters:
ifnotisinstance(item, int):
print("机器人获取多个虚拟IO错误",json.dumps(currentRegister))
returncurrentRegisterprint("机器人获取多个虚拟IO正确",str(registers))
returnTrueexcept:
print("没有拿到返回值result")
return"未获得机器人多个虚拟IO状态"defcheck_Speed(self,result):
""" 校验SDK获取的机器人运行速度接口数据是否正确 :param result: :return: """try:
if0.05<=float(result["result"]) <=100:
returnfloat(result["result"])
else:
returnFalseexcept:
print("暂无数据校验")
returnFalsedefcheck_SDK_linux_params(self,replace_result,get_linux_params_xml):
""" 校验SDK返回的安全参数和linux配置文件中读取的参数 :param get_linux_params_xml: :param replace_result: :return: """result_params_num=list(map(float, replace_result))
linux_params_xml_num=list(map(float, get_linux_params_xml))
ifresult_params_num==linux_params_xml_num:
print("数据一致")
print("SDK获取到的数据",result_params_num)
print("配置文件读取到的数据",linux_params_xml_num)
returnTrueelse:
print("数据不一致")
print("SDK获取到的数据", result_params_num)
print("配置文件读取到的数据", linux_params_xml_num)
returnFalsedefcheck_tt_state(self, result):
""" 校验机器人获取是否处于透传状态的结果是否正确 :param result: :return: """try:
state=json.loads(result["result"])
ifstate==0orstate==1:
returnstateelse:
print("获取当前是否处于透传状态", json.dumps(result))
returnFalseexcept:
print("没有拿到result")
returnFalsedefcheck_FlangeButton(self,FlangeButton):
""" 获取机器人末端按钮 :param FlangeButton: result拿到的参数区间0-2 :return: """try:
robot_mode_data=FlangeButton["result"]
if0<=int(robot_mode_data) <=2:
print("0:禁用,1:拖动,2:记点")
returnint(robot_mode_data)
else:
return"机器人当前state状态:"+FlangeButtonexcept:
print("没有拿到返回值result")
returnFalsedefcheck_getAlarmNum(self,getAlarmNum):
""" 校验机械臂本体异常情况 :param getAlarmNum: result拿到int数 :return: """try:
alarmnum=len(getAlarmNum["result"].replace('"', "").split(","))
ifalarmnum==5:
print("获取到",alarmnum,"错误数据")
returnTrueelse:
print("获取到",alarmnum,"错误数据")
returnFalseexcept:
print("没有拿到返回值result")
returnNonedefcheck_get_joint_speed(self,get_joint_speed):
""" 校验机械臂本体异常情况 :param get_joint_speed: result拿到int数 :return: """try:
alarmnum=len(get_joint_speed["result"].replace("[", "").replace("]", "").split(","))
ifalarmnum==8:
print("获取到8条数据:",get_joint_speed["result"])
returnTrueelse:
print("获取到错误数据:",get_joint_speed["result"])
returnFalseexcept:
print("没有拿到返回值result")
returnNonedefcheck_trajectory(self, current_result):
""" 校验机器人检查时间戳点位传送状态 :param result: :return: """try:
result=json.loads(current_result["result"])
ifresultin [0, -1, -2, -3]:
returnresultelse:
print("获取当前时间戳传送点位状态错误", json.dumps(current_result))
returnFalseexcept:
print("没有拿到返回值result")
returnNone