Exemplo n.º 1
0
        public void TestStopImmediately()
        {
            var timeout         = TimeSpan.FromMilliseconds(100);
            var memory          = new PLCMemory();
            var customerLogic   = new PLCLogic(new PLCController(memory));
            var mujinController = new PLCController(memory);

            customerLogic.ClearAllSignals();

            // indicate we are ready
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", false },
                { "isRobotMoving", false },
                { "isModeAuto", true },
                { "isSystemReady", true },
                { "isCycleReady", true },
            });
            customerLogic.WaitUntilOrderCycleReady(timeout);

            // start order cycle
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", true },
                { "numLeftInOrder", 1 },
                { "numLeftInLocation1", 1 },
            });
            var status = customerLogic.StartOrderCycle("orderId", "orderPartType", 1, timeout);

            Assert.Equal(true, status.isRunningOrderCycle);
            Assert.Equal(1, status.numLeftInOrder);
            Assert.Equal(1, status.numLeftInLocation1);

            // stop immediately
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRobotMoving", false },
                { "isRunningOrderCycle", false },
                { "numLeftInOrder", 1 },
                { "numLeftInLocation1", 1 },
                { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedStoppedImmediately },
            });
            customerLogic.StopImmediately();

            // controller might reset variables
            // mujinController.Set(new Dictionary<string, object>()
            // {
            //     { "numLeftInOrder", 0 },
            //     { "numLeftInLocation1", 0 },
            //     { "orderCycleFinishCode", 0 },
            // });

            status = customerLogic.GetOrderCycleStatus();
            Assert.Equal(false, status.isRunningOrderCycle);
            Assert.Equal(false, status.isRobotMoving);
            Assert.Equal(1, status.numLeftInOrder);
            Assert.Equal(1, status.numLeftInLocation1);
            Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedStoppedImmediately, status.orderCycleFinishCode);
        }
Exemplo n.º 2
0
        public void TestResetError()
        {
            var timeout         = TimeSpan.FromMilliseconds(100);
            var memory          = new PLCMemory();
            var customerLogic   = new PLCLogic(new PLCController(memory));
            var mujinController = new PLCController(memory);

            customerLogic.ClearAllSignals();

            // indicate we are ready
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", false },
                { "isRobotMoving", false },
                { "isModeAuto", true },
                { "isSystemReady", true },
                { "isCycleReady", true },
            });
            customerLogic.WaitUntilOrderCycleReady(timeout);

            // start order cycle
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", true },
                { "numLeftInOrder", 1 },
                { "numLeftInLocation1", 1 },
            });
            var status = customerLogic.StartOrderCycle("orderId", "orderPartType", 1, timeout);

            Assert.Equal(true, status.isRunningOrderCycle);
            Assert.Equal(1, status.numLeftInOrder);
            Assert.Equal(1, status.numLeftInLocation1);

            // set error
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRobotMoving", false },
                { "isRunningOrderCycle", false },
                { "numLeftInOrder", 1 },
                { "numLeftInLocation1", 1 },
                { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedPlanningFailure },
                { "isError", true },
                { "errorcode", (int)PLCLogic.PLCErrorCode.PlanningError },
            });
            var e = Assert.Throws <PLCLogic.PLCError>(() =>
            {
                customerLogic.WaitUntilOrderCycleFinish();
            });

            Assert.Equal(PLCLogic.PLCErrorCode.PlanningError, e.errorcode);
            //Assert.Equal(0, e.detailedErrorCode);

            status = customerLogic.GetOrderCycleStatus();
            Assert.Equal(false, status.isRunningOrderCycle);
            Assert.Equal(false, status.isRobotMoving);
            Assert.Equal(1, status.numLeftInOrder);
            Assert.Equal(1, status.numLeftInLocation1);
            Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedPlanningFailure, status.orderCycleFinishCode);

            // reset error
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isError", false },
                { "errorcode", 0 },
                { "orderCycleFinishCode", 0 },
            });
            customerLogic.ResetError();

            status = customerLogic.GetOrderCycleStatus();
            Assert.Equal(false, status.isRunningOrderCycle);
            Assert.Equal(false, status.isRobotMoving);
            Assert.Equal(1, status.numLeftInOrder);
            Assert.Equal(1, status.numLeftInLocation1);
            Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedNotAvailable, status.orderCycleFinishCode);
        }
Exemplo n.º 3
0
        public void TestOrderCycle(string orderId, string orderPartType, int orderNumber, int supplyNumber)
        {
            var timeout         = TimeSpan.FromMilliseconds(100);
            var memory          = new PLCMemory();
            var customerLogic   = new PLCLogic(new PLCController(memory));
            var mujinController = new PLCController(memory);

            customerLogic.ClearAllSignals();

            // indicate we are ready
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", false },
                { "isRobotMoving", false },
                { "isModeAuto", true },
                { "isSystemReady", true },
                { "isCycleReady", true },
            });
            customerLogic.WaitUntilOrderCycleReady(timeout);

            // start order cycle
            mujinController.Set(new Dictionary <string, object>()
            {
                { "isRunningOrderCycle", true },
                { "numLeftInOrder", orderNumber },
                { "numLeftInLocation1", supplyNumber },
            });
            var status = customerLogic.StartOrderCycle(orderId, orderPartType, orderNumber, timeout);

            Assert.Equal(true, status.isRunningOrderCycle);
            Assert.Equal(orderNumber, status.numLeftInOrder);
            Assert.Equal(supplyNumber, status.numLeftInLocation1);

            // check order status
            while (true)
            {
                mujinController.Set(new Dictionary <string, object>()
                {
                    { "isRobotMoving", true },
                    { "numLeftInOrder", orderNumber },
                    { "numLeftInLocation1", supplyNumber },
                });
                status = customerLogic.GetOrderCycleStatus(timeout);
                Assert.Equal(true, status.isRobotMoving);
                Assert.Equal(orderNumber, status.numLeftInOrder);
                Assert.Equal(supplyNumber, status.numLeftInLocation1);

                if (orderNumber <= 0 || supplyNumber <= 0)
                {
                    break;
                }

                orderNumber--;
                supplyNumber--;
            }

            if (orderNumber == 0)
            {
                mujinController.Set(new Dictionary <string, object>()
                {
                    { "isRobotMoving", false },
                    { "isRunningOrderCycle", false },
                    { "numLeftInOrder", orderNumber },
                    { "numLeftInLocation1", supplyNumber },
                    { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedOrderComplete },
                });
                status = customerLogic.WaitUntilOrderCycleFinish(timeout);
                Assert.Equal(false, status.isRunningOrderCycle);
                Assert.Equal(false, status.isRobotMoving);
                Assert.Equal(0, status.numLeftInOrder);
                Assert.Equal(supplyNumber, status.numLeftInLocation1);
                Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedOrderComplete, status.orderCycleFinishCode);
            }
            else
            {
                mujinController.Set(new Dictionary <string, object>()
                {
                    { "isRobotMoving", false },
                    { "isRunningOrderCycle", false },
                    { "numLeftInOrder", orderNumber },
                    { "numLeftInLocation1", supplyNumber },
                    { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedNoMoreTargets },
                });
                status = customerLogic.WaitUntilOrderCycleFinish(timeout);
                Assert.Equal(false, status.isRunningOrderCycle);
                Assert.Equal(false, status.isRobotMoving);
                Assert.Equal(orderNumber, status.numLeftInOrder);
                Assert.Equal(0, status.numLeftInLocation1);
                Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedNoMoreTargets, status.orderCycleFinishCode);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var           memory     = new PLCMemory();
            PLCController controller = new PLCController(memory, TimeSpan.FromSeconds(1.0));
            var           logic      = new PLCLogic(controller);
            var           server     = new PLCServer(memory, "tcp://*:5555");

            Console.WriteLine("Starting server to listen on {0} ...", server.Address);
            server.Start();

            Console.WriteLine("Waiting for controller connection ...");
            logic.WaitUntilConnected();
            Console.WriteLine("Controller connected.");

            try
            {
                if (controller.GetBoolean("isError"))
                {
                    Console.WriteLine("controller is in error 0x{0:X}, resetting", controller.Get("errorcode"));
                    logic.ResetError();
                }

                if (controller.GetBoolean("isRunningOrderCycle"))
                {
                    Console.WriteLine("previous cycle already running, so stop and wait");
                    logic.StopOrderCycle();
                }

                Console.WriteLine("Waiting for cycle ready...");
                logic.WaitUntilOrderCycleReady();

                Console.WriteLine("Starting order cycle ...");
                PLCLogic.PLCOrderCycleStatus status;
                if (true)
                {
                    // first work piece
                    controller.Set("orderRobotId", 1);
                    status = logic.StartOrderCycle("123", "work1", 1);
                }
                else
                {
                    // for the second work piece do
                    controller.Set("orderRobotId", 2);
                    status = logic.StartOrderCycle("123", "work2_b", 1);
                }
                Console.WriteLine("Order cycle started. numLeftInOrder = {0}, numLeftInLocation1 = {1}.", status.numLeftInOrder, status.numLeftInLocation1);

                while (true)
                {
                    status = logic.WaitForOrderCycleStatusChange();
                    if (!status.isRunningOrderCycle)
                    {
                        Console.WriteLine("Cycle finished. {0}", status.orderCycleFinishCode);
                        break;
                    }
                    Console.WriteLine("Cycle running. numLeftInOrder = {0}, numLeftInLocation1 = {1}.", status.numLeftInOrder, status.numLeftInLocation1);
                }
            }
            catch (PLCLogic.PLCError e)
            {
                Console.WriteLine("PLC Error. {0}", e.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey(true);

            server.Stop();
        }