public bool NearestCmd1(SimpleCraneCommand cmd1, SimpleCraneCommand cmd2, FLocation location) { FLocation fpos1 = GetLocation(cmd1.Source); FLocation fpos2 = GetLocation(cmd2.Source); return((location - fpos1).Distance() <= (location - fpos2).Distance()); }
public override void Strategy() { try { if (!Warehouse.StrategyActive) { return; } if (!Strategy1.Crane.Communicator.Online()) { return; } bool remote = Warehouse.SteeringCommands.RemoteMode; LinkedConveyor lc = null; Strategy2.PrefferedInput = Strategy1.PrefferedInput; Strategy1.Command = Strategy1.Crane.Command; Strategy1.BufferCommand = Strategy1.Crane.BufferCommand; Strategy2.Command = Strategy2.Crane.Command; Strategy2.BufferCommand = Strategy2.Crane.BufferCommand; if (Strategy1.Crane.FastCommand == null) { Strategy1.Crane.FastCommand = Warehouse.DBService.FindFirstFastSimpleCraneCommand(Strategy1.Crane.Name, Warehouse.SteeringCommands.AutomaticMode); } if (Strategy2.Crane.FastCommand == null) { Strategy2.Crane.FastCommand = Warehouse.DBService.FindFirstFastSimpleCraneCommand(Strategy2.Crane.Name, Warehouse.SteeringCommands.AutomaticMode); } Strategy1.WriteCommandToPLC(Strategy1.Crane.FastCommand, true); Strategy2.WriteCommandToPLC(Strategy2.Crane.FastCommand, true); if (!Warehouse.SteeringCommands.Run) { return; } if ((!Strategy1.Crane.Remote() || Strategy1.Crane.LongTermBlock())) { return; } if (!Strategy1.Crane.Automatic()) { return; } SimpleCraneCommand c1c = Warehouse.DBService.CheckIfPlaceBlocked(Strategy1.Crane.Name) ? null : Strategy1.GetNewCommand(remote, null); // SimpleCraneCommand c1b = Strategy1.GetNewCommand(remote); Strategy2.BannedPlaces.AddRange(Strategy1.BannedPlaces); SimpleCraneCommand c2c = Warehouse.DBService.CheckIfPlaceBlocked(Strategy2.Crane.Name) ? null : Strategy2.GetNewCommand(remote, c1c); // SimpleCraneCommand c2b = Strategy2.GetNewCommand(remote); if (c1c != null && c2c != null && c1c.Task == c2c.Task) // && ((Strategy1.Crane.Command == null && Strategy2.Crane.Command == null) || // (Strategy1.Crane.Command != null && Strategy2.Crane.Command != null))) { if (c1c.Task == SimpleCommand.EnumTask.Pick) { Strategy1.PrefferedInput = !Strategy1.PrefferedInput; } // new both Execute command with same task bool opposite = false; FLocation lastloc = null; if (Strategy1.Crane.Command != null && Strategy2.Crane.Command != null) { lastloc = Strategy1.Crane.Command.Command_ID > Strategy2.Crane.Command.ID ? GetLocation(Strategy1.Crane.Command.Source) : GetLocation(Strategy2.Crane.Command.Source); } else if (Strategy1.Crane.Command != null) { lastloc = GetLocation(Strategy1.Crane.Command.Source); } else if (Strategy2.Crane.Command != null) { lastloc = GetLocation(Strategy2.Crane.Command.Source); } else { lastloc = Strategy1.Crane.FLocation; } if (c1c != null && c2c != null && c1c.Task == c2c.Task && c1c.Source.StartsWith("W") && c2c.Source.StartsWith("W") && c1c.Source.Substring(0, c1c.Source.Length - 1) == c2c.Source.Substring(0, c2c.Source.Length - 1)) { opposite = (c1c.Task == SimpleCommand.EnumTask.Pick && c1c.Source.EndsWith("2") && c2c.Source.EndsWith("1")) || (c1c.Task == SimpleCommand.EnumTask.Drop && c1c.Source.EndsWith("1") && c2c.Source.EndsWith("2")); } else { opposite = (c1c.Task == SimpleCommand.EnumTask.Drop && GetLocation(c1c.Source).X > GetLocation(c2c.Source).X) || (c1c.Task == SimpleCommand.EnumTask.Pick && GetLocation(c1c.Source).X < GetLocation(c2c.Source).X); } if (!opposite) { Strategy1.WriteCommandToPLC(c1c); Strategy2.WriteCommandToPLC(c2c); } else { Strategy2.WriteCommandToPLC(c2c); Strategy1.WriteCommandToPLC(c1c); } } else if (c1c != null && c2c != null && c1c.Task != c2c.Task) { // only drop if different comands to be done if (c1c.Task == SimpleCommand.EnumTask.Drop) { Strategy1.WriteCommandToPLC(c1c); } else { Strategy2.WriteCommandToPLC(c2c); } } else if (c1c != null && (Strategy1.Command == null || Strategy1.Command.Status < SimpleCommand.EnumStatus.Written) && (Strategy2.Command == null || (c1c.Task == Strategy2.Command.Task && c1c.Source.StartsWith("T") && Strategy2.Command.Source.StartsWith("T")))) { if (c1c.Task == SimpleCommand.EnumTask.Pick) { Strategy1.PrefferedInput = !Strategy1.PrefferedInput; } Strategy1.WriteCommandToPLC(c1c); } else if (c2c != null && (Strategy2.Command == null || Strategy2.Command.Status < SimpleCommand.EnumStatus.Written) && (Strategy1.Command == null || (c2c.Task == Strategy1.Command.Task && c2c.Source.StartsWith("T") && Strategy1.Command.Source.StartsWith("T")))) { if (c2c.Task == SimpleCommand.EnumTask.Pick) { Strategy1.PrefferedInput = !Strategy1.PrefferedInput; } Strategy2.WriteCommandToPLC(c2c); } Strategy1.BannedPlaces.Clear(); Strategy2.BannedPlaces.Clear(); // logic for prefferable double pick if (Strategy1.PickAction != null && Strategy1.ForcedInput == null) { Strategy2.ForcedInput = (lc = LinkedInputConveyors.FirstOrDefault(prop => prop.ConveyorCrane1.Name == Strategy1.PickAction.Source)) != null ? lc.ConveyorCrane2 : null; } // logic for prefferable double pick if (Strategy2.PickAction != null && Strategy2.ForcedInput == null) { Strategy1.ForcedInput = (lc = LinkedInputConveyors.FirstOrDefault(prop => prop.ConveyorCrane2.Name == Strategy2.PickAction.Source)) != null ? lc.ConveyorCrane1 : null; } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new StrategyDoubleForkCraneException(String.Format("{0} StrategyDoubleForkCrane.Refresh failed", Name)); } }