From 7b3161e949bb32f91d5cebc9d52147198e360b6b Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 06 六月 2025 09:03:25 +0800
Subject: [PATCH] 1.增加菜单项设置send able等信号,用于模拟测试;

---
 SourceCode/Bond/Servo/CMaster.cpp |  216 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 181 insertions(+), 35 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index d536f7c..41b9205 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -279,6 +279,32 @@
 
 	unsigned CMaster::DispatchProc()
 	{
+		// 优先考虑的类型和次要类型
+		// 一种情况,如果不分主次,一直搬G1, 等到Bonder1和Bonder2都放了G1, Aligner也放了G1,
+		// Bonder1和Bonder2需要的G2就过不来了
+		// 最基本的实现,可以G2和G2轮流搬送,但最好根据Bonder的需求来决定
+		MaterialsType primaryType, secondaryType;
+
+
+		// 各种机器
+		CLoadPort* pLoadPort1 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT1);
+		CLoadPort* pLoadPort2 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT2);
+		CFliper* pFliper = (CFliper*)getEquipment(EQ_ID_FLIPER);
+		CVacuumBake* pVacuumBack = (CVacuumBake*)getEquipment(EQ_ID_VACUUMBAKE);
+		CAligner* pAligner = (CAligner*)getEquipment(EQ_ID_ALIGNER);
+		CBonder* pBonder1 = (CBonder*)getEquipment(EQ_ID_Bonder1);
+		CBonder* pBonder2 = (CBonder*)getEquipment(EQ_ID_Bonder2);
+		CBakeCooling* pBakeCooling = (CBakeCooling*)getEquipment(EQ_ID_BAKE_COOLING);
+
+		ASSERT(pLoadPort1);
+		ASSERT(pLoadPort2);
+		ASSERT(pFliper);
+		ASSERT(pVacuumBack);
+		ASSERT(pAligner);
+		ASSERT(pBonder1);
+		ASSERT(pBonder2);
+		ASSERT(pBakeCooling);
+
 		while (1) {
 			// 待退出信号或时间到
 			HANDLE hEvents[] = { m_hEventDispatchThreadExit[0], m_hDispatchEvent };
@@ -310,38 +336,135 @@
 			// 调度逻辑处理
 			else if (m_state == MASTERSTATE::RUNNING) {
 				unlock();
-				LOGI("调度处理中...");
+				// LOGI("调度处理中...");
 
 				lock();
 				if (m_pActiveRobotTask != nullptr) {
 					unlock();
 					// 检测到当前有正在下午的任务,确保当前任务完成或中止后继续
-					LOGI("检测到当前有正在下午的任务,确保当前任务完成或中止后继续...");
+					// LOGI("检测到当前有正在下午的任务,确保当前任务完成或中止后继续...");
 					continue;
 				}
 
-				// LoadPort -> Fliper(G2)
-				CLoadPort* pLoadPort1 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT1);
-				CLoadPort* pLoadPort2 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT2);
-				CFliper* pFliper = (CFliper*)getEquipment(EQ_ID_FLIPER);
-				CVacuumBake* pVacuumBack = (CVacuumBake*)getEquipment(EQ_ID_VACUUMBAKE);
-				ASSERT(pLoadPort1);
-				ASSERT(pLoadPort2);
-				ASSERT(pFliper);
-				ASSERT(pVacuumBack);
 
-				m_pActiveRobotTask = createTransferTask(pLoadPort1, pFliper);
+				// 此处检测优先类型和次要类型(G1或G2)
+				// 如果其中一Bonder有单个玻璃,优先取它的配对类型,否则无所谓了
+				primaryType = MaterialsType::G1;
+				secondaryType = MaterialsType::G2;
+				if ((!pBonder1->canPlaceGlassInSlot(0) && !pBonder1->canPlaceGlassInSlot(1))
+					&& (!pBonder2->canPlaceGlassInSlot(0) && !pBonder2->canPlaceGlassInSlot(1))) {
+					// 如果G1和G2都满了,那就看Aligner, 如果Aligner有玻璃为G1, 则取G2
+					CGlass* pGlass = pAligner->getGlassFromSlot(1);
+					if (pGlass != nullptr && pGlass->getType() == MaterialsType::G1) {
+						primaryType = MaterialsType::G2;
+						secondaryType = MaterialsType::G1;
+					}
+				}
+				else if ((pBonder1->canPlaceGlassInSlot(0) && !pBonder1->canPlaceGlassInSlot(1))
+					|| (pBonder2->canPlaceGlassInSlot(0) && !pBonder2->canPlaceGlassInSlot(1))) {
+					primaryType = MaterialsType::G2;
+					secondaryType = MaterialsType::G1;
+				}
+
+
+				// Bonder -> BakeCooling
+				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder1, pBakeCooling, primaryType, secondaryType);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
 					LOGI("创建新任务<%s>...", strDescription.c_str());
 					continue;
 				}
 
-				m_pActiveRobotTask = createTransferTask(pLoadPort2, pFliper);
+				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder2, pBakeCooling, primaryType, secondaryType);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+				// Aligner -> Bonder
+				m_pActiveRobotTask = createTransferTask(pAligner, pBonder1, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+				m_pActiveRobotTask = createTransferTask(pAligner, pBonder2, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+
+				// Fliper(G2) -> Aligner
+				// VacuumBake(G1) -> Aligner
+				m_pActiveRobotTask = createTransferTask(pFliper, pAligner, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+				m_pActiveRobotTask = createTransferTask(pVacuumBack, pAligner, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+
+				// LoadPort -> Fliper(G2)
+				// LoadPort -> VacuumBake(G1)
+				CEquipment* pEqTar1 = pVacuumBack;
+				CEquipment* pEqTar2 = pFliper;
+				if (primaryType == MaterialsType::G2) {
+					pEqTar1 = pFliper;
+					pEqTar2 = pVacuumBack;
+				}
+				m_pActiveRobotTask = createTransferTask(pLoadPort1, pEqTar1, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+				m_pActiveRobotTask = createTransferTask(pLoadPort2, pEqTar1, primaryType, secondaryType);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
 					LOGI("创建新任务<%s>...", strDescription.c_str());
 					continue;
 				}
@@ -349,34 +472,27 @@
 
 
 				// LoadPort -> VacuumBake(G1)
-				m_pActiveRobotTask = createTransferTask(pLoadPort1, pVacuumBack);
+				m_pActiveRobotTask = createTransferTask(pLoadPort1, pEqTar2, primaryType, secondaryType);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
-					LOGI("创建新任务1<%s>...", strDescription.c_str());
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
 					continue;
 				}
 
-				m_pActiveRobotTask = createTransferTask(pLoadPort2, pVacuumBack);
+				m_pActiveRobotTask = createTransferTask(pLoadPort2, pEqTar2, primaryType, secondaryType);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
-					LOGI("创建新任务2<%s>...", strDescription.c_str());
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
 					continue;
 				}
-
-
-
-				// Fliper(G2) -> Aligner
-
-
-				// VacuumBake(G1) -> Aligner
-
-
-				// Aligner -> Bonder
-
-
-				// Bonder -> BakeCooling
 
 
 				// BakeCooling ->Measurement
@@ -552,6 +668,9 @@
 
 
 					lock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_FINISH);
+					}
 					delete m_pActiveRobotTask;
 					m_pActiveRobotTask = nullptr;
 				}
@@ -969,15 +1088,42 @@
 	}
 
 	static int taskSeqNo = 0;
-	CRobotTask* CMaster::createTransferTask(CEquipment* pSrcEq, CEquipment* pTarEq)
+	CRobotTask* CMaster::createTransferTask(CEquipment* pSrcEq, CEquipment* pTarEq,
+		MaterialsType primaryType/* = MaterialsType::G1*/, MaterialsType secondaryType/* = MaterialsType::G2*/)
 	{
 		CRobotTask* pTask = nullptr;
 		CSlot* pSrcSlot, * pTarSlot;
-		pTarSlot = pTarEq->getAvailableSlotForGlass(MaterialsType::G1);
-		pSrcSlot = pSrcEq->getNonEmptySlot(MaterialsType::G1);
+		pTarSlot = pTarEq->getAvailableSlotForGlass(primaryType);
+		pSrcSlot = pSrcEq->getProcessedSlot(primaryType);
 		if (pSrcSlot == nullptr || nullptr == pTarSlot) {
-			pTarSlot = pTarEq->getAvailableSlotForGlass(MaterialsType::G2);
-			pSrcSlot = pSrcEq->getNonEmptySlot(MaterialsType::G2);
+			pTarSlot = pTarEq->getAvailableSlotForGlass(secondaryType);
+			pSrcSlot = pSrcEq->getProcessedSlot(secondaryType);
+		}
+
+
+		if (pSrcSlot != nullptr && nullptr != pTarSlot) {
+			pTask = new CRobotTask();
+			pTask->setContext(pSrcSlot->getContext());
+			pTask->setRobotTransferParam(++taskSeqNo, 1, pSrcSlot->getPosition(),
+				pTarSlot->getPosition(), pSrcSlot->getNo(), pTarSlot->getNo());
+		}
+
+
+		return pTask;
+	}
+
+	CRobotTask* CMaster::createTransferTask_bonder_to_bakecooling(CEquipment* pSrcEq, CEquipment* pTarEq,
+		MaterialsType primaryType/* = MaterialsType::G1*/, MaterialsType secondaryType/* = MaterialsType::G2*/)
+	{
+		std::vector<int> slots = {1, 2};
+
+		CRobotTask* pTask = nullptr;
+		CSlot* pSrcSlot, * pTarSlot;
+		pTarSlot = pTarEq->getAvailableSlotForGlass2(primaryType, slots);
+		pSrcSlot = pSrcEq->getProcessedSlot(primaryType);
+		if (pSrcSlot == nullptr || nullptr == pTarSlot) {
+			pTarSlot = pTarEq->getAvailableSlotForGlass(secondaryType);
+			pSrcSlot = pSrcEq->getProcessedSlot(secondaryType);
 		}
 
 

--
Gitblit v1.9.3