public void Register(ProcedureItemSelected ProcedureItem, RobotUnity robot, OrderItem orderItem)
        {
            CleanUp();
            switch (ProcedureItem)
            {
            case ProcedureItemSelected.PROCEDURE_FORLIFT_TO_BUFFER:
            {
                ProcedureForkLiftToBuffer procfb = new ProcedureForkLiftToBuffer(robot, doorService, trafficService);
                procfb.Registry(deviceService);
                ProcedureDataItems profbDataItems = new ProcedureDataItems();
                profbDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocfb = new RegisterProcedureItem()
                {
                    item = procfb, robot = robot, procedureDataItems = profbDataItems
                };
                procfb.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procfb.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                //RegisterProcedureItemList.Add (itemprocfb);
                procfb.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pFB = procfb;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_FORKLIFT_TO_BUFFER;
                procfb.Registry(robotManagementService);
                procfb.Start();

                break;
            }

            case ProcedureItemSelected.PROCEDURE_BUFFER_TO_MACHINE:
                ProcedureBufferToMachine procbm = new ProcedureBufferToMachine(robot, trafficService);
                procbm.Registry(deviceService);
                ProcedureDataItems prcobmDataItems = new ProcedureDataItems();
                prcobmDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocbm = new RegisterProcedureItem()
                {
                    item = procbm, robot = robot, procedureDataItems = prcobmDataItems
                };
                procbm.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procbm.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                //RegisterProcedureItemList.Add (itemprocbm);
                procbm.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pBM = procbm;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_BUFFER_TO_MACHINE;
                procbm.Registry(robotManagementService);
                procbm.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_BUFFER_TO_RETURN:
                ProcedureBufferToReturn procbr          = new ProcedureBufferToReturn(robot, trafficService);
                ProcedureDataItems      prcobrDataItems = new ProcedureDataItems();
                prcobrDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocbr = new RegisterProcedureItem()
                {
                    item = procbr, robot = robot, procedureDataItems = prcobrDataItems
                };
                procbr.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procbr.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocbr);
                procbr.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pBR = procbr;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_BUFFER_TO_RETURN;
                procbr.Registry(robotManagementService);
                procbr.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_PALLETEMPTY_MACHINE_TO_RETURN:
                ProcedureMachineToReturn procmr          = new ProcedureMachineToReturn(robot, trafficService);
                ProcedureDataItems       prcomrDataItems = new ProcedureDataItems();
                prcomrDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocmr = new RegisterProcedureItem()
                {
                    item = procmr, robot = robot, procedureDataItems = prcomrDataItems
                };
                procmr.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procmr.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                //RegisterProcedureItemList.Add (itemprocmr);
                procmr.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pMR = procmr;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_MACHINE_TO_RETURN;
                procmr.Registry(robotManagementService);
                procmr.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_RETURN_TO_GATE:
                ProcedureReturnToGate procrg         = new ProcedureReturnToGate(robot, doorService, trafficService);
                ProcedureDataItems    prorgDataItems = new ProcedureDataItems();
                prorgDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocrg = new RegisterProcedureItem()
                {
                    item = procrg, robot = robot, procedureDataItems = prorgDataItems
                };
                procrg.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procrg.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocrg);
                procrg.AssignAnOrder(orderItem);
                procrg.Registry(robotManagementService);
                procrg.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_ROBOT_TO_CHARGE:
                ProcedureRobotToCharger procrc          = new ProcedureRobotToCharger(robot, chargerService, robot.properties.ChargeID);
                ProcedureDataItems      procrcDataItems = new ProcedureDataItems();
                procrcDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocrc = new RegisterProcedureItem()
                {
                    item = procrc, robot = robot, procedureDataItems = procrcDataItems
                };
                procrc.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procrc.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                //  RegisterProcedureItemList.Add (itemprocrc);
                robot.proRegistryInRobot.pRC = procrc;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_CHARGE;
                procrc.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_ROBOT_TO_READY:
                robot.ShowText(robot.properties.Label + "Add PROCEDURE_ROBOT_TO_READY ----------(--___--)---------------");
                ProcedureRobotToReady procrr          = new ProcedureRobotToReady(robot, robot.properties.ChargeID, trafficService, chargerService, null);
                ProcedureDataItems    procrrDataItems = new ProcedureDataItems();
                procrrDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocrr = new RegisterProcedureItem()
                {
                    item = procrr, robot = robot, procedureDataItems = procrrDataItems
                };
                procrr.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procrr.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocrr);
                robot.proRegistryInRobot.pRR = procrr;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_READY;
                procrr.Registry(deviceService);
                procrr.Registry(robotManagementService);
                procrr.Registry(assigmentTask);
                procrr.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_ROBOT_READY_TO_READY:
                ProcedureRobotToReady procRrr          = new ProcedureRobotToReady(robot, robot.properties.ChargeID, trafficService, chargerService, doorService.DoorMezzamineUp.config.PointCheckInGate);
                ProcedureDataItems    procRrrDataItems = new ProcedureDataItems();
                procRrrDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocRrr = new RegisterProcedureItem()
                {
                    item = procRrr, robot = robot, procedureDataItems = procRrrDataItems
                };
                procRrr.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procRrr.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add(itemprocRrr);
                robot.proRegistryInRobot.pRR = procRrr;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_READY;
                procRrr.Registry(robotManagementService);
                procRrr.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_FORLIFT_TO_MACHINE:
                ProcedureForkLiftToMachine procfm         = new ProcedureForkLiftToMachine(robot, doorService, trafficService);
                ProcedureDataItems         profmDataItems = new ProcedureDataItems();
                profmDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocfm = new RegisterProcedureItem()
                {
                    item = procfm, robot = robot, procedureDataItems = profmDataItems
                };
                procfm.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procfm.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                //RegisterProcedureItemList.Add(itemprocfm);
                procfm.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pFM = procfm;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_FORKLIFT_TO_MACHINE;
                procfm.Registry(robotManagementService);
                procfm.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_BUFFER_TO_BUFFER:
                ProcedureBufferReturnToBuffer401 procbb = new ProcedureBufferReturnToBuffer401(robot, trafficService);
                ProcedureDataItems prcobbDataItems      = new ProcedureDataItems();
                prcobbDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocbb = new RegisterProcedureItem()
                {
                    item = procbb, robot = robot, procedureDataItems = prcobbDataItems
                };
                procbb.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procbb.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocbr);
                procbb.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pBB = procbb;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_BUFFER_TO_BUFFER;
                procbb.Registry(robotManagementService);
                procbb.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_BUFFER_TO_GATE:
                ProcedureBufferToGate procbg         = new ProcedureBufferToGate(robot, doorService, trafficService);
                ProcedureDataItems    probgDataItems = new ProcedureDataItems();
                probgDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocbg = new RegisterProcedureItem()
                {
                    item = procbg, robot = robot, procedureDataItems = probgDataItems
                };
                procbg.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procbg.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocrg);
                procbg.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pBG = procbg;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_BUFFER_TO_GATE;
                procbg.Registry(robotManagementService);
                procbg.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_MACHINE_TO_GATE:
                ProcedureMachineToGate procmg         = new ProcedureMachineToGate(robot, doorService, trafficService);
                ProcedureDataItems     promgDataItems = new ProcedureDataItems();
                promgDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocmg = new RegisterProcedureItem()
                {
                    item = procmg, robot = robot, procedureDataItems = promgDataItems
                };
                procmg.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procmg.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocrg);
                procmg.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pMG = procmg;
                robot.ProcedureRobotAssigned = ProcedureControlAssign.PRO_MACHINE_TO_GATE;
                procmg.Start();
                break;

            case ProcedureItemSelected.PROCEDURE_MACHINE_TO_BUFFER_RETURN:
                ProcedureMachineToBufferReturn procmbr         = new ProcedureMachineToBufferReturn(robot, trafficService);
                ProcedureDataItems             prombrDataItems = new ProcedureDataItems();
                prombrDataItems.StartTaskTime = DateTime.Now;
                RegisterProcedureItem itemprocmbr = new RegisterProcedureItem()
                {
                    item = procmbr, robot = robot, procedureDataItems = prombrDataItems
                };
                procmbr.ReleaseProcedureHandler += ReleaseProcedureItemHandler;
                procmbr.ErrorProcedureHandler   += ErrorApprearInProcedureItem;
                // RegisterProcedureItemList.Add (itemprocrg);
                procmbr.AssignAnOrder(orderItem);
                robot.proRegistryInRobot.pMBR = procmbr;
                robot.ProcedureRobotAssigned  = ProcedureControlAssign.PRO_MACHINE_TO_BUFFER_RETURN;
                procmbr.Registry(robotManagementService);
                procmbr.Start();
                break;
            }
        }
        public void Procedure(object ojb)
        {
            ProcedureReturnToGate ReToGate = (ProcedureReturnToGate)ojb;
            RobotUnity            rb       = ReToGate.robot;

            // DataReturnToGate p = ReToGate.points;
            ds = ReToGate.door.DoorMezzamineReturn;
            ds.setRb(rb);
            TrafficManagementService Traffic = ReToGate.Traffic;

            rb.mcuCtrl.lampRbOn();
            robot.ShowText(" Start -> " + procedureCode);
            while (ProRun)
            {
                switch (StateReturnToGate)
                {
                case ReturnToGate.RETGATE_IDLE:
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_CHECKIN_RETURN:     // doi robot di den khu vuc checkin cua vung buffer
                    try
                    {
                        if (rb.PreProcedureAs == ProcedureControlAssign.PRO_READY)
                        {
                            if (rb.SendCmdPosPallet(RequestCommandPosPallet.REQUEST_GOBACK_FRONTLINE_TURN_RIGHT))
                            {
                                Stopwatch sw = new Stopwatch();
                                sw.Start();
                                do
                                {
                                    if (resCmd == ResponseCommand.RESPONSE_FINISH_GOBACK_FRONTLINE)
                                    {
                                        if (rb.SendPoseStamped(ReToGate.GetCheckInBuffer()))
                                        {
                                            resCmd            = ResponseCommand.RESPONSE_NONE;
                                            StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_ZONE_RETURN_READY;
                                            robot.ShowText("RETGATE_ROBOT_WAITTING_ZONE_RETURN_READY");
                                            break;
                                        }
                                    }
                                    else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                                    {
                                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                                        CheckUserHandleError(this);
                                        break;
                                    }
                                    if (sw.ElapsedMilliseconds > TIME_OUT_WAIT_GOTO_FRONTLINE)
                                    {
                                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                                        CheckUserHandleError(this);
                                        break;
                                    }
                                    Thread.Sleep(100);
                                } while (ProRunStopW);
                                sw.Stop();
                            }
                        }
                        else
                        {
                            if (rb.SendPoseStamped(ReToGate.GetCheckInBuffer()))
                            {
                                StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_ZONE_RETURN_READY;
                                robot.ShowText("RETGATE_ROBOT_WAITTING_ZONE_RETURN_READY");
                            }
                        }
                    }
                    catch (System.Exception)
                    {
                        errorCode = ErrorCode.CAN_NOT_GET_DATA;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_ZONE_RETURN_READY:     // doi khu vuc buffer san sang de di vao
                    try
                    {
                        if (false == robot.CheckInZoneBehavior(ReToGate.GetFrontLineReturn().Position))
                        {
                            if (rb.SendPoseStamped(ReToGate.GetFrontLineReturn()))
                            {
                                StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_CAME_FRONTLINE_RETURN;
                                robot.ShowText("RETGATE_ROBOT_WAITTING_CAME_FRONTLINE_RETURN");
                            }
                        }
                    }
                    catch (System.Exception)
                    {
                        errorCode = ErrorCode.CAN_NOT_GET_DATA;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_CAME_FRONTLINE_RETURN:
                    try
                    {
                        if (resCmd == ResponseCommand.RESPONSE_LASER_CAME_POINT)
                        {
                            resCmd            = ResponseCommand.RESPONSE_NONE;
                            StateReturnToGate = ReturnToGate.RETGATE_ROBOT_SEND_CMD_PICKUP_PALLET;
                        }
                        else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                        {
                            errorCode = ErrorCode.DETECT_LINE_ERROR;
                            CheckUserHandleError(this);
                        }
                    }
                    catch (System.Exception)
                    {
                        errorCode = ErrorCode.CAN_NOT_GET_DATA;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_SEND_CMD_PICKUP_PALLET:
                    if (rb.SendCmdAreaPallet(ReToGate.GetInfoOfPalletReturn(PistonPalletCtrl.PISTON_PALLET_UP)))
                    {
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_PICKUP_PALLET_RETURN;
                        robot.ShowText("RETGATE_ROBOT_WAITTING_PICKUP_PALLET_RETURN");
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_PICKUP_PALLET_RETURN:
                    if (resCmd == ResponseCommand.RESPONSE_LINEDETECT_PALLETUP)
                    {
                        resCmd = ResponseCommand.RESPONSE_NONE;
                        ReToGate.UpdatePalletState(PalletStatus.F, order.palletId_H, order.planId);
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_RETURN;
                        robot.ShowText("RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_RETURN");
                    }
                    else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                    {
                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_RETURN:     // đợi
                    if (resCmd == ResponseCommand.RESPONSE_FINISH_GOBACK_FRONTLINE)
                    {
                        //rb.prioritLevel.OnAuthorizedPriorityProcedure = false;
                        if (rb.SendPoseStamped(ds.config.PointCheckInGate))
                        {
                            resCmd            = ResponseCommand.RESPONSE_NONE;
                            StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_CHECKIN_GATE;
                            robot.ShowText("RETGATE_ROBOT_WAITTING_GOTO_CHECKIN_GATE");
                        }
                    }
                    else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                    {
                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                        CheckUserHandleError(this);
                    }
                    break;

                // case ReturnToGate.RETGATE_ROBOT_GOTO_CHECKIN_GATE: //gui toa do di den khu vuc checkin cong
                //     rb.SendPoseStamped(ds.config.PointCheckInGate);
                //     StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_CHECKIN_GATE;
                //     break;
                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_CHECKIN_GATE:
                    if (resCmd == ResponseCommand.RESPONSE_LASER_CAME_POINT)
                    {
                        resCmd = ResponseCommand.RESPONSE_NONE;
                        //rb.prioritLevel.OnAuthorizedPriorityProcedure = true;
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_CAME_CHECKIN_GATE;
                        robot.ShowText("RETGATE_ROBOT_CAME_CHECKIN_GATE");
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_CAME_CHECKIN_GATE:     // đã đến vị trí, kiem tra va cho khu vuc cong san sang de di vao.
                    if (false == robot.CheckInZoneBehavior(ds.config.PointFrontLine.Position))
                    {
                        //rb.prioritLevel.OnAuthorizedPriorityProcedure = false;
                        if (rb.SendPoseStamped(ds.config.PointFrontLine))
                        {
                            StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_GATE;
                            robot.ShowText("RETGATE_ROBOT_WAITTING_GOTO_GATE");
                        }
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_GATE:
                    if (Traffic.RobotIsInArea("GATE3", rb.properties.pose.Position))
                    {
                        ds.setDoorBusy(true);
                        ds.openDoor(DoorService.DoorType.DOOR_BACK);
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_GATE_OPENDOOR;
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOTO_GATE_OPENDOOR:
                    if (resCmd == ResponseCommand.RESPONSE_LASER_CAME_POINT)
                    {
                        resCmd = ResponseCommand.RESPONSE_NONE;
                        //rb.prioritLevel.OnAuthorizedPriorityProcedure = true;
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_CAME_GATE_POSITION;
                        robot.ShowText("RETGATE_ROBOT_CAME_GATE_POSITION");
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_CAME_GATE_POSITION:     // da den khu vuc cong , gui yeu cau mo cong.
                    //ds.setDoorBusy(true);
                    //ds.openDoor(DoorService.DoorType.DOOR_BACK);
                    StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_OPEN_DOOR;
                    robot.ShowText("RETGATE_ROBOT_WAITTING_OPEN_DOOR");
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_OPEN_DOOR:     //doi mo cong
                    RetState ret = ds.checkOpen(DoorService.DoorType.DOOR_BACK);
                    if (ret == RetState.DOOR_CTRL_SUCCESS)
                    {
                        if (rb.SendCmdAreaPallet(ds.config.infoPallet))
                        {
                            StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_DROPDOWN_PALLET_RETURN;
                            robot.ShowText("RETGATE_ROBOT_WAITTING_DROPDOWN_PALLET_RETURN");
                        }
                    }
                    else if (ret == RetState.DOOR_CTRL_ERROR)
                    {
                        robot.ShowText("RETGATE_ROBOT_WAITTING_OPEN_DOOR_ERROR__(-_-)");
                        Thread.Sleep(1000);
                        ds.setDoorBusy(true);
                        ds.openDoor(DoorService.DoorType.DOOR_BACK);
                    }
                    break;

                // case ReturnToGate.RETGATE_ROBOT_OPEN_DOOR_SUCCESS: // mo cua thang cong ,gui toa do line de robot di vao
                //     rb.SendCmdLineDetectionCtrl(RequestCommandLineDetect.REQUEST_LINEDETECT_PALLETDOWN);
                //     StateReturnToGate = ReturnToGate.RETGATE_ROBOT_GOTO_POSITION_PALLET_RETURN;
                //     break;
                // case ReturnToGate.RETGATE_ROBOT_GOTO_POSITION_PALLET_RETURN:
                //     if (true == rb.CheckPointDetectLine(ds.config.PointOfPallet, rb))
                //     {
                //         rb.SendCmdPosPallet(RequestCommandPosPallet.REQUEST_LINEDETECT_COMING_POSITION);
                //         StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_DROPDOWN_PALLET_RETURN;
                //     }
                //     break;
                case ReturnToGate.RETGATE_ROBOT_WAITTING_DROPDOWN_PALLET_RETURN:     // doi robot gap hang
                    if (resCmd == ResponseCommand.RESPONSE_LINEDETECT_PALLETDOWN)
                    {
                        resCmd = ResponseCommand.RESPONSE_NONE;
                        // ReToGate.UpdatePalletState(PalletStatus.W);
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_GATE;
                        robot.ShowText("RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_GATE");
                    }
                    else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                    {
                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_GOBACK_FRONTLINE_GATE:
                    if (resCmd == ResponseCommand.RESPONSE_FINISH_GOBACK_FRONTLINE)
                    {
                        resCmd = ResponseCommand.RESPONSE_NONE;
                        ds.closeDoor(DoorService.DoorType.DOOR_BACK);
                        ds.setDoorBusy(false);
                        StateReturnToGate = ReturnToGate.RETGATE_ROBOT_WAITTING_CLOSE_GATE;
                        robot.ShowText("RETGATE_ROBOT_WAITTING_CLOSE_GATE");
                    }
                    else if (resCmd == ResponseCommand.RESPONSE_ERROR)
                    {
                        errorCode = ErrorCode.DETECT_LINE_ERROR;
                        CheckUserHandleError(this);
                    }
                    break;

                case ReturnToGate.RETGATE_ROBOT_WAITTING_CLOSE_GATE:     // doi dong cong.
                    //if (true == ds.WaitClose(DoorService.DoorType.DOOR_BACK, TIME_OUT_CLOSE_DOOR))
                    //{
                    StateReturnToGate = ReturnToGate.RETGATE_ROBOT_RELEASED;
                    //rb.prioritLevel.OnAuthorizedPriorityProcedure = false;
                    robot.ShowText("RETGATE_ROBOT_WAITTING_CLOSE_GATE");
                    //}
                    //else
                    //{
                    //    errorCode = ErrorCode.CLOSE_DOOR_ERROR;
                    //    CheckUserHandleError(this);
                    //}
                    break;

                case ReturnToGate.RETGATE_ROBOT_RELEASED:     // trả robot về robotmanagement để nhận quy trình mới
                    ds.removeListCtrlDoorBack();
                    robot.robotTag    = RobotStatus.IDLE;
                    rb.PreProcedureAs = ProcedureControlAssign.PRO_RETURN_TO_GATE;
                    // if (errorCode == ErrorCode.RUN_OK) {
                    ReleaseProcedureHandler(this);
                    // } else {
                    // ErrorProcedureHandler (this);
                    // }
                    ProRun = false;
                    robot.ShowText("RELEASED");
                    UpdateInformationInProc(this, ProcessStatus.S);
                    order.endTimeProcedure   = DateTime.Now;
                    order.totalTimeProcedure = order.endTimeProcedure.Subtract(order.startTimeProcedure).TotalMinutes;
                    KillEvent();
                    break;

                default:
                    break;
                }
                Thread.Sleep(5);
            }
            StateReturnToGate = ReturnToGate.RETGATE_IDLE;
        }