// 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); }