public void Move(int id, CellLocation dst) { var item = ItemDatabase.Instance().GetItem(id); if (item.Moving) { Console.WriteLine("MOVE: item is already moving, ignoring request"); return; } ForkLoader current = item.Place.Rack == Side.Left ? LeftForkLoader : RightForkLoader; current.EnqueueUnloadRequest(new UnloadRequest(id, dst.Rack == Side.Left? Item.Destination.Left : Item.Destination.Right, dst)); }
public void Unload(int id) { // TODO: cancel movement var item = ItemDatabase.Instance().GetItem(id); if (item.Moving) { item.PendingForOut = true; Console.WriteLine("UNLOAD: Item is moving: scheduling unload"); } else if (item.Dest == Item.Destination.Out) { Console.WriteLine("UNLOAD: Already unloaded"); } else { ForkLoader current = item.Place.Rack == Side.Left ? LeftForkLoader : RightForkLoader; current.EnqueueUnloadRequest(new UnloadRequest(id, Item.Destination.Out)); Console.WriteLine("UNLOAD: Item is *not* moving: unloading now"); } }
public StorageController() { M.reset.Value = true; MemoryMap.Instance.Update(); Thread.Sleep(32); M.reset.Value = false; // M.pause.Value = false; // M.run.Value = true; MemoryMap.Instance.Update(); Thread.Sleep(32); LeftForkLoader = new ForkLoader(M.targetPositionA, M.forksLeftA, M.forksRightA, M.liftA, M.movingXA, M.movingZA, M.atLeftA, M.atRightA, M.atMiddleA, RLeftLoad, RLeftUnload, Side.Left); RightForkLoader = new ForkLoader(M.targetPositionB, M.forksLeftB, M.forksRightB, M.liftB, M.movingXB, M.movingZB, M.atLeftB, M.atRightB, M.atMiddleB, RRightLoad, RRightUnload, Side.Right); Updater = new Task(() => { Console.WriteLine("Updater Started"); while (true) { Thread.Sleep(8); MemoryMap.Instance.Update(); } }); Updater.Start(); Console.WriteLine("After Updater"); JTopLeft = new Junction(M.csA) .SetInputs(new JunctionInput(RLeftUnload, M.ctAp)) .SetOutputs(new JunctionOutput(RLeftToRight, M.ctAp), new JunctionOutput(RDown, M.ctAR)) .SetRoutingTable(new Dictionary <Item.Destination, int> { { Item.Destination.Right, 0 }, { Item.Destination.Out, 1 }, { Item.Destination.Left, 1 } }) .Start(); JTopRight = new Junction(M.csB) .SetInputs(new JunctionInput(RUp, M.ctBL), new JunctionInput(RLeftToRight, M.ctBp)) .SetOutputs(new JunctionOutput(RRightLoad, M.ctBp)) .SetRoutingTable(new Dictionary <Item.Destination, int>() { { Item.Destination.Right, 0 } }) .Start(); JLeft = new DoubleJunction(M.cs1A, M.cs1, M.ct1AR, M.ct1L, M.ct1AL, M.ct1R) .SetTopInputs(new JunctionInput(RLeftBackward, M.ct1Ap)) .SetBottomInputs(new JunctionInput(RInput, M.ct1p)) .SetTopOutputs(new JunctionOutput(RLeftLoad, M.ct1AR)) .SetBottomOutputs(new JunctionOutput(RLeftForward, M.ct1p)) .SetRoutingTable(new Dictionary <Item.Destination, int>() { { Item.Destination.Left, 0 }, { Item.Destination.Right, 1 }, { Item.Destination.Out, 1 } }) .Start(); JMiddleLeft = new DoubleJunction(M.cs2A, M.cs2, M.ct2AR, M.ct2L, M.ct2AL, M.ct2R) .SetTopInputs(new JunctionInput(RDown, M.ct2AL), new JunctionInput(RMiddleBackward, M.ct2Ap)) .SetBottomInputs(new JunctionInput(RLeftForward, M.ct2p)) .SetTopOutputs(new JunctionOutput(RLeftBackward, M.ct2Ap)) .SetBottomOutputs(new JunctionOutput(RMiddleForward, M.ct2p)) .SetRoutingTable(new Dictionary <Item.Destination, int>() { { Item.Destination.Left, 0 }, { Item.Destination.Right, 1 }, { Item.Destination.Out, 1 } }) .Start(); JMiddleRight = new DoubleJunction(M.cs3B, M.cs3, M.ct3BR, M.ct3L, M.ct3BL, M.ct3R) .SetTopInputs(new JunctionInput(RRightBackward, M.ct3Bp)) .SetBottomInputs(new JunctionInput(RMiddleForward, M.ct3p)) .SetTopOutputs(new JunctionOutput(RUp, M.ct3BR), new JunctionOutput(RMiddleBackward, M.ct3Bp)) .SetBottomOutputs(new JunctionOutput(RRightForward, M.ct3p)) .SetRoutingTable(new Dictionary <Item.Destination, int>() { { Item.Destination.Left, 1 }, { Item.Destination.Right, 0 }, { Item.Destination.Out, 2 } }) .Start(); JRight = new DoubleJunction(M.cs4B, M.cs4, M.ct4BR, M.ct4L, M.ct4BL, M.ct4R) .SetTopInputs(new JunctionInput(RRightUnload, M.ct4BL)) .SetBottomInputs(new JunctionInput(RRightForward, M.ct4p)) .SetTopOutputs(new JunctionOutput(RRightBackward, M.ct4Bp)) .SetBottomOutputs(new JunctionOutput(ROutput, M.ct4p)) .SetRoutingTable(new Dictionary <Item.Destination, int>() { { Item.Destination.Left, 0 }, { Item.Destination.Right, 0 }, { Item.Destination.Out, 1 } }) .Start(); LeftForkLoader.Start(); RightForkLoader.Start(); }