public static void AddLabelAGV(string Mode, int agvID, int initExitNode, char initOrientation, float initDistanceToExitNode) { /// Create new label for AGV Label lbAGV = new Label(); lbAGV.BackColor = Color.Silver; lbAGV.Font = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lbAGV.Size = new Size(50, 50); lbAGV.ForeColor = Color.Black; lbAGV.Text = "AGV#" + agvID.ToString(); lbAGV.TextAlign = ContentAlignment.MiddleCenter; lbAGV.Name = "AGV" + agvID.ToString(); /// Create new label for Pallet in AGV Label pallet = new Label(); pallet.BackColor = Color.Goldenrod; pallet.Size = new Size(50, 11); pallet.ForeColor = Color.Black; pallet.Font = new Font("Microsoft Sans Serif", 8.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); pallet.Text = "Pallet"; pallet.TextAlign = ContentAlignment.MiddleCenter; //pallet.BorderStyle = BorderStyle.FixedSingle; pallet.Name = "PalletInAGV" + agvID.ToString(); pallet.Visible = false; int initPixelDistance = (int)Math.Round(initDistanceToExitNode * 2); // Init the Location of new AGV List <Node> Nodes = DBUtility.GetDataFromDB <List <Node> >("NodeInfoTable"); int x = Nodes[initExitNode].X - lbAGV.Size.Width / 2; int y = Nodes[initExitNode].Y - lbAGV.Size.Height / 2; switch (initOrientation) { case 'E': lbAGV.Location = new Point(x + initPixelDistance, y); pallet.Size = new Size(15, 50); pallet.Location = new Point(x - initPixelDistance - 15, y); break; case 'W': lbAGV.Location = new Point(x - initPixelDistance, y); pallet.Size = new Size(15, 50); pallet.Location = new Point(x + initPixelDistance + 50, y); break; case 'N': lbAGV.Location = new Point(x, y - initPixelDistance); pallet.Size = new Size(50, 15); pallet.Location = new Point(x, y + initPixelDistance + 50); break; case 'S': lbAGV.Location = new Point(x, y + initPixelDistance); pallet.Size = new Size(50, 15); pallet.Location = new Point(x, y - initPixelDistance - 15); break; } // Add to Array for use switch (Mode) { case "Real Time": LabelAGV[agvID] = lbAGV; LabelPalletInAGV[agvID] = pallet; break; case "Simulation": SimLabelAGV[agvID] = lbAGV; SimLabelPalletInAGV[agvID] = pallet; break; } }
public static void SimUpdatePathFromTaskOfAGVs(AGV agv) { // Clear all path (this do not affect Task.SimListTask) //agv.Tasks.Clear(); // Find all task of this AGV //agv.Tasks = Task.SimListTask.FindAll(t => t.AGVID == agv.ID);&& agv.Path.Count ==0 // if not having task or path has been initialized, skip to next AGV if (agv.Tasks.Count != 0) { Task currentTask = agv.Tasks[0]; //agv.Path.RemoveAt(0);agv.CurrentNode != currentTask.PickNode && if (currentTask.Status == "Waiting") { agv.Path.Clear(); agv.Path.Add(Algorithm.A_starFindPath(Node.ListNode, Node.MatrixNodeDistance, agv.CurrentNode, agv.Tasks[0].PickNode)); AGV.SimFullPathOfAGV[agv.ID] = Navigation.GetNavigationFrame(agv.Path[0], Node.MatrixNodeOrient); agv.Tasks[0].Status = "Doing"; agv.PathCopmpleted = 0; agv.Status = "Running"; Display.SimLabelAGV[agv.ID].BackColor = Color.CornflowerBlue; } else if (agv.CurrentNode == currentTask.PickNode && currentTask.Status == "Doing" && agv.PathCopmpleted == 1) { agv.Path.RemoveAt(0); agv.Path.Add(Algorithm.A_starFindPath(Node.ListNode, Node.MatrixNodeDistance, agv.CurrentNode, agv.Tasks[0].DropNode)); AGV.SimFullPathOfAGV[agv.ID] = Navigation.GetNavigationFrame(agv.Path[0], Node.MatrixNodeOrient); agv.HavePallet = true; if (currentTask.Type == "Order") { Pallet pallet = Pallet.SimListPallet.Find(c => c.Code == currentTask.PalletCode); Display.DeleteLabelPallet(pallet); } else if (currentTask.Type == "Store") { } } else if ((agv.CurrentNode == currentTask.DropNode && currentTask.Status == "Doing" && agv.PathCopmpleted == 2)) { agv.Tasks.RemoveAt(0); agv.Path.Clear(); agv.Status = "Stop"; Display.SimLabelAGV[agv.ID].BackColor = Color.Silver; string timeComplete = DateTime.Now.ToString("dddd, MMMM dd, yyyy h:mm:ss tt"); DBUtility.InsertCompleteTaskToDB("SimHistoryTask", currentTask, timeComplete, "Done"); agv.HavePallet = false; if (currentTask.Type == "Order") { DBUtility.DeletePalletFromDB("SimPalletInfoTable", currentTask.PalletCode); Task.SimListTask.Remove(currentTask); } else if (currentTask.Type == "Store") { //agv.HavePallet = false; Pallet pallet = Pallet.SimStorePallet.Find(c => c.Code == currentTask.PalletCode); pallet.DeliverTime = DateTime.Now.ToString("dddd, MMMM dd, yyyy h:mm:ss tt"); DBUtility.InsertNewPalletToDB("SimPalletInfoTable", pallet.Code, pallet.Name, pallet.InStock, pallet.DeliverTime, pallet.AtBlock, pallet.AtColumn, pallet.AtLevel); Pallet.SimStorePallet.Remove(pallet); Pallet.SimListPallet.Add(pallet); Display.UpdateLabelPallet(pallet); Task.SimListTask.Remove(currentTask); } else if (currentTask.Type == "Input" || currentTask.Type == "Output") { Task.SimListTask.Remove(currentTask); } } } else { if (agv.CurrentNode == 55) { agv.Status = "Stop"; agv.Path.Clear(); } } }
public static void SimUpdatePositionAGV(int agvID, float speed, Panel pnFloor, Label lbagv, Label lbpallet) { //int step = (int)speed * 2 / 10; //1pixel = 0.5cm =>> 20cm/s=40pixel/s var index = AGV.SimListAGV.FindIndex(a => a.ID == agvID); AGV agv = AGV.SimListAGV[index]; //List<char> fullpath = AGV.FullPathOfAGV[agvID].ToList(); string[] frameArr = AGV.SimFullPathOfAGV[agvID].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); Point oldAGVPosition = Display.SimLabelAGV[agvID].Location; Point newAGVPosition = new Point(); Point oldPalletPosition = Display.SimLabelPalletInAGV[agvID].Location; Point newPalletPosition = new Point(); Size oldPalletSize = Display.SimLabelPalletInAGV[agvID].Size; Size newPalletSize = new Size(); int indexNode = Array.FindIndex(frameArr, a => a == agv.CurrentNode.ToString()); if (agv.Stop) { return; } if (agv.IsColision) { return; } if (frameArr[indexNode + 1] == "G" || frameArr[indexNode + 1] == null) { agv.PathCopmpleted++; if (agv.PathCopmpleted == 1 || agv.PathCopmpleted == 0) { Display.Points = new Point[] { new Point(), new Point() }; pnFloor.Refresh(); } } else { int currentNode = agv.CurrentNode; int nextNode = Convert.ToInt32(frameArr[indexNode + 2]); if (agv.CurrentOrient != Display.UpdateOrient(frameArr[indexNode + 1])) { agv.DistanceToCurrentNode -= speed / 5.2f; if (agv.DistanceToCurrentNode <= 0) { agv.CurrentOrient = Display.UpdateOrient(frameArr[indexNode + 1]); agv.DistanceToCurrentNode = 0; } } else { agv.DistanceToCurrentNode += speed / 5.2f; if (agv.DistanceToCurrentNode * 2 >= Node.MatrixNodeDistance[currentNode, nextNode]) { agv.DistanceToCurrentNode = 0; agv.CurrentNode = nextNode; if (frameArr[indexNode + 3] != "G") { agv.CurrentOrient = Display.UpdateOrient(frameArr[indexNode + 3]); } } } } int pixelDistance = (int)Math.Round(agv.DistanceToCurrentNode * 2); List <Node> Nodes = DBUtility.GetDataFromDB <List <Node> >("NodeInfoTable"); int x = Nodes[agv.CurrentNode].X - 50 / 2; int y = Nodes[agv.CurrentNode].Y - 50 / 2; switch (agv.CurrentOrient) { case 'E': newAGVPosition = new Point(x + pixelDistance, y); newPalletSize = new Size(15, 50); newPalletPosition = new Point(x + pixelDistance - 15, y); break; case 'W': newAGVPosition = new Point(x - pixelDistance, y); newPalletSize = new Size(15, 50); newPalletPosition = new Point(x - pixelDistance + 50, y); break; case 'S': newAGVPosition = new Point(x, y + pixelDistance); newPalletSize = new Size(50, 15); newPalletPosition = new Point(x, y + pixelDistance - 15); break; case 'N': newAGVPosition = new Point(x, y - pixelDistance); newPalletSize = new Size(50, 15); newPalletPosition = new Point(x, y - pixelDistance + 50); break; default: newAGVPosition = oldAGVPosition; newPalletPosition = oldPalletPosition; newPalletSize = oldPalletSize; break; } lbpallet.Size = newPalletSize; lbpallet.Location = newPalletPosition; //lbpallet.Visible = true; lbagv.Location = newAGVPosition; }