first commit
This commit is contained in:
216
Model/FeedModel.py
Normal file
216
Model/FeedModel.py
Normal file
@ -0,0 +1,216 @@
|
||||
import configparser
|
||||
|
||||
import Constant
|
||||
from Model.Position import Real_Position
|
||||
|
||||
|
||||
class LineModel:
|
||||
def __init__(self,index=9):
|
||||
self.id = index
|
||||
self.name = '未定义'
|
||||
self.positions = []
|
||||
self.dropline_id = index
|
||||
self.section = f'{Constant.feedLine_set_section}{index}'
|
||||
|
||||
def read_line_model(self,config_reader,index:int):
|
||||
|
||||
self.section = f'FeedLine{index}'
|
||||
|
||||
self.id = config_reader.getint(self.section, 'id')
|
||||
self.name = config_reader.get(self.section, 'name')
|
||||
self.dropline_id = config_reader.get(self.section, 'dropline_id')
|
||||
for i in range(1, Constant.MAX_Position_num):
|
||||
if config_reader.has_section(f'{Constant.position_set_section}{i}'):
|
||||
position = PositionModel()
|
||||
position.read_position_model(config_reader,i)
|
||||
if position.lineId == self.id:
|
||||
self.positions.append(position)
|
||||
self.positions = sorted(self.positions, key=lambda x: x.order)
|
||||
|
||||
|
||||
|
||||
|
||||
def save_line_model(self,config_reader):
|
||||
if not config_reader.has_section(self.section):
|
||||
config_reader.add_section(self.section)
|
||||
config_reader.set(self.section, 'id', str(self.id))
|
||||
config_reader.set(self.section, 'name', self.name)
|
||||
for i in range(len(self.positions)):
|
||||
self.positions[i].save_position_model(config_reader)
|
||||
|
||||
|
||||
class PositionModel:
|
||||
def __init__(self,index=99):
|
||||
self.X = 0.0
|
||||
self.Y = 0.0
|
||||
self.Z = 0.0
|
||||
self.U = 0.0
|
||||
self.V = 0.0
|
||||
self.W = 0.0
|
||||
self.id = index
|
||||
self.order = 0
|
||||
self.lineId = 0
|
||||
self.status = 0
|
||||
self.lineType = 0
|
||||
self.section = f'Position{index}'
|
||||
|
||||
pass
|
||||
def init_position(self,real_pos:Real_Position):
|
||||
self.set_position(real_pos)
|
||||
self.id = 0
|
||||
self.order = 0
|
||||
self.status = 3
|
||||
|
||||
|
||||
def read_position_model(self,config_reader,index:int):
|
||||
self.section = f'Position{index}'
|
||||
self.X = config_reader.getfloat(self.section, 'X')
|
||||
self.Y = config_reader.getfloat(self.section, 'Y')
|
||||
self.Z = config_reader.getfloat(self.section, 'Z')
|
||||
self.U = config_reader.getfloat(self.section, 'U')
|
||||
self.V = config_reader.getfloat(self.section, 'V')
|
||||
self.W = config_reader.getfloat(self.section, 'W')
|
||||
self.id = config_reader.getint(self.section, 'id')
|
||||
self.order = config_reader.getint(self.section, 'order')
|
||||
self.lineId = config_reader.getint(self.section, 'lineId')
|
||||
self.status = config_reader.getint(self.section, 'status')
|
||||
self.lineType = config_reader.getint(self.section, 'lineType')
|
||||
|
||||
def get_position(self):
|
||||
real_pos = Real_Position()
|
||||
real_pos.init_position(self.X, self.Y, self.Z, self.U, self.V, self.W)
|
||||
if real_pos.X == -9999:
|
||||
return None
|
||||
return real_pos
|
||||
def set_position(self,real_pos:Real_Position):
|
||||
if real_pos == None:
|
||||
self.X = -9999
|
||||
self.Y = -9999
|
||||
self.Z = -9999
|
||||
self.U = -9999
|
||||
self.V = -9999
|
||||
self.W = -9999
|
||||
return
|
||||
self.X = real_pos.X
|
||||
self.Y = real_pos.Y
|
||||
self.Z = real_pos.Z
|
||||
self.U = real_pos.U
|
||||
self.V = real_pos.V
|
||||
self.W = real_pos.W
|
||||
def save_position_model(self,config_reader):
|
||||
if not config_reader.has_section(self.section):
|
||||
config_reader.add_section(self.section)
|
||||
config_reader.set(self.section, 'X', str(self.X))
|
||||
config_reader.set(self.section, 'Y', str(self.Y))
|
||||
config_reader.set(self.section, 'Z', str(self.Z))
|
||||
config_reader.set(self.section, 'U', str(self.U))
|
||||
config_reader.set(self.section, 'V', str(self.V))
|
||||
config_reader.set(self.section, 'W', str(self.W))
|
||||
config_reader.set(self.section, 'id', str(self.id))
|
||||
config_reader.set(self.section, 'order', str(self.order))
|
||||
config_reader.set(self.section, 'lineId', str(self.lineId))
|
||||
config_reader.set(self.section, 'status', str(self.status))
|
||||
config_reader.set(self.section, 'lineType', str(self.lineType))
|
||||
|
||||
class DropLineModel:
|
||||
def __init__(self,index=9):
|
||||
self.id = index
|
||||
self.name = '未定义'
|
||||
self.positions = []
|
||||
self.section = f'{Constant.droppoints_set_section}{index}'
|
||||
|
||||
def read_line_model(self,config_reader,index:int):
|
||||
|
||||
self.section = f'DropLine{index}'
|
||||
|
||||
self.id = config_reader.getint(self.section, 'id')
|
||||
self.name = config_reader.get(self.section, 'name')
|
||||
for i in range(1, Constant.MAX_DropPoints_num):
|
||||
if config_reader.has_section(f'{Constant.droppoints_set_section}{i}'):
|
||||
position = DropPositionModel()
|
||||
position.read_position_model(config_reader,i)
|
||||
if position.lineId == self.id:
|
||||
self.positions.append(position)
|
||||
self.positions = sorted(self.positions, key=lambda x: x.order)
|
||||
|
||||
|
||||
|
||||
|
||||
def save_line_model(self,config_reader):
|
||||
if not config_reader.has_section(self.section):
|
||||
config_reader.add_section(self.section)
|
||||
config_reader.set(self.section, 'id', str(self.id))
|
||||
config_reader.set(self.section, 'name', self.name)
|
||||
for i in range(len(self.positions)):
|
||||
self.positions[i].save_position_model(config_reader)
|
||||
|
||||
class DropPositionModel:
|
||||
def __init__(self,index=99):
|
||||
self.X = 0.0
|
||||
self.Y = 0.0
|
||||
self.Z = 0.0
|
||||
self.U = 0.0
|
||||
self.V = 0.0
|
||||
self.W = 0.0
|
||||
self.id = index
|
||||
self.order = 0
|
||||
self.lineId = 0
|
||||
self.status = 0
|
||||
self.lineType = 0
|
||||
self.section = f'DropPoints{index}'
|
||||
|
||||
def init_position(self,real_pos:Real_Position):
|
||||
self.set_position(real_pos)
|
||||
self.id = 0
|
||||
self.order = 0
|
||||
self.status = 3
|
||||
|
||||
|
||||
def read_position_model(self,config_reader,index:int):
|
||||
self.section = f'DropPoints{index}'
|
||||
self.X = config_reader.getfloat(self.section, 'X')
|
||||
self.Y = config_reader.getfloat(self.section, 'Y')
|
||||
self.Z = config_reader.getfloat(self.section, 'Z')
|
||||
self.U = config_reader.getfloat(self.section, 'U')
|
||||
self.V = config_reader.getfloat(self.section, 'V')
|
||||
self.W = config_reader.getfloat(self.section, 'W')
|
||||
self.id = config_reader.getint(self.section, 'id')
|
||||
self.order = config_reader.getint(self.section, 'order')
|
||||
self.lineId = config_reader.getint(self.section, 'lineId')
|
||||
self.status = config_reader.getint(self.section, 'status')
|
||||
self.lineType = config_reader.getint(self.section, 'lineType')
|
||||
def get_position(self):
|
||||
real_pos = Real_Position()
|
||||
real_pos.init_position(self.X, self.Y, self.Z, self.U, self.V, self.W)
|
||||
if real_pos.X == -9999:
|
||||
return None
|
||||
return real_pos
|
||||
def set_position(self,real_pos:Real_Position):
|
||||
if real_pos == None:
|
||||
self.X = -9999
|
||||
self.Y = -9999
|
||||
self.Z = -9999
|
||||
self.U = -9999
|
||||
self.V = -9999
|
||||
self.W = -9999
|
||||
return
|
||||
self.X = real_pos.X
|
||||
self.Y = real_pos.Y
|
||||
self.Z = real_pos.Z
|
||||
self.U = real_pos.U
|
||||
self.V = real_pos.V
|
||||
self.W = real_pos.W
|
||||
def save_position_model(self,config_reader):
|
||||
if not config_reader.has_section(self.section):
|
||||
config_reader.add_section(self.section)
|
||||
config_reader.set(self.section, 'X', str(self.X))
|
||||
config_reader.set(self.section, 'Y', str(self.Y))
|
||||
config_reader.set(self.section, 'Z', str(self.Z))
|
||||
config_reader.set(self.section, 'U', str(self.U))
|
||||
config_reader.set(self.section, 'V', str(self.V))
|
||||
config_reader.set(self.section, 'W', str(self.W))
|
||||
config_reader.set(self.section, 'id', str(self.id))
|
||||
config_reader.set(self.section, 'order', str(self.order))
|
||||
config_reader.set(self.section, 'lineId', str(self.lineId))
|
||||
config_reader.set(self.section, 'status', str(self.status))
|
||||
config_reader.set(self.section, 'lineType', str(self.lineType))
|
||||
90
Model/Position.py
Normal file
90
Model/Position.py
Normal file
@ -0,0 +1,90 @@
|
||||
import math
|
||||
|
||||
from Constant import position_accuracy_command
|
||||
from Constant import position_accuracy_action
|
||||
class Position:
|
||||
def __init__(self):
|
||||
self.X = 0.0
|
||||
self.Y = 0.0
|
||||
self.Z = 0.0
|
||||
self.U = 0.0
|
||||
self.V = 0.0
|
||||
self.W = 0.0
|
||||
self.a = 0.0
|
||||
self.b = 0.0
|
||||
self.c = 0.0
|
||||
|
||||
|
||||
def compare(self,position,is_action=False):
|
||||
# distance = math.sqrt((self.X-position.X)**2+
|
||||
# (self.Y-position.Y)**2+
|
||||
# (self.Z - position.Z)**2+
|
||||
# (self.U - position.U)**2+
|
||||
# (self.V - position.V)**2+
|
||||
# (self.W - position.W) ** 2)
|
||||
distance = math.sqrt((self.X - position.X) ** 2 +
|
||||
(self.Y - position.Y) ** 2 +
|
||||
(self.Z - position.Z) ** 2 )
|
||||
if distance<=(position_accuracy_action if is_action else position_accuracy_command):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# def compare(self,position):
|
||||
# if self.X-position.X<position_accuracy and \
|
||||
# self.Y-position.Y<position_accuracy and \
|
||||
# self.Z - position.Z < position_accuracy and \
|
||||
# self.U - position.U < position_accuracy and \
|
||||
# self.V - position.V < position_accuracy and \
|
||||
# self.W - position.W < position_accuracy:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
# pass
|
||||
|
||||
def is_error_angel_move(self,position,interval):
|
||||
if self.X - position.X >= interval or \
|
||||
self.Y - position.Y >= interval or \
|
||||
self.Z - position.Z >= interval or \
|
||||
self.U - position.U >= interval or \
|
||||
self.V - position.V >= interval or \
|
||||
self.W - position.W >= interval:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
pass
|
||||
"""
|
||||
摄像头识别位置和角度
|
||||
"""
|
||||
class Detection_Position(Position):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def init_position(self,X,Y,Z,U,V,W):
|
||||
self.X = X
|
||||
self.Y = Y
|
||||
self.Z = Z
|
||||
self.U = U
|
||||
self.V = V
|
||||
self.W = W
|
||||
|
||||
|
||||
class Real_Position(Position):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def init_position(self, X, Y, Z, U, V, W):
|
||||
self.X = X
|
||||
self.Y = Y
|
||||
self.Z = Z
|
||||
self.U = U
|
||||
self.V = V
|
||||
self.W = W
|
||||
return self
|
||||
|
||||
# def init_position(self, position):
|
||||
# return self.init_position(position.X,position.Y,position.Z,position.U,position.V,position.W)
|
||||
|
||||
def to_string(self):
|
||||
return "X:{:.3f},Y:{:.3f},Z:{:.3f},U:{:.3f},V:{:.3f},W:{:.3f}".format(self.X,self.Y,self.Z,self.U,self.V,self.W)
|
||||
0
Model/Robot.py
Normal file
0
Model/Robot.py
Normal file
198
Model/RobotModel.py
Normal file
198
Model/RobotModel.py
Normal file
@ -0,0 +1,198 @@
|
||||
from enum import Enum
|
||||
|
||||
from Model.Position import Real_Position
|
||||
|
||||
|
||||
class MoveType(Enum):
|
||||
AXIS = 4
|
||||
WORLD = 10
|
||||
Cure = 17
|
||||
|
||||
class DATARequest:
|
||||
def __init__(self):
|
||||
self.dsID = 'www.hc-system.com.RemoteMonitor'
|
||||
self.reqType = 'query'
|
||||
self.queryAddr = []
|
||||
def toString(self):
|
||||
model_str = '{'+f'"dsID":"{self.dsID}","reqType":"{self.reqType}","queryAddr":[' \
|
||||
f'{self.queryAddr[0].toString()}]'+'}'
|
||||
return model_str
|
||||
|
||||
|
||||
|
||||
class DataAddress:
|
||||
def __init__(self):
|
||||
self.version = ''
|
||||
self.curMold = ''
|
||||
self.counterList = ''
|
||||
self.counter_n = ''
|
||||
self.curMode = 0
|
||||
self.boardIONum = ''
|
||||
self.input_n = ''
|
||||
self.output_n = 0
|
||||
self.axisNum = '6'
|
||||
self.axis_n = ''
|
||||
self.world_0 = 0
|
||||
self.world_1 = 0
|
||||
self.world_2 = 0
|
||||
self.world_3 = 0
|
||||
self.world_4 = 0
|
||||
self.world_5 = 0
|
||||
self.axis_0 = 0
|
||||
self.axis_1 = 0
|
||||
self.axis_2 = 0
|
||||
self.axis_3 = 0
|
||||
self.axis_4 = 0
|
||||
self.axis_5 = 0
|
||||
self.curAlarm = 0
|
||||
self.curCycle = ''
|
||||
self.lastCycle = ''
|
||||
self.machineName = ''
|
||||
self.curTorque_n = ''
|
||||
self.curSpeed_n = ''
|
||||
self.curAccount = ''
|
||||
self.origin = ''
|
||||
self.moldList = ''
|
||||
self.isMoving = False
|
||||
self.M_n = ''
|
||||
self.RemoteCmdLen = 0
|
||||
self.toolCoord=0
|
||||
|
||||
#return
|
||||
def setPosition(self,w0,w1,w2,w3,w4,w5,a0,a1,a2,a3,a4,a5):
|
||||
self.world_0 = float(w0)
|
||||
self.world_1 = float(w1)
|
||||
self.world_2 = float(w2)
|
||||
self.world_3 = float(w3)
|
||||
self.world_4 = float(w4)
|
||||
self.world_5 = float(w5)
|
||||
self.axis_0 = float(a0)
|
||||
self.axis_1 = float(a1)
|
||||
self.axis_2 = float(a2)
|
||||
self.axis_3 = float(a3)
|
||||
self.axis_4 = float(a4)
|
||||
self.axis_5 = float(a5)
|
||||
|
||||
def getRealPosition(self):
|
||||
real_position = Real_Position().init_position(self.world_0,self.world_1,self.world_2,self.world_3,self.world_4,self.world_5)
|
||||
return real_position
|
||||
|
||||
def getAnglePosition(self):
|
||||
real_position = Real_Position().init_position(self.axis_0,self.axis_1,self.axis_2,self.axis_3,self.axis_4,self.axis_5)
|
||||
return real_position
|
||||
def get_IO_bits(self):
|
||||
io_bits_str = format(self.output_n, '032b')[::-1]
|
||||
io_bits_arry = [bit == '1' for bit in io_bits_str]
|
||||
return io_bits_arry
|
||||
|
||||
def setAngle(self,a0,a1,a2,a3,a4,a5):
|
||||
pass
|
||||
|
||||
def toString(self):
|
||||
model_str = f'"curMode",' \
|
||||
f'"world-0","world-1","world-2","world-3","world-4","world-5","axis-0","axis-1","axis-2","axis-3","axis-4","axis-5",' \
|
||||
f'"curAlarm","isMoving","RemoteCmdLen","toolCoord","input-n","output-n","curSpeed-n"'
|
||||
return model_str
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DATAReply:
|
||||
def __init__(self):
|
||||
self.dsID = ''
|
||||
self.reqType = ''
|
||||
self.queryData = []
|
||||
|
||||
|
||||
|
||||
def JsonToObject(self):
|
||||
return
|
||||
|
||||
class CMDRequest:
|
||||
def __init__(self):
|
||||
self.dsID = 'www.hc-system.com.RemoteMonitor'
|
||||
self.reqType = 'command'
|
||||
self.cmdData = []
|
||||
return
|
||||
def toString(self):
|
||||
model_str = '{'+f'"dsID":"{self.dsID}","reqType":"{self.reqType}","cmdData":'
|
||||
if len(self.cmdData) != 0:
|
||||
model_str = model_str+"["+','.join(f'"{item}"' for item in self.cmdData)+"]"+"}"
|
||||
else:
|
||||
model_str = model_str+"}"
|
||||
return model_str
|
||||
|
||||
class CMDReply:
|
||||
def __init__(self):
|
||||
self.dsID = 'www.hc-system.com.RemoteMonitor'
|
||||
self.reqType = 'command'
|
||||
self.cmdData = []
|
||||
return
|
||||
|
||||
|
||||
class Instruction:
|
||||
def __init__(self):
|
||||
self.oneshot = 1
|
||||
self.action = 4 #4 自由路径 10 姿势直线 17 姿势曲线
|
||||
self.m0 = 0.0
|
||||
self.m1 = 0.0
|
||||
self.m2 = 0.0
|
||||
self.m3 = 0.0
|
||||
self.m0_p = 0.0
|
||||
self.m1_p = 0.0
|
||||
self.m2_p = 0.0
|
||||
self.m3_p = 0.0
|
||||
self.m4_p = 0.0
|
||||
self.m5_p = 0.0
|
||||
self.ckStatus = '0x3F'
|
||||
self.speed = 10
|
||||
self.smooth = 0
|
||||
self.tool=2
|
||||
self.IO = False
|
||||
self.type = 0
|
||||
self.io_status=1
|
||||
self.point = 0
|
||||
self.delay = 0
|
||||
|
||||
def toString(self):
|
||||
if not self.IO :
|
||||
model_str = f'"oneshot":"{self.oneshot}","action":"{self.action}","m0":"{self.m0}","m1":"{self.m1}","m2":"{self.m2}",' \
|
||||
f'"m3":"{self.m3}","ckStatus":"{self.ckStatus}","speed":"{self.speed}",' \
|
||||
f'"delay":"{self.delay}","smooth":"{self.smooth}","tool":"{self.tool}"'
|
||||
if self.action == 17:
|
||||
model_str = f'"oneshot":"{self.oneshot}","action":"{self.action}","m0":"{self.m0}","m1":"{self.m1}","m2":"{self.m2}",' \
|
||||
f'"m3":"{self.m3}","m0_p":"{self.m0_p}","m1_p":"{self.m1_p}","m2_p":"{self.m2_p}",' \
|
||||
f'"m3_p":"{self.m3_p}","ckStatus":"{self.ckStatus}","speed":"{self.speed}",' \
|
||||
f'"delay":"{self.delay}","smooth":"{self.smooth}","tool":"{self.tool}"'
|
||||
else:
|
||||
model_str = f'"oneshot":"{self.oneshot}","action":"{200}","type":"{self.type}","io_status":"{self.io_status}"' \
|
||||
f',"point":"{self.point}","delay":"{self.delay}"'
|
||||
return model_str
|
||||
|
||||
|
||||
|
||||
|
||||
class CMDInstructRequest:
|
||||
def __init__(self):
|
||||
self.dsID = 'www.hc-system.com.HCRemoteCommand'
|
||||
self.reqType = "AddRCC"
|
||||
self.emptyList = '0' #清空机械臂的远程命令数据
|
||||
self.instructions = []
|
||||
|
||||
def toString(self):
|
||||
model_str = '{'+f'"dsID":"{self.dsID}","reqType":"{self.reqType}","emptyList":"{self.emptyList}"'
|
||||
if len(self.instructions) != 0:
|
||||
model_str = model_str+',"instructions":'+"[{"+self.instructions[0].toString()+"}]"+"}"
|
||||
else:
|
||||
model_str = model_str+',"instructions":'+"[]"+"}" #model_str+"}"
|
||||
return model_str
|
||||
|
||||
class CMDInstructReply:
|
||||
|
||||
def __init__(self):
|
||||
self.dsID = 'www.hc-system.com.HCRemoteCommand'
|
||||
self.reqType = 'command'
|
||||
self.cmdReply = []
|
||||
return
|
||||
|
||||
BIN
Model/__pycache__/FeedModel.cpython-39.pyc
Normal file
BIN
Model/__pycache__/FeedModel.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Model/__pycache__/Position.cpython-39.pyc
Normal file
BIN
Model/__pycache__/Position.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Model/__pycache__/RobotModel.cpython-39.pyc
Normal file
BIN
Model/__pycache__/RobotModel.cpython-39.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user