// Use this for initialization void Start() { crane = GameObject.FindWithTag ("Crane").GetComponent<Crane> (); if (isStartPoint || isEndPoint) { SetRandomYPos(); } }
public CraneEventArgs(Crane crane) { this._crane = crane; }
private void tmCraneWorker2(object sender, System.Timers.ElapsedEventArgs e) { try { tmCrane2.Stop(); int[] location = new int[2]; string serviceName = "CranePLC2"; object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneLocation")); for (int j = 0; j < obj.Length; j++) location[j] = Convert.ToInt16(obj[j]) - 48; int[] craneInfo = new int[6]; obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneInfo")); for (int j = 0; j < obj.Length; j++) craneInfo[j] = Convert.ToInt16(obj[j]) - 48; obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo")); string plcTaskNo = Util.ConvertStringChar.BytesToString(obj); obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneSpeed")); Crane crane = new Crane(); crane.CraneNo = 2; crane.Column = location[0]; crane.Height = location[1]; crane.ForkStatus = craneInfo[1]; crane.Action = craneInfo[2]; crane.TaskType = craneInfo[3]; crane.ErrCode = craneInfo[4]; crane.TaskNo = plcTaskNo; crane.WalkCode = int.Parse(obj[3].ToString()); crane.UpDownCode = int.Parse(obj[4].ToString()); Cranes.CraneInfo(crane); } catch (Exception ex) { Logger.Error(ex.Message); } finally { tmCrane2.Start(); } }
private void tmCraneWorker1(object sender, System.Timers.ElapsedEventArgs e) { try { tmCrane1.Stop(); string binary = Convert.ToString(255, 2).PadLeft(8, '0'); string serviceName = "CranePLC1"; string plcTaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo"))); string craneMode = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneMode")).ToString(); string craneFork = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneFork")).ToString(); object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneAlarmCode")); Crane crane = new Crane(); crane.CraneNo = 1; crane.Row = int.Parse(obj[4].ToString()); crane.Column = int.Parse(obj[2].ToString()); crane.Height = int.Parse(obj[3].ToString()); crane.ForkStatus = int.Parse(craneFork); crane.Action = int.Parse(craneMode); crane.TaskType = int.Parse(obj[1].ToString()); crane.ErrCode = int.Parse(obj[0].ToString()); crane.PalletCode = ""; crane.TaskNo = plcTaskNo; Cranes.CraneInfo(crane); } catch (Exception ex) { Logger.Error(ex.Message); } finally { tmCrane1.Start(); } }
// Update is called once per frame void Update() { leftAxis = rightAxis = 0; upperCraneRotationAxis = 0; armCraneAxis = 0; //TEMP INPUTS, here we will manage with the levers the value of each axis variable leftAxis = InputManager.Instance.GetAxisVertical(); rightAxis = InputManager.Instance.GetAxisVertical2(); if (InputManager.Instance.GetButton(InputManager.MiniGameButtons.BUTTON1)) { upperCraneRotationAxis = 1; } else if (InputManager.Instance.GetButton(InputManager.MiniGameButtons.BUTTON2)) { upperCraneRotationAxis = -1; } if (InputManager.Instance.GetButton(InputManager.MiniGameButtons.BUTTON3)) { armCraneAxis = 1; } else if (InputManager.Instance.GetButton(InputManager.MiniGameButtons.BUTTON4)) { armCraneAxis = -1; } if (rightAxis > 1.0f) { rightAxis = 1.0f; } else if (rightAxis < -1.0f) { rightAxis = -1.0f; } if (leftAxis > 1.0f) { rightAxis = 1.0f; } else if (leftAxis < -1.0f) { rightAxis = -1.0f; } //MOVEMENT LEVERS leftWheelMovement = speed * leftAxis; rightWheelMovement = speed * rightAxis; Crane.Rotate(Vector3.up * (leftWheelMovement - rightWheelMovement) * Time.deltaTime * 2); if (leftAxis != 0 && rightAxis != 0) { Crane.Translate(Vector3.right * (leftWheelMovement * Time.deltaTime) / 10); Crane.Translate(Vector3.right * (rightWheelMovement * Time.deltaTime) / 10); } //Crane LEVER craneArm.Rotate(Vector3.forward * (armCraneAxis * armCraneSpeed) * Time.deltaTime * 2); if (craneArm.transform.rotation.eulerAngles.z > 336) { craneArm.transform.rotation = Quaternion.Euler(new Vector3(craneArm.transform.rotation.eulerAngles.x, craneArm.transform.eulerAngles.y, 336)); } else if (craneArm.transform.rotation.eulerAngles.z < 289) { craneArm.transform.rotation = Quaternion.Euler(new Vector3(craneArm.transform.rotation.eulerAngles.x, craneArm.transform.rotation.eulerAngles.y, 289)); } //Upper Crane rotation upperCrane.Rotate(Vector3.forward * (upperCraneRotationAxis * rotationSpeed) * Time.deltaTime * 2); }
void Monitor_OnCrane(CraneEventArgs args) { if (InvokeRequired) { BeginInvoke(new CraneEventHandler(Monitor_OnCrane), args); } else { Crane crane = args.crane; TextBox txt = GetTextBox("txtTaskNo", crane.CraneNo); if (txt != null) { txt.Text = crane.TaskNo; } txt = GetTextBox("txtState", crane.CraneNo); if (txt != null && dicCraneState.ContainsKey(crane.TaskType)) { txt.Text = dicCraneState[crane.TaskType]; } txt = GetTextBox("txtCraneAction", crane.CraneNo); if (txt != null && dicCraneAction.ContainsKey(crane.Action)) { txt.Text = dicCraneAction[crane.Action]; } txt = GetTextBox("txtRow", crane.CraneNo); if (txt != null) { txt.Text = crane.Row.ToString(); } txt = GetTextBox("txtColumn", crane.CraneNo); if (txt != null) { txt.Text = crane.Column.ToString(); } //堆垛机位置 if (crane.CraneNo == 1) { this.picCrane.Visible = true; Point P1 = InitialP1; if (crane.Column < 46) { P1.X = P1.X + (int)((crane.Column - 1) * colDis); } else { P1.X = picCar.Location.X + 15; } P1.Y = P1.Y + (int)(rowDis * (crane.Row - 1)); this.picCrane.Location = P1; Point P2 = InitialP2; P2.Y = P2.Y + (int)(rowDis * (crane.Row - 1)); this.picCar.Location = P2; } txt = GetTextBox("txtHeight", crane.CraneNo); if (txt != null) { txt.Text = crane.Height.ToString(); } txt = GetTextBox("txtForkStatus", crane.CraneNo); if (txt != null && dicCraneFork.ContainsKey(crane.ForkStatus)) { txt.Text = dicCraneFork[crane.ForkStatus]; } txt = GetTextBox("txtErrorDesc", crane.CraneNo); if (txt != null && dicCraneError.ContainsKey(crane.ErrCode)) { txt.Text = dicCraneError[crane.ErrCode]; } //更新错误代码、错误描述 //更新任务状态为执行中 //bll.ExecNonQuery("WCS.UpdateTaskError", new DataParameter[] { new DataParameter("@CraneErrCode", crane.ErrCode.ToString()), new DataParameter("@CraneErrDesc", dicCraneError[crane.ErrCode]), new DataParameter("@TaskNo", crane.TaskNo) }); txt = GetTextBox("txtErrorNo", crane.CraneNo); if (txt != null) { if (crane.ErrCode > 0) { DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", crane.TaskNo), new DataParameter("@CraneErrCode", crane.ErrCode.ToString()), new DataParameter("@CraneErrDesc", dicCraneError[crane.ErrCode]) }; bll.ExecNonQueryTran("WCS.Sp_UpdateTaskError", param); if (txt.Text.Trim() == "") { txt.Text = "0"; } if (crane.ErrCode != int.Parse(txt.Text)) { Logger.Error(crane.CraneNo.ToString() + "堆垛机执行时出现错误,代码:" + crane.ErrCode.ToString() + ",描述:" + dicCraneError[crane.ErrCode]); } txt.Text = crane.ErrCode.ToString(); } else { txt.Text = "0"; } } } }
private CraneMove ArrivalToShuffle(List <Location> targetLocations, Crane crane, List <(Location Location, List <Block> Lot)> arrivalLots)
private Tuple <List <Route>, bool> BuildRouteCost(ConveyorBasic t, int level, bool ignoreBlocked) { if (visited.Contains(t)) { return(new Tuple <List <Route>, bool>(null, false)); } if (t is ConveyorJunction) { visited.Add(t); ConveyorJunction jt = t as ConveyorJunction; List <Route> newRes = new List <Route>(); Tuple <List <Route>, bool> res = null; foreach (RouteNode jt1 in jt.RouteDef.Node) { ConveyorBasic final = FindNextNonConveyor(jt1.Next); if (final == null || (!ignoreBlocked && DBService.FindPlaceID(final.Name).Blocked)) { res = new Tuple <List <Route>, bool>(new List <Route>(), true); } else { res = BuildRouteCost(final, level + 1, ignoreBlocked); } if (res.Item2) { RouteDescription rd = new RouteDescription { First = jt, Next = jt1.Next, Final = final }; res.Item1.ForEach(p => { p.Items.Insert(0, rd); p.Cost += jt1.Cost; }); res.Item1.ForEach(p => newRes.Add(p)); } } if (t is IConveyorOutput && level > 0) { RouteDescription rd = new RouteDescription { First = t, Next = t, Final = t }; newRes.Add(new Route { Cost = 0, Items = new List <RouteDescription> { rd } }); } visited.Remove(t); return(new Tuple <List <Route>, bool>(newRes, newRes.Count > 0)); } else if (t is Crane) { visited.Add(t); Crane jt = t as Crane; List <Route> newRes = new List <Route>(); // crane could be final location bool shuttle = !jt.FinalDevice; if (jt.Shelve != null && jt.Shelve.Count > 0) { RouteDescription rd = new RouteDescription { First = jt, Next = jt, Final = jt }; newRes.Add(new Route { Items = new List <RouteDescription> { rd }, Cost = 0 }); } Tuple <List <Route>, bool> res = null; if (jt.OutRouteDef != null && jt.OutRouteDef.Node != null) { foreach (RouteNode jt1 in jt.OutRouteDef.Node) { ConveyorBasic final = FindNextNonConveyor(jt1.Next); if (final == null || (!ignoreBlocked && DBService.FindPlaceID(final.Name).Blocked)) { res = new Tuple <List <Route>, bool>(new List <Route>(), true); } else { res = BuildRouteCost(final, level + 1, ignoreBlocked); } if (res.Item2 && (level == 0 || shuttle)) { RouteDescription rd = new RouteDescription { First = jt, Next = jt1.Next, Final = final }; res.Item1.ForEach(p => { p.Items.Insert(0, rd); p.Cost += jt1.Cost; }); res.Item1.ForEach(p => newRes.Add(p)); } } } visited.Remove(t); return(new Tuple <List <Route>, bool>(newRes, newRes.Count > 0)); } else if (t is IConveyorOutput) { RouteDescription rd = new RouteDescription { First = t, Next = t, Final = t }; return(new Tuple <List <Route>, bool>(new List <Route> { new Route { Cost = 0, Items = new List <RouteDescription> { rd } } }, true)); } throw new BasicWarehouseException("Unknown type in path calculation..."); }
public override void Strategy() { if (Crane.PLC_Status != null) { Crane.FastCommand = null; } if (!Warehouse.StrategyActive) { return; } if (!Crane.Communicator.Online()) { return; } if (!Crane.CheckIfAllNotified()) { return; } try { PickAction = null; Command = Crane.Command; BufferCommand = Crane.BufferCommand; bool remote = Warehouse.SteeringCommands.RemoteMode; if (Crane.FastCommand == null) { Crane.FastCommand = Warehouse.DBService.FindFirstFastSimpleCraneCommand(Crane.Name, Warehouse.SteeringCommands.AutomaticMode); } WriteCommandToPLC(Crane.FastCommand, true); if (!Warehouse.SteeringCommands.Run) { return; } if ((!Crane.Remote() || Crane.LongTermBlock())) { return; } if (!Crane.Automatic()) { return; } GetNewCommand(remote, null); GetNewCommand(remote, null); // make double cycles if (PickAction != null) { PrefferedInput = LPosition.FromString(PickAction.Source).IsWarehouse(); } WriteCommandToPLC(Command); WriteCommandToPLC(BufferCommand); BannedPlaces.Clear(); } catch (Exception e) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, e.Message); throw new StrategyCraneException(String.Format("{0} Strategy failed.", Name)); } }
void Monitor_OnCrane(CraneEventArgs args) { if (InvokeRequired) { BeginInvoke(new CraneEventHandler(Monitor_OnCrane), args); } else { Crane crane = args.crane; Button btn = GetButton(crane.CraneNo); TextBox txt = GetTextBox("txtTaskNo", crane.CraneNo); if (txt != null) { txt.Text = crane.TaskNo; } txt = GetTextBox("txtStatus", crane.CraneNo); if (txt != null && dicStatus.ContainsKey(crane.Status)) { txt.Text = dicStatus[crane.Status]; if (txt.Text == "空闲") { txt.BackColor = Color.Lime; } else { txt.BackColor = Color.Yellow; } } txt = GetTextBox("txtWorkMode", crane.CraneNo); if (txt != null && dicWorkMode.ContainsKey(crane.Mode)) { txt.Text = dicWorkMode[crane.Mode]; if (crane.Mode == 1) { txt.BackColor = Color.Lime; } else { txt.BackColor = Color.Yellow; } } if (crane.Mode == 1) { btn.BackColor = Color.Lime; } else { btn.BackColor = Color.Yellow; } txt = GetTextBox("txtRow", crane.CraneNo); if (txt != null) { txt.Text = crane.Row.ToString(); } txt = GetTextBox("txtColumn", crane.CraneNo); if (txt != null) { txt.Text = crane.Column.ToString(); } //堆垛机位置 if (crane.CraneNo == "05") { Point P = InitialP5; if (crane.Row == 6) { P = InitialP6; } else if (crane.Row == 7) { P = InitialP7; } P.X = P.X + (int)((45 - crane.Column) * colDis); this.btnSRM5.Location = P; } if (crane.CraneNo == "06") { Point P = InitialP6; if (crane.Row == 5) { P = InitialP5; } else if (crane.Row == 7) { P = InitialP7; } P.X = P.X + (int)((45 - crane.Column) * colDis); this.btnSRM6.Location = P; } if (crane.CraneNo == "07") { Point P = InitialP7; if (crane.Row == 5) { P = InitialP5; } else if (crane.Row == 6) { P = InitialP6; } P.X = P.X + (int)((45 - crane.Column) * colDis); this.btnSRM7.Location = P; } txt = GetTextBox("txtLayer", crane.CraneNo); if (txt != null) { txt.Text = crane.Layer.ToString(); } txt = GetTextBox("txtForkStatus", crane.CraneNo); if (txt != null && dicFork.ContainsKey(crane.ForkStatus)) { txt.Text = dicFork[crane.ForkStatus]; } txt = GetTextBox("txtAlarmCode", crane.CraneNo); if (txt != null) { txt.Text = crane.AlarmCode.ToString(); if (txt.Text == "0") { txt.BackColor = DefaultBackColor; } else { txt.BackColor = Color.Red; } } string strAlarmDesc = ""; txt = GetTextBox("txtAlarmDesc", crane.CraneNo); if (txt != null) { if (crane.AlarmCode != 0) { DataRow[] drs = dtDeviceAlarm.Select(string.Format("Flag=1 and AlarmCode={0}", crane.AlarmCode)); if (drs.Length > 0) { strAlarmDesc = drs[0]["AlarmDesc"].ToString(); } else { strAlarmDesc = "设备未知错误!"; } } else { strAlarmDesc = ""; } txt.Text = strAlarmDesc; if (txt.Text == "") { txt.BackColor = DefaultBackColor; } else { txt.BackColor = Color.Red; } } txt = GetTextBox("txtSTB", crane.CraneNo); if (txt != null) { txt.Text = crane.STB.ToString(); } txt = GetTextBox("txtACK", crane.CraneNo); if (txt != null) { txt.Text = crane.ACK.ToString(); } //更新错误代码、错误描述 //更新任务状态为执行中 //bll.ExecNonQuery("WCS.UpdateTaskError", new DataParameter[] { new DataParameter("@CraneErrCode", crane.ErrCode.ToString()), new DataParameter("@CraneErrDesc", dicCraneError[crane.ErrCode]), new DataParameter("@TaskNo", crane.TaskNo) }); if (crane.AlarmCode > 0) { btn.BackColor = Color.Red; //DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", crane.TaskNo), new DataParameter("@CraneErrCode", crane.AlarmCode.ToString()), new DataParameter("@CraneErrDesc", strAlarmDesc) }; //bll.ExecNonQueryTran("WCS.Sp_UpdateTaskError", param); //Logger.Error(crane.CraneNo.ToString() + "堆垛机执行时出现错误,代码:" + crane.AlarmCode.ToString() + ",描述:" + strAlarmDesc); } } }
private void tmCraneWorker(object sender, System.Timers.ElapsedEventArgs e) { try { tmCrane.Stop(); for (int i = 1; i <= 5; i++) { TextBox txt = GetTextBox("txtColumn", i); if (txt != null) { Crane crane = new Crane(); crane.CraneNo = i; int column = 0; if (txt.Text != "") { column = int.Parse(txt.Text); } crane.Column = column; Cranes.CraneInfo(crane); } txt = GetTextBox("txtErrorNo", i); if (txt != null) { if (txt.Text.Length == 0) { continue; } int ErrCode = int.Parse(txt.Text); if (ErrCode == 0) { continue; } //string[] d = new string[2]; //d[0] = i.ToString(); //d[1] = GetTextBox("txtErrorDesc", i).Text; //Context.ProcessDispatcher.WriteToProcess("LEDProcess", "Error", d);//LED显示 if (ErrCode == 506 || ErrCode == 505) { string serviceName = "CranePLC" + i; string plcTaskNo = GetTextBox("txtTaskNo", i).Text; string plcPalletCode = GetTextBox("txtPalletCode", i).Text; DataTable dtErr = bll.FillDataTable("WCS.SelectWmsSend", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}'", plcTaskNo)) }); if (dtErr.Rows.Count > 0) { string Taskstatus = dtErr.Rows[0]["TASKSTATUS"].ToString(); if (Taskstatus == "4") { bll.ExecNonQueryTran("WCS.SPCancelTask", new DataParameter[] { new DataParameter("VTASKNO", plcTaskNo) }); Logger.Info("任务:" + plcTaskNo + " 托盘编号:" + dtErr.Rows[0]["PALLETID"].ToString() + "任务取消!"); if (ErrCode == 506)//空取异常 { //取消堆垛机当前任务 Context.ProcessDispatcher.WriteToService(serviceName, "CancelTask", true); sbyte[] taskNo = new sbyte[20]; Util.ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0); Context.ProcessDispatcher.WriteToService(serviceName, "ClearTaskNo", taskNo); } else //crane.ErrCode == 505,重入异常 { if (GetTextBox("txtTaskType", i).Text == "出库") { continue; } DataTable dtTask = bll.FillDataTable("WCS.SelectWmsTask", new DataParameter[] { new DataParameter("{0}", string.Format("PALLETID='{0}' AND TASKSTATUS='0' AND ASRSID='{1}'", plcPalletCode, i)) }); if (dtTask.Rows.Count > 0) { string TaskNo = dtTask.Rows[0]["TASKID"].ToString(); sbyte[] staskNo = new sbyte[20]; Util.ConvertStringChar.stringToBytes(TaskNo, 12).CopyTo(staskNo, 0); Util.ConvertStringChar.stringToBytes(plcPalletCode, 8).CopyTo(staskNo, 12); string strDLocation = dtTask.Rows[0]["DLOCATION"].ToString(); int[] Location = new int[6]; Location[0] = 0; Location[1] = 0; Location[2] = 0; Location[3] = int.Parse(strDLocation.Split('-')[0]); Location[4] = int.Parse(strDLocation.Split('-')[1]); int ToRow = int.Parse(strDLocation.Split('-')[2]); if (ToRow > 1) { ToRow += 1; } Location[5] = ToRow; Context.ProcessDispatcher.WriteToService(serviceName, "Address", Location); Context.ProcessDispatcher.WriteToService(serviceName, "WriteTask", staskNo); if (Context.ProcessDispatcher.WriteToService(serviceName, "WriteFinish", true)) { bll.ExecNonQueryTran("WCS.SPReciveWmsTask", new DataParameter[] { new DataParameter("VTASKNO", TaskNo) }); //更新WCSTask状态为3 bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) }); Logger.Info("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 位:" + strDLocation + " 已下发给" + i + "堆垛机"); } else { Logger.Error("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 无法写入堆垛机" + i); } } } } } } } } } catch (Exception ex) { Logger.Error("监控界面中tmCraneWorker出现异常:" + ex.Message); } finally { tmCrane.Start(); } }