合并35kg

This commit is contained in:
2025-09-30 14:44:12 +08:00
parent e764586cc7
commit bda47e10e9
15 changed files with 1173 additions and 17665 deletions

View File

@ -268,7 +268,7 @@ class Feeding(QObject):
# --- 新增: 用于码垛模式的投料点索引 ---
self.current_drop_index = 0
self.drop_manager = DropPositionManager()
# self.drop_manager = DropPositionManager()
pass
def close_feed(self):

View File

@ -75,7 +75,7 @@ class FeedPosition:
self.position = position
class FeedLine:
def __init__(self, id, name, feed_positions:list,remain_count:int):
def __init__(self, id, name, feed_positions:list,remain_count:int,drop_manage:DropPositionManager):
self.feed_positions = copy.deepcopy(feed_positions)
self.feeding2end_pos_index = 0
@ -83,7 +83,7 @@ class FeedLine:
self.start2take_pos_index = 0
self.name = name
self.id = id
self.drop_manager = DropPositionManager()
self.drop_manager = drop_manage
# 初始化各个阶段的位置列表
self.feeding_to_end = []
@ -479,34 +479,37 @@ class Feeding(QObject):
self.next_position()
return
#初始点无论如何先打开夹爪
self.relay_controller.close(clamp=True)
#重新抓去信号料带
self.take_sensor_signal=False
self.relay_controller.sensor2_ready=True
#去除list.ini读取抓取点20250915
#self.feedConfig.feedLine.set_take_position(self.detect.detect_position, 0)
#self.feedConfig.feedLine.set_take_position(real_position, 0)#必须设置
# 一直等待传感器2信号永不超时
# TODO:逻辑需改变不能用while循环
if Constant.DebugPosition:
self.take_sensor_signal=True
while True:
# sensors = self.relay_controller.get_all_device_status('sensors')
# sensor2_value = sensors.get(self.relay_controller.SENSOR2, False)
if self.take_sensor_signal:
self.log_signal.emit(logging.INFO, "传感器2检测到料包到位开始执行抓取")
break # ✅ 条件满足,跳出循环,继续执行下面的代码
else:
if self.feedStatus == FeedStatus.FNone:
return
time.sleep(1) # 每秒检查一次
#第二次执行FeedStatus.FPhoto时改变码垛点
# self.camera_img.save_frame_path()
self.feedConfig.feedLine.set_feeding_to_end()
# self.take_photo_sigal.emit()
self.next_position()
self.log_signal.emit(logging.INFO, Constant.str_sys_runing2)
if self.relay_controller.close(clamp=True):
#重新抓去信号料带
self.take_sensor_signal=False
self.relay_controller.sensor2_ready=True
#去除list.ini读取抓取点20250915
#self.feedConfig.feedLine.set_take_position(self.detect.detect_position, 0)
#self.feedConfig.feedLine.set_take_position(real_position, 0)#必须设置
# 一直等待传感器2信号永不超时
# TODO:逻辑需改变不能用while循环
if Constant.DebugPosition:
self.take_sensor_signal=True
while True:
# sensors = self.relay_controller.get_all_device_status('sensors')
# sensor2_value = sensors.get(self.relay_controller.SENSOR2, False)
if self.take_sensor_signal:
self.log_signal.emit(logging.INFO, "传感器2检测到料包到位开始执行抓取")
break # ✅ 条件满足,跳出循环,继续执行下面的代码
else:
if self.feedStatus == FeedStatus.FNone:
return
time.sleep(1) # 每秒检查一次
#第二次执行FeedStatus.FPhoto时改变码垛点
# self.camera_img.save_frame_path()
self.feedConfig.feedLine.set_feeding_to_end()
# self.take_photo_sigal.emit()
self.next_position()
self.log_signal.emit(logging.INFO, Constant.str_sys_runing2)
else:
self.log_signal.emit(logging.ERROR, Constant.str_clamp_open_error)
time.sleep(2)
# self.feedStatus = FeedStatus.FTake
elif self.feedStatus == FeedStatus.FTake:
@ -534,8 +537,11 @@ class Feeding(QObject):
# 移动到下一个抓取点
# 更新丢包点: 如果需要根据放置情况调整下次抓取
self.relay_controller.open(clamp=True)
self.next_position(self.is_reverse)
if self.relay_controller.open(clamp=True):
self.next_position(self.is_reverse)
else:
self.log_signal.emit(logging.ERROR, Constant.str_clamp_close_error)
time.sleep(2)
#self.feedConfig.feedLine.set_drop_position(real_position)#我想在这里读取我的一个ini文件值里面有很多个drop点每一次索引递增的点

Binary file not shown.

View File

@ -8,7 +8,7 @@ import Constant
class DropPositionManager:
def __init__(self, config_path=Constant.dropLine_set_file):
def __init__(self, config_path):
self.config_path = config_path
self.config = configparser.ConfigParser()
self._load_config()
@ -167,11 +167,14 @@ class DropPositionManager:
return None
#region 前端UI编辑码垛点位调用方法
def load_path_points(self,lineid: int) ->Optional[LineModel]:
"""根据lineid加载所有码垛的路径信息"""
#默认码垛的lineid从10开始
_lineid=lineid+10
if self.config_path==Constant.dropLine_set_file_35:
_lineid=lineid+11
else:
_lineid=lineid+10
line_model = LineModel(_lineid)
line_model.line_category = 2
line_model.id = _lineid
@ -255,10 +258,13 @@ class DropPositionManager:
def save_path_points(self, line_model: LineModel):
"""根据lineid保存所有码垛的路径信息"""
#默认码垛的lineid从10开始,保存的时候减一
_lineid=line_model.id-10
if self.config_path==Constant.dropLine_set_file_35:
_lineid=line_model.id-11
else:
_lineid=line_model.id-10
if _lineid<=0:
return
self.config.read(Constant.dropLine_set_file, encoding='utf-8')
self.config.read(self.config_path, encoding='utf-8')
# 查找主表 DropLineX
main_section = f"{Constant.dropLine_set_section}{_lineid}"
if not self.config.has_section(main_section):
@ -267,7 +273,7 @@ class DropPositionManager:
self.config.set(main_section, "id", str(_lineid))
_current_reset_index=1
_current_mid_index=1
_current_drop_section_val=self._current_drop_section[main_section]
_current_drop_section_val=self._get_max_drop_section()
# 保存每个DropPoints
for i, pos in enumerate(line_model.positions):
if pos.lineId == _lineid or pos.lineId == line_model.id:
@ -300,49 +306,25 @@ class DropPositionManager:
#保存数据
pos.save_position_model(self.config)
with open(Constant.dropLine_set_file, 'w', encoding='utf-8') as f:
with open(self.config_path, 'w', encoding='utf-8') as f:
self.config.write(f)
def del_drop_point(self,section):
self.config.read(Constant.dropLine_set_file, encoding = 'utf-8')
self.config.read(self.config_path, encoding = 'utf-8')
self.config.remove_section(section)
with open(Constant.dropLine_set_file, 'w', encoding='utf-8') as f:
with open(self.config_path, 'w', encoding='utf-8') as f:
self.config.write(f)
def _get_point_debug_info(manager, pos, model):
config = manager.config
for sec in config.sections():
if sec.startswith("DropPoints"):
try:
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
point_id = config.getint(sec, "id")
return f"📌 DropPoints{point_id} | id={point_id}"
except: pass
elif sec.startswith("DropMidPoint"):
try:
parts = sec.split('-')
if len(parts) != 2: continue
point_id = int(''.join(filter(str.isdigit, parts[0])))
level = int(parts[1])
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
return f"📍 DropMidPoint{point_id}-{level} | id={point_id}, level={level}"
except: pass
elif sec.startswith("ResetPoint"):
try:
parts = sec.split('-')
if len(parts) != 2: continue
point_id = int(''.join(filter(str.isdigit, parts[0])))
level = int(parts[1])
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
return f"🔙 ResetPoint{point_id}-{level} | id={point_id}, level={level}"
except: pass
return "❓ 未知点位"
def _get_max_drop_section(self):
"""获取最大的DropPoints序号"""
max_section = 1
for section in self.config.sections():
if section.startswith("DropPoints"):
num_part = int(section.replace("DropPoints", "0"))
if num_part > max_section:
max_section = num_part
return max_section
#endregion
# 测试
if __name__ == "__main__":
# manager = DropPositionManager("drop.ini")