示例#1
0
 private static void ReadCommand(ICommand command, IRobotAction printCommand)
 {
     while (true)
     {
         var commandtxt = Console.ReadLine();
         try
         {
             rover = command.ExecuteCommand(rover, commandtxt);
         }
         catch (Exception ex)
         {
             Console.ForegroundColor = ConsoleColor.Yellow;
             Console.WriteLine(ex.Message);
             Console.ResetColor();
         }
         Print(printCommand);
     }
 }
        public void Initialise()
        {
            var mockLogger = new Mock <ILogger>();

            robotAction = new RobotAction(mockLogger.Object);
        }
示例#3
0
 public RobotCommander(ILogger logger, IRobotAction iRobotAction)
 {
     _logger      = logger;
     _robotAction = iRobotAction;
 }
示例#4
0
 public IRobot ExecuteCommand(IRobot rover, string commandText)
 {
     ValidateCommand(commandText);
     robotAction = robotActionResolver.GetRobotAction(commandText);
     return(robotAction.Excecute(rover));
 }
示例#5
0
 private static void Print(IRobotAction printCommand)
 {
     rover = printCommand.Excecute(rover);
     Console.WriteLine(rover.FormattedString);
 }
        /// <summary>
        /// 执行动作
        /// </summary>
        public void DoAction(ModeEnum mode, ActionEnum action)
        {
            Reset();
            startTicks = DateTime.Now.Ticks;

            LumbarRobotController.RobotController.ControlCommand.PauseCmd();
            Thread.Sleep(10);
            LumbarRobotController.RobotController.ControlCommand.PauseCmd();
            Thread.Sleep(10);
            if (mode == ModeEnum.Fit)
            {
                if (action == ActionEnum.Bend || action == ActionEnum.Protrusive || action == ActionEnum.ProtrusiveOrBend)
                {
                    if (bendStretchFitAction == null)
                    {
                        bendStretchFitAction = new BendStretchFitAction();
                        bendStretchFitAction.StartAction += new EventHandler(action_StartAction);
                    }
                    bendStretchFitAction.Mode = mode;
                    bendStretchFitAction.Action = action;
                    currentControl = bendStretchFitAction;
                }
                else if(action == ActionEnum.Rotation)
                {
                    if (rotateFitAction == null)
                    {
                        rotateFitAction = new RotateFitAction();
                        rotateFitAction.StartAction += new EventHandler(action_StartAction);
                    }
                    rotateFitAction.Mode = mode;
                    rotateFitAction.Action = action;
                    currentControl = rotateFitAction;
                }
            }
            else if (mode == ModeEnum.StrengthEvaluation)
            {
                if (action == ActionEnum.Bend || action == ActionEnum.Protrusive || action == ActionEnum.ProtrusiveOrBend)
                {
                    if (bendStrechStrengthEvaluationAction == null)
                    {
                        bendStrechStrengthEvaluationAction = new BendStrechStrengthEvaluationAction();
                        bendStrechStrengthEvaluationAction.StartAction += new EventHandler(action_StartAction);
                        bendStrechStrengthEvaluationAction.SetForce += new SetForceHandler(action_SetForce);
                    }
                    bendStrechStrengthEvaluationAction.Mode = mode;
                    bendStrechStrengthEvaluationAction.Action = action;
                    currentControl = bendStrechStrengthEvaluationAction;
                }
                else if (action == ActionEnum.Rotation)
                {
                    if (rotateStrengthEvaluationAction == null)
                    {
                        rotateStrengthEvaluationAction = new RotateStrengthEvaluationAction();
                        rotateStrengthEvaluationAction.StartAction += new EventHandler(action_StartAction);
                        rotateStrengthEvaluationAction.SetForce += new SetForceHandler(action_SetForce);
                    }
                    rotateStrengthEvaluationAction.Mode = mode;
                    rotateStrengthEvaluationAction.Action = action;
                    currentControl = rotateStrengthEvaluationAction;
                }
            }
            else
            {

                if (action == ActionEnum.Bend)
                {
                    if (mode == ModeEnum.Sokoban || mode == ModeEnum.Free || mode == ModeEnum.FreeConstantResistance || mode == ModeEnum.FreeCounterWeight || mode == ModeEnum.Dengsu || mode == ModeEnum.Lixin)
                    {
                        if (bendStretchFreeAction == null)
                        {
                            bendStretchFreeAction = new BendStretchFreeAction();
                            bendStretchFreeAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchFreeAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchFreeAction.StartAction += new EventHandler(action_StartAction);
                        }
                        //bendStretchFreeAction.ModeEnum = mode;
                        //bendStretchFreeAction.ActionEnum = action;
                        currentControl = bendStretchFreeAction;
                    }
                    else if (mode == ModeEnum.Guided)
                    {
                        if (bendStretchGuidedAction == null)
                        {
                            bendStretchGuidedAction = new BendStretchGuidedAction();
                            bendStretchGuidedAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchGuidedAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchGuidedAction.StartAction += new EventHandler(action_StartAction);
                        }
                        currentControl = bendStretchGuidedAction;
                    }
                    else if (mode == ModeEnum.Initiated)
                    {
                        if (bendStretchAssistedAction == null)
                        {
                            bendStretchAssistedAction = new BendStretchAssistedAction();
                        }
                        currentControl = bendStretchAssistedAction;
                    }
                    else if (mode == ModeEnum.IsotonicA)
                    {
                        if (isotonicAAction == null)
                        {
                            isotonicAAction = new IsotonicAAction();
                            isotonicAAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicAAction.NextTime += new EventHandler(action_NextTime);
                            isotonicAAction.StartAction += new EventHandler(action_StartAction);
                            isotonicAAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicAAction.Type = 0;
                        currentControl = isotonicAAction;
                    }
                    else if (mode == ModeEnum.IsotonicB)
                    {
                        if (isotonicBAction == null)
                        {
                            isotonicBAction = new IsotonicBAction();
                            isotonicBAction.NextTime += new EventHandler(action_NextTime);
                            isotonicBAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicBAction.StartAction += new EventHandler(action_StartAction);
                            isotonicBAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicBAction.Type = 0;
                        currentControl = isotonicBAction;
                    }
                }
                else if (action == ActionEnum.Protrusive)
                {
                    if (mode == ModeEnum.Sokoban || mode == ModeEnum.Free || mode == ModeEnum.FreeConstantResistance || mode == ModeEnum.FreeCounterWeight || mode == ModeEnum.Dengsu || mode == ModeEnum.Lixin)
                    {
                        if (bendStretchFreeAction == null)
                        {
                            bendStretchFreeAction = new BendStretchFreeAction();
                            bendStretchFreeAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchFreeAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchFreeAction.StartAction += new EventHandler(action_StartAction);
                        }
                        //bendStretchFreeAction.ModeEnum = mode;
                        //bendStretchFreeAction.ActionEnum = action;
                        currentControl = bendStretchFreeAction;
                    }
                    else if (mode == ModeEnum.Guided)
                    {
                        if (bendStretchGuidedAction == null)
                        {
                            bendStretchGuidedAction = new BendStretchGuidedAction();
                            bendStretchGuidedAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchGuidedAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchGuidedAction.StartAction += new EventHandler(action_StartAction);
                        }
                        currentControl = bendStretchGuidedAction;
                    }
                    else if (mode == ModeEnum.Initiated)
                    {
                        if (bendStretchAssistedAction == null)
                        {
                            bendStretchAssistedAction = new BendStretchAssistedAction();
                        }
                        currentControl = bendStretchAssistedAction;
                    }
                    else if (mode == ModeEnum.IsotonicA)
                    {
                        if (isotonicAAction == null)
                        {
                            isotonicAAction = new IsotonicAAction();
                            isotonicAAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicAAction.NextTime += new EventHandler(action_NextTime);
                            isotonicAAction.StartAction += new EventHandler(action_StartAction);
                            isotonicAAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicAAction.Type = 0;
                        currentControl = isotonicAAction;
                    }
                    else if (mode == ModeEnum.IsotonicB)
                    {
                        if (isotonicBAction == null)
                        {
                            isotonicBAction = new IsotonicBAction();
                            isotonicBAction.NextTime += new EventHandler(action_NextTime);
                            isotonicBAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicBAction.StartAction += new EventHandler(action_StartAction);
                            isotonicBAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicBAction.Type = 0;
                        currentControl = isotonicBAction;
                    }
                }
                else if (action == ActionEnum.ProtrusiveOrBend)
                {
                    if (mode == ModeEnum.Sokoban || mode == ModeEnum.Free || mode == ModeEnum.FreeConstantResistance || mode == ModeEnum.FreeCounterWeight || mode == ModeEnum.Dengsu || mode == ModeEnum.Lixin)
                    {
                        if (bendStretchFreeAction == null)
                        {
                            bendStretchFreeAction = new BendStretchFreeAction();
                            bendStretchFreeAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchFreeAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchFreeAction.StartAction += new EventHandler(action_StartAction);
                        }
                        //bendStretchFreeAction.ModeEnum = mode;
                        //bendStretchFreeAction.ActionEnum = action;
                        currentControl = bendStretchFreeAction;
                    }
                    else if (mode == ModeEnum.Guided)
                    {
                        if (bendStretchGuidedAction == null)
                        {
                            bendStretchGuidedAction = new BendStretchGuidedAction();
                            bendStretchGuidedAction.NextTime += new EventHandler(action_NextTime);
                            bendStretchGuidedAction.StopAction += new EventHandler(action_StopAction);
                            bendStretchGuidedAction.StartAction += new EventHandler(action_StartAction);
                        }
                        currentControl = bendStretchGuidedAction;
                    }
                    else if (mode == ModeEnum.Initiated)
                    {
                        if (bendStretchAssistedAction == null)
                        {
                            bendStretchAssistedAction = new BendStretchAssistedAction();
                        }
                        currentControl = bendStretchAssistedAction;
                    }
                    else if (mode == ModeEnum.IsotonicA)
                    {
                        if (isotonicAAction == null)
                        {
                            isotonicAAction = new IsotonicAAction();
                            isotonicAAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicAAction.NextTime += new EventHandler(action_NextTime);
                            isotonicAAction.StartAction += new EventHandler(action_StartAction);
                            isotonicAAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicAAction.Type = 0;
                        currentControl = isotonicAAction;
                    }
                    else if (mode == ModeEnum.IsotonicB)
                    {
                        if (isotonicBAction == null)
                        {
                            isotonicBAction = new IsotonicBAction();
                            isotonicBAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicBAction.NextTime += new EventHandler(action_NextTime);
                            isotonicBAction.StartAction += new EventHandler(action_StartAction);
                            isotonicBAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicBAction.Type = 0;
                        currentControl = isotonicBAction;
                    }
                }
                else if (action == ActionEnum.Rotation)
                {
                    if (mode == ModeEnum.Sokoban || mode == ModeEnum.Free || mode == ModeEnum.FreeConstantResistance || mode == ModeEnum.FreeCounterWeight || mode == ModeEnum.Dengsu || mode == ModeEnum.Lixin)
                    {
                        if (rotateFreeAction == null)
                        {
                            rotateFreeAction = new RotateFreeAction();
                            rotateFreeAction.NextTime += new EventHandler(action_NextTime);
                            rotateFreeAction.StopAction += new EventHandler(action_StopAction);
                            rotateFreeAction.StartAction += new EventHandler(action_StartAction);
                        }
                        //rotateFreeAction.ModeEnum = mode;
                        currentControl = rotateFreeAction;
                    }
                    else if (mode == ModeEnum.Guided)
                    {
                        if (rotateGuidedAction == null)
                        {
                            rotateGuidedAction = new RotateGuidedAction();
                            rotateGuidedAction.NextTime += new EventHandler(action_NextTime);
                            rotateGuidedAction.StopAction += new EventHandler(action_StopAction);
                            rotateGuidedAction.StartAction += new EventHandler(action_StartAction);
                        }
                        currentControl = rotateGuidedAction;

                    }
                    else if (mode == ModeEnum.Initiated)
                    {
                        if (rotateAssistedAction == null)
                        {
                            rotateAssistedAction = new RotateAssistedAction();
                        }
                        currentControl = rotateAssistedAction;
                    }
                    else if (mode == ModeEnum.IsotonicA)
                    {
                        if (isotonicAAction == null)
                        {
                            isotonicAAction = new IsotonicAAction();
                            isotonicAAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicAAction.NextTime += new EventHandler(action_NextTime);
                            isotonicAAction.StartAction += new EventHandler(action_StartAction);
                            isotonicAAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicAAction.Type = 1;
                        currentControl = isotonicAAction;
                    }
                    else if (mode == ModeEnum.IsotonicB)
                    {
                        if (isotonicBAction == null)
                        {
                            isotonicBAction = new IsotonicBAction();
                            isotonicBAction.SetForce += new SetForceHandler(action_SetForce);
                            isotonicBAction.NextTime += new EventHandler(action_NextTime);
                            isotonicBAction.StartAction += new EventHandler(action_StartAction);
                            isotonicBAction.StopAction += new EventHandler(action_StopAction);
                        }
                        isotonicBAction.Type = 1;
                        currentControl = isotonicBAction;
                    }
                }
            }

            if (currentControl != null)
            {
                currentControl.Mode = mode;
                currentControl.Action = action;
                currentControl.Controller = this;
                currentControl.Start();
            }
        }
        public void DoEvaluateAction(EvaluateActionEnum evaluateActionEnum, EvaluateModeEnum evaluateMode)
        {
            Reset();
            startTicks = DateTime.Now.Ticks;

            LumbarRobotController.RobotController.ControlCommand.PauseCmd();
            Thread.Sleep(10);
            LumbarRobotController.RobotController.ControlCommand.PauseCmd();
            Thread.Sleep(10);

            if (evaluateAction == null)
            {
                evaluateAction = new EvaluateAction();
                evaluateAction.SetForce += new SetForceHandler(action_SetForce);
                evaluateAction.StartAction += new EventHandler(action_StartAction);
                evaluateAction.StopAction += new EventHandler(action_StopAction);
            }

            evaluateAction.Mode = ModeEnum.Evaluation;
            if (evaluateActionEnum == EvaluateActionEnum.RotationRangeLeft || evaluateActionEnum == EvaluateActionEnum.RotationRangeRight
                || evaluateActionEnum == EvaluateActionEnum.RotationStrengthLeft || evaluateActionEnum == EvaluateActionEnum.RotationStrengthRigth)
            {

                evaluateAction.Action = ActionEnum.Rotation;
            }
            else
            {
                evaluateAction.Action = ActionEnum.ProtrusiveOrBend;
            }
            currentControl = evaluateAction;

            if (currentControl != null)
            {
                evaluateAction.EvaluateActionValue = evaluateActionEnum;
                evaluateAction.EvaluateMode = evaluateMode;
                evaluateAction.Controller = this;
                evaluateAction.Start();
            }
        }