Example #1
0
 private ControllerOperationStatus Sort(TabletMagazine mag, CancellationToken ct)
 {
     var status = ControllerOperationStatus.Succeeded;
     try
     {
         List<Tablet> visibleTablets = null;
         while ((visibleTablets = GetVisibleTablets()).Count > 0)
         {
             var tablet = visibleTablets[0];
             Logger.Instance.Write(String.Format("[Sorter] Seen ({0}) tablet seen at ({1},{2}) in camera space",
                 tablet.Color, tablet.LocationPoint.X, tablet.LocationPoint.Y));
             if (mag.IsFull() || ct.IsCancellationRequested)
             {
                 status = ControllerOperationStatus.Cancelled;
                 return status;
             }
             if (!mag.IsSlotFull(tablet.Color))
             {
                 PlaceTablet(tablet, mag);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Instance.Write(new LogEntry(ex));
         status = ControllerOperationStatus.Failed;
     }
     return status;
 }
Example #2
0
 private void SortAsync(TabletMagazine mag)
 {
     var ct = _cancelTokenSource.Token;
     Task.Run(() =>
     {
         var status = Sort(mag, ct);
         IsRunning = false;
         OnCompleted(new SorterCompletedEventArgs()
         {
             OperationStatus = status,
             Action = SorterAction.Sort
         });
     }, ct);
 }
Example #3
0
 private void PlaceTablet(Tablet tablet, TabletMagazine mag)
 {
     var p = TransformToRobotSpace(tablet.LocationPoint);
     Logger.Instance.Write(String.Format("[Sorter] Picking ({0}) tablet from ({1},{2}) in robot space",
                 tablet.Color, p.X, p.Y));
     _robot.GetTablet(p.X, p.Y, mag.GetSlotIndex(tablet.Color));
     mag.AddTablet(tablet.Color);
 }
Example #4
0
 public bool canCompleteOrder(TabletMagazine mag, OrderConfiguration orderConfiguration)
 {
     foreach (var pair in orderConfiguration.Tablets.Where(x => x.Value > 0))
     {
         if (pair.Value > mag.GetSlotDepth(pair.Key))
         {
             return false;
         }
     }
     return true;
 }
Example #5
0
 private void AssembleAsync(TabletMagazine mag, OrderConfiguration orderConfiguration)
 {
     var ct = _cancelTokenSource.Token;
         Task.Run(() =>
         {
             var status = Assemble(mag, orderConfiguration, ct);
             IsRunning = false;
             OnCompleted(new AssemblerEventArgs()
             {
                 OperationStatus = status,
                 AssemblerOperationStatus = AssemblerOperationStatus.Normal
             });
         }, ct);
 }
Example #6
0
        private ControllerOperationStatus Assemble(TabletMagazine mag, OrderConfiguration orderConfiguration, CancellationToken ct)
        {
            var status = ControllerOperationStatus.Succeeded;
            try
            {
                var tray = MapOrderToTray(orderConfiguration);
                for (int i = 0; i < tray.Cells.Count; i++)
                {
                    var tablet = tray.Cells[i];

                    if(tablet == null)
                    {
                        continue;
                    }

                    if (ct.IsCancellationRequested)
                    {
                        status = ControllerOperationStatus.Cancelled;
                        return status;
                    }
                    else
                    {
                        var slotDepth = mag.GetSlotDepth(tablet.Color);
                        mag.RemoveTablet(tablet.Color);
                        var slotIndex = mag.GetSlotIndexReversed(tablet.Color);
                        Logger.Instance.Write(String.Format("[Assembler] Placing ({0}) tablet from slot {1} into slot {2}",
                            tablet.Color, slotIndex, i));
                        _assemblerRobot.PlaceTablet(slotIndex, slotDepth, i);
                    }
                }
                status = ControllerOperationStatus.Succeeded;
                LastOrderTray = tray;
            }
            catch (Exception ex)
            {
                var outer = new Exception("[Assembler] Assembler failed to assemble.", ex);
                Logger.Instance.Write(new LogEntry(outer));
                status = ControllerOperationStatus.Failed;
            }
            return status;
        }
Example #7
0
        private bool Create(string configFile)
        {
            try
            {
                this.ClusterConfig = ClusterFactory.Instance.CreateCluster(configFile);

                this.EnvironmentMonitor = new EnvironmentMonitor(this.ClusterConfig);
                this.HardwareMonitor = new HardwareMonitor(this.ClusterConfig);
                this.TabletMagazine = new TabletMagazine();
                this.OrderConsumer = new OrderConsumer();
                this._sequencer = new FSMSequencer(this);
                this._eStopMonitor = new EmergencyStopMonitor(this);
            }
            catch (Exception ex)
            {
                var outer = new Exception("Unable to initialise the SCADA system", ex);

                Logger.Instance.Write(new LogEntry(outer, LogType.Error));
                return false;
            }
            this.StartAllTimers();
            return true;
        }