| | |
| | | #include "afxdialogex.h" |
| | | #include "Common.h" |
| | | |
| | | const POINT g_arm1Offset = { -30, -45 }; // ARM1 从中心向左47, 向上33 |
| | | const POINT g_arm2Offset = { 27, -45 }; // ARM2 从中心向右10, 向上33 |
| | | |
| | | const std::map<SERVO::ROBOT_POSITION, RobotPositionMapping> g_positionMap = { |
| | | { SERVO::ROBOT_POSITION::Port1, { SERVO::ROBOT_POSITION::Port1, 1.00f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Port2, { SERVO::ROBOT_POSITION::Port2, 0.90f, 0.00f } }, |
| | |
| | | #define INDICATE_BAKE_COOLING 12 |
| | | #define INDICATE_MEASUREMENT 13 |
| | | |
| | | // 定时器 |
| | | #define TIMER_ID_DEVICE_STATUS 1 // 用于初始化设备状态 |
| | | #define TIMER_ID_ROBOT_STATUS 2 // 用于周期刷新机器人位置/臂状态 |
| | | |
| | | // CPageGraph1 对话框 |
| | | |
| | | IMPLEMENT_DYNAMIC(CPageGraph1, CDialogEx) |
| | |
| | | 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_arm1Offset = LoadArmOffset("ARM1"); |
| | | m_arm2Offset = LoadArmOffset("ARM2"); |
| | | |
| | | //m_arm1Offset = { -30, -45 }; // ARM1 从中心向左47, 向上33 |
| | | //m_arm2Offset = { 27, -45 }; // ARM2 从中心向右10, 向上33 |
| | | } |
| | | |
| | | CPageGraph1::~CPageGraph1() |
| | |
| | | |
| | | // CPageGraph1 消息处理程序 |
| | | |
| | | std::string CPageGraph1::GetConfigPath() |
| | | { |
| | | char path[MAX_PATH]; |
| | | GetModuleFileNameA(NULL, path, MAX_PATH); |
| | | std::string exePath(path); |
| | | std::string configDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\Config"; |
| | | CreateDirectoryA(configDir.c_str(), NULL); |
| | | return configDir + "\\robot_offset.ini"; |
| | | } |
| | | |
| | | void CPageGraph1::InitRxWindows() |
| | | { |
| | |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | InitRxWindows(); |
| | | SetTimer(1, 3000, nullptr); |
| | | |
| | | SetTimer(TIMER_ID_DEVICE_STATUS, 3000, nullptr); |
| | | SetTimer(TIMER_ID_ROBOT_STATUS, 1000, nullptr); // 每 1000ms 更新一次状态 |
| | | |
| | | // 图示 |
| | | m_pGraph = CServoGraph::Hook(GetDlgItem(IDC_SERVO_GRAPH1)->GetSafeHwnd()); |
| | |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | | case OFFLINE: |
| | | newBackgroundColor = RGB(222, 222, 222); |
| | | newBackgroundColor = EQ_BOX_OFFLINE; |
| | | newFrameColor1 = EQ_BOX_FRAME1; |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | | case OCCUPIED: |
| | | newBackgroundColor = EQ_BOX_OCCUPIED; |
| | | newFrameColor1 = EQ_BOX_FRAME1; |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | | |
| | | KillTimer(TIMER_ID_ROBOT_STATUS); |
| | | |
| | | if (m_hbrBkgnd != nullptr) { |
| | | ::DeleteObject(m_hbrBkgnd); |
| | | } |
| | |
| | | m_pObserver->unsubscribe(); |
| | | m_pObserver = NULL; |
| | | } |
| | | |
| | | SaveArmOffset("ARM1", m_arm1Offset); |
| | | SaveArmOffset("ARM2", m_arm2Offset); |
| | | } |
| | | |
| | | void CPageGraph1::OnSize(UINT nType, int cx, int cy) |
| | |
| | | int cx = currentX + pImage->bmWidth / 2; |
| | | |
| | | // 旋转后的偏移 |
| | | int rotatedX1 = static_cast<int>(cos(radians) * g_arm1Offset.x - sin(radians) * g_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * g_arm1Offset.x + cos(radians) * g_arm1Offset.y); |
| | | int rotatedX2 = static_cast<int>(cos(radians) * g_arm2Offset.x - sin(radians) * g_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * g_arm2Offset.x + cos(radians) * g_arm2Offset.y); |
| | | 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); |
| | |
| | | |
| | | // 最终位置校正 |
| | | int cx = endX + pImage->bmWidth / 2; |
| | | int rotatedX1 = static_cast<int>(cos(radians) * g_arm1Offset.x - sin(radians) * g_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * g_arm1Offset.x + cos(radians) * g_arm1Offset.y); |
| | | int rotatedX2 = static_cast<int>(cos(radians) * g_arm2Offset.x - sin(radians) * g_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * g_arm2Offset.x + cos(radians) * g_arm2Offset.y); |
| | | 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, endX, y); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | |
| | | float radians = angleInDegrees * 3.1415926f / 180.0f; |
| | | |
| | | // 旋转 offset1 |
| | | int rotatedX1 = static_cast<int>(cos(radians) * g_arm1Offset.x - sin(radians) * g_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * g_arm1Offset.x + cos(radians) * g_arm1Offset.y); |
| | | 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); |
| | | |
| | | // 旋转 offset2 |
| | | int rotatedX2 = static_cast<int>(cos(radians) * g_arm2Offset.x - sin(radians) * g_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * g_arm2Offset.x + cos(radians) * g_arm2Offset.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->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | |
| | | |
| | | // 旋转方向 |
| | | RotateRobot(mapping.angle); |
| | | |
| | | m_lastRobotPosition = position; |
| | | } |
| | | |
| | | POINT CPageGraph1::LoadArmOffset(const std::string& armName) |
| | | { |
| | | std::string iniPath = GetConfigPath(); |
| | | POINT pt; |
| | | pt.x = GetPrivateProfileIntA("Offsets", (armName + "_X").c_str(), 0, iniPath.c_str()); |
| | | pt.y = GetPrivateProfileIntA("Offsets", (armName + "_Y").c_str(), 0, iniPath.c_str()); |
| | | return pt; |
| | | } |
| | | |
| | | void CPageGraph1::SaveArmOffset(const std::string& armName, const POINT& pt) |
| | | { |
| | | std::string iniPath = GetConfigPath(); |
| | | char buf[16]; |
| | | |
| | | sprintf_s(buf, "%d", pt.x); |
| | | WritePrivateProfileStringA("Offsets", (armName + "_X").c_str(), buf, iniPath.c_str()); |
| | | |
| | | sprintf_s(buf, "%d", pt.y); |
| | | WritePrivateProfileStringA("Offsets", (armName + "_Y").c_str(), buf, iniPath.c_str()); |
| | | } |
| | | |
| | | void CPageGraph1::OnGraphItemClicked(NMHDR* pNMHDR, LRESULT* pResult) |
| | |
| | | else if (pGraphNmhdr->dwData == INDICATE_MEASUREMENT) { |
| | | MoveRobotToPosition(SERVO::ROBOT_POSITION::Measurement); |
| | | } |
| | | |
| | | CString s; s.Format(_T("OnGraphItemClicked %d"), pGraphNmhdr->dwData); |
| | | SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)m_pGraph->GetIndicateBoxData(pGraphNmhdr->dwData); |
| | | if (pEquipment != nullptr) { |
| | | theApp.m_model.notifyPtr(RX_CODE_SELECT_EQUIPMENT, pEquipment); |
| | | } |
| | | |
| | | *pResult = 0; |
| | | } |
| | | |
| | | void CPageGraph1::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (1 == nIDEvent) { |
| | | KillTimer(1); |
| | | if (TIMER_ID_DEVICE_STATUS == nIDEvent) { |
| | | KillTimer(TIMER_ID_DEVICE_STATUS); |
| | | |
| | | // 更新状态 |
| | | { |
| | | SERVO::CEquipment* pEquipment = (SERVO::CEFEM*)theApp.m_model.m_master.getEquipment(EQ_ID_EFEM); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_FLIPER, status); |
| | | UpdateDeviceStatus(INDICATE_ALIGNER, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT1, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT2, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT3, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT4, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM1, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM2, status); |
| | | } |
| | |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BONDER2, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_VACUUMBAKE); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_VACUUM_BAKE, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_BAKE_COOLING); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BAKE_COOLING, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_MEASUREMENT); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_MEASUREMENT, status); |
| | | } |
| | | } |
| | | else if (nIDEvent == TIMER_ID_ROBOT_STATUS) { |
| | | SERVO::CEFEM* pEFEM = (SERVO::CEFEM*)theApp.m_model.m_master.getEquipment(EQ_ID_EFEM); |
| | | if (!pEFEM || !pEFEM->isAlive()) { |
| | | return; |
| | | } |
| | | |
| | | // 如果设备在线,那么更新 ARM 状态 |
| | | SERVO::RMDATA& robotData = pEFEM->getRobotMonitoringData(); |
| | | if (m_lastArmState[0] != robotData.armState[0]) { |
| | | m_lastArmState[0] = robotData.armState[0]; |
| | | DeviceStatus arm1Status; |
| | | arm1Status = robotData.armState[0] ? DeviceStatus::OCCUPIED : DeviceStatus::ONLINE; |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM1, arm1Status); |
| | | } |
| | | |
| | | if (m_lastArmState[1] != robotData.armState[1]) { |
| | | m_lastArmState[1] = robotData.armState[1]; |
| | | DeviceStatus arm2Status; |
| | | arm2Status = robotData.armState[1] ? DeviceStatus::OCCUPIED : DeviceStatus::ONLINE; |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM2, arm2Status); |
| | | } |
| | | |
| | | // 位置信息状态显示 |
| | | if (robotData.position != m_lastRobotPosition) { |
| | | MoveRobotToPosition(robotData.position); |
| | | } |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |