Ejemplo n.º 1
0
        public QualityCheck PostQualityCheck(ProductLocation product)
        {
            if (_db.QualityChecks.Any(d => d.EndDate == null))
            {
                return(null);
            }

            // get correct object from database by id
            ProductLocation pr = _db.Locations.Find(product.Id);

            // initiate quality check object
            QualityCheck qualitycheck = new QualityCheck();

            qualitycheck.StartDate       = DateTime.Now;
            qualitycheck.ProductLocation = pr;
            qualitycheck.EndDate         = null;
            _db.QualityChecks.Add(qualitycheck);
            _db.SaveChanges();

            // create commands for quality check
            DroneCommandProcessor commands = createCommands(qualitycheck);

            // Execute quality check
            commands.Execute();

            return(qualitycheck);
        }
Ejemplo n.º 2
0
        // Method to create commands for the drone to execute
        private DroneCommandProcessor createCommands(QualityCheck qc)
        {
            // Get productLocation to take picture from
            ProductLocation pl = qc.ProductLocation;

            // Initiate CommandProcessor
            _droneCommandProcessor = new DroneCommandProcessor();

            // Get Graph datastructure in pathfinder generated from selected warehouse
            IPathfinderFactory pathfinderFactory = new PathfinderFactory();
            Pathfinder         pathfinder        = pathfinderFactory.GetPathfinderFromWarehouse(pl.District.Warehouse);

            // Initiate start position (start position is drone start location)
            Position startNode = new Position(pl.District.Warehouse.StartNode.X, pl.District.Warehouse.StartNode.Y);

            // Get path to take from startposition to nearest graphnode for the Productlocation by using dijkstra algoritm
            LinkedList <Position> path = pathfinder.GetPath(startNode, this.giveEndPosition(pl));

            // save path to qualitycheck for webpage view
            List <Position> path2 = pathfinder.GetPathList(startNode, this.giveEndPosition(pl));
            var             s     = JsonConvert.SerializeObject(path2, Formatting.Indented,
                                                                new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            qc.JSONPath         = s;
            _db.Entry(qc).State = EntityState.Modified;
            _db.SaveChanges();

            // add start / takeoff command to the droneCommandProcessor
            _droneCommandProcessor.AddCommand(new Command {
                name = "Start"
            });

            // add commands to the droneCommandProcessor from path, this generates the commands needed to move to the nearest graphnode to the productlocation
            IMovementCommandFactory mFactory = new MovementCommandFactory();

            _droneCommandProcessor.AddListCommand(mFactory.GetMovementCommands(path));

            // add commands to move from the nearest graphnode to the position in front of the productlocation
            IDistrictCommandFactory dFactory = new DistrictCommandFactory();

            _droneCommandProcessor.AddListCommand(dFactory.GetCommands(giveEndPosition(pl), pl));

            // add command to take picture, this also needs the current quality check id, needed for saving the pictures to the correct location
            _droneCommandProcessor.AddCommand(new Command {
                name = "TakePicture", value = qc.Id
            });

            // add command to land the drone
            _droneCommandProcessor.AddCommand(new Command {
                name = "Land"
            });

            return(_droneCommandProcessor);
        }