From fcfe1d4a6c0f06adb4716914901ccc76a88d8dba Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 14 十一月 2025 13:52:10 +0800
Subject: [PATCH] 1.修复两个Job相关的问题;
---
SourceCode/Bond/Servo/CPageGraph1.cpp | 124 ++++++++++++++++++++++++++++++++++-------
1 files changed, 102 insertions(+), 22 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPageGraph1.cpp b/SourceCode/Bond/Servo/CPageGraph1.cpp
index 6378512..60f2ac4 100644
--- a/SourceCode/Bond/Servo/CPageGraph1.cpp
+++ b/SourceCode/Bond/Servo/CPageGraph1.cpp
@@ -41,6 +41,7 @@
// 瀹氭椂鍣�
#define TIMER_ID_DEVICE_STATUS 1 // 鐢ㄤ簬鍒濆鍖栬澶囩姸鎬�
#define TIMER_ID_ROBOT_STATUS 2 // 鐢ㄤ簬鍛ㄦ湡鍒锋柊鏈哄櫒浜轰綅缃�/鑷傜姸鎬�
+#define TIMER_ID_ROBOT_ANIMATION 3 //
// CPageGraph1 瀵硅瘽妗�
@@ -49,17 +50,29 @@
CPageGraph1::CPageGraph1(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_PAGE_GRAPH1, pParent)
{
- m_pGraph = nullptr;
- m_pObserver = nullptr;
- m_bIsRobotMoving = FALSE;
- m_crBkgnd = PAGE_GRPAH1_BACKGROUND_COLOR;
- m_hbrBkgnd = nullptr;
- m_lastRobotPosition = SERVO::ROBOT_POSITION::Port1;
- m_lastArmState[0] = FALSE;
- m_lastArmState[1] = FALSE;
+ // ===== 鍥惧舰鐣岄潰鐩稿叧鎴愬憳鍙橀噺鍒濆鍖� =====
+ m_pGraph = nullptr; // 鍥惧舰缁樺浘瀵硅薄
+ m_pObserver = nullptr; // 瑙傚療鑰呭璞★紙鍙兘鏄簨浠惰瀵熻�咃級
+ m_crBkgnd = PAGE_GRPAH1_BACKGROUND_COLOR; // 鑳屾櫙棰滆壊
+ m_hbrBkgnd = nullptr; // 鑳屾櫙鍒峰彞鏌�
- m_arm1Offset = LoadArmOffset("ARM1");
- m_arm2Offset = LoadArmOffset("ARM2");
+ // ===== 鏈哄櫒浜哄姩鐢荤姸鎬佸垵濮嬪寲 =====
+ m_bIsRobotMoving = FALSE; // 褰撳墠鏄惁姝e湪鍔ㄧ敾绉诲姩
+ m_nRobotMoveStartX = 0; // 鍔ㄧ敾璧峰 X 鍧愭爣
+ m_nRobotMoveEndX = 0; // 鍔ㄧ敾鐩爣 X 鍧愭爣
+ m_nRobotMoveSteps = 30; // 鍔ㄧ敾鎬绘鏁帮紙鍔ㄧ敾閫熷害鎺у埗锛�
+ m_nRobotMoveCurrentStep = 0; // 褰撳墠鍔ㄧ敾姝ユ暟
+ m_nRobotMoveStartAngle = 0.0f; // 鍔ㄧ敾璧峰瑙掑害
+ m_nRobotMoveEndAngle = 0.0f; // 鍔ㄧ敾鐩爣瑙掑害
+
+ // ===== 鏈哄櫒浜轰笂涓�娆$姸鎬佸垵濮嬪寲 =====
+ m_lastRobotPosition = SERVO::ROBOT_POSITION::Port1; // 涓婃鏈哄櫒浜轰綅缃紙榛樿 Port1锛�
+ m_lastArmState[0] = FALSE; // 涓婃鏈烘鑷�1 鐘舵�侊紙鏈崰鐢級
+ m_lastArmState[1] = FALSE; // 涓婃鏈烘鑷�2 鐘舵�侊紙鏈崰鐢級
+
+ // ===== 鏈烘鑷傜浉瀵瑰亸绉婚噺鍒濆鍖栵紙浠庨厤缃腑鍔犺浇锛� =====
+ m_arm1Offset = LoadArmOffset("ARM1"); // 鍔犺浇鏈烘鑷�1鍋忕Щ
+ m_arm2Offset = LoadArmOffset("ARM2"); // 鍔犺浇鏈烘鑷�2鍋忕Щ
//m_arm1Offset = { -30, -45 }; // ARM1 浠庝腑蹇冨悜宸�47, 鍚戜笂33
//m_arm2Offset = { 27, -45 }; // ARM2 浠庝腑蹇冨悜鍙�10, 鍚戜笂33
@@ -494,6 +507,32 @@
m_lastRobotPosition = position;
}
+void CPageGraph1::StartRobotMoveToPosition(SERVO::ROBOT_POSITION position)
+{
+ auto it = g_positionMap.find(position);
+ if (it == g_positionMap.end()) {
+ TRACE("Invalid robot position: %d\n", static_cast<int>(position));
+ return;
+ }
+
+ const RobotPositionMapping& mapping = it->second;
+
+ auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT);
+ if (!pImage) return;
+
+ m_nRobotMoveStartX = pImage->x;
+ m_nRobotMoveEndX = static_cast<int>(170 + mapping.percentage * (700 - 170));
+
+ m_nRobotMoveStartAngle = pImage->angle; // 璧峰瑙掑害锛堝綋鍓嶈搴︼級
+ m_nRobotMoveEndAngle = mapping.angle; // 鐩爣瑙掑害
+
+ m_nRobotMoveCurrentStep = 0;
+ m_targetRobotPosition = position;
+ m_bIsRobotMoving = TRUE;
+
+ SetTimer(TIMER_ID_ROBOT_ANIMATION, 16, nullptr);
+}
+
POINT CPageGraph1::LoadArmOffset(const std::string& armName)
{
std::string iniPath = GetConfigPath();
@@ -521,37 +560,37 @@
// 绉诲姩鍒版寚瀹氫綅缃� (娴嬭瘯浣跨敤)
if (pGraphNmhdr->dwData == INDICATE_LPORT1) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Port1);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Port1);
}
else if (pGraphNmhdr->dwData == INDICATE_LPORT2) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Port2);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Port2);
}
else if (pGraphNmhdr->dwData == INDICATE_LPORT3) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Port3);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Port3);
}
else if (pGraphNmhdr->dwData == INDICATE_LPORT4) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Port4);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Port4);
}
else if (pGraphNmhdr->dwData == INDICATE_ALIGNER) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Aligner);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Aligner);
}
else if (pGraphNmhdr->dwData == INDICATE_FLIPER) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Fliper);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Fliper);
}
else if (pGraphNmhdr->dwData == INDICATE_BONDER1) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Bonder1);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Bonder1);
}
else if (pGraphNmhdr->dwData == INDICATE_BONDER2) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Bonder2);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Bonder2);
}
else if (pGraphNmhdr->dwData == INDICATE_VACUUM_BAKE) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Bake);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Bake);
}
else if (pGraphNmhdr->dwData == INDICATE_BAKE_COOLING) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Cooling);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Cooling);
}
else if (pGraphNmhdr->dwData == INDICATE_MEASUREMENT) {
- MoveRobotToPosition(SERVO::ROBOT_POSITION::Measurement);
+ StartRobotMoveToPosition(SERVO::ROBOT_POSITION::Measurement);
}
*pResult = 0;
@@ -636,9 +675,50 @@
// 浣嶇疆淇℃伅鐘舵�佹樉绀�
if (robotData.position != m_lastRobotPosition) {
- MoveRobotToPosition(robotData.position);
+ StartRobotMoveToPosition(robotData.position);
}
}
+ else if (nIDEvent == TIMER_ID_ROBOT_ANIMATION) {
+ if (!m_bIsRobotMoving) {
+ KillTimer(TIMER_ID_ROBOT_ANIMATION);
+ return;
+ }
+
+ m_nRobotMoveCurrentStep++;
+
+ float progress = static_cast<float>(m_nRobotMoveCurrentStep) / m_nRobotMoveSteps;
+ if (progress >= 1.0f) {
+ progress = 1.0f;
+ m_bIsRobotMoving = FALSE;
+ KillTimer(TIMER_ID_ROBOT_ANIMATION);
+ m_lastRobotPosition = m_targetRobotPosition;
+ }
+
+ // 骞虫粦璁$畻浣嶇疆
+ int currentX = static_cast<int>(m_nRobotMoveStartX + progress * (m_nRobotMoveEndX - m_nRobotMoveStartX));
+ auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT);
+ if (!pImage) return;
+
+ int cx = currentX + pImage->bmWidth / 2;
+ int y = 270;
+ int cy = y + pImage->bmHeight / 2;
+
+ // 骞虫粦璁$畻瑙掑害
+ float currentAngle = m_nRobotMoveStartAngle + progress * (m_nRobotMoveEndAngle - m_nRobotMoveStartAngle);
+ float radians = currentAngle * 3.1415926f / 180.0f;
+
+ int rotatedX1 = static_cast<int>(cos(radians) * m_arm1Offset.x - sin(radians) * m_arm1Offset.y);
+ int rotatedY1 = static_cast<int>(sin(radians) * m_arm1Offset.x + cos(radians) * m_arm1Offset.y);
+ int rotatedX2 = static_cast<int>(cos(radians) * m_arm2Offset.x - sin(radians) * m_arm2Offset.y);
+ int rotatedY2 = static_cast<int>(sin(radians) * m_arm2Offset.x + cos(radians) * m_arm2Offset.y);
+
+ m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, currentX, y);
+ m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1);
+ m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, cx + rotatedX2, cy + rotatedY2);
+ m_pGraph->UpdateImageAngle(IMAGE_ROBOT, currentAngle);
+
+ Invalidate();
+ }
CDialogEx::OnTimer(nIDEvent);
}
--
Gitblit v1.9.3