Example #1
0
        /// <summary>
        /// In the Start() method we can call all the different methods which shall be executed by the robot. This happens via a new
        /// console window which allows input and also shows the possible inputs with a explanation.
        /// </summary>
        public void Start()
        {
            _robot.Enable();

            if (_robot != null && _robot.Enable())
            {
                var consoleInput = "";

                while (consoleInput != "exit")
                {
                    ConsoleFormatter.Custom(ConsoleColor.DarkGreen,
                                            "'stop' - stop robot,   'exit' - terminate program",
                                            "'disable' - disable robot,   'enable' - enable robot",
                                            "'movecm <cm>',  'movev <v>'",
                                            "'turndg <dg>'",
                                            "'keys' - start arrow keys mode",
                                            "'up' - arm gets higher",
                                            "'down' - arm gets lower",
                                            "'divide' - more space between grippers",
                                            "'join' - less space between grippers",
                                            "'task' - starts the task programm",

                                            /*
                                             * "'auto' - starts drive, henry drives forward and stops if a obstacle is in front of him and waits a given ammount of time",
                                             * "'testcorridor' - testing check2() Method, which is based on corridor calculation ",
                                             * "'testauto4' - testing check() with safety_threshold",
                                             * "'auto4' - starts autodrive based on default safety_threshold=700",
                                             */
                                            "'forward' - MUST henry drives forward, if there is an obstacle he waits for it to go away",
                                            "'random' - CAN CAN Have - drives forward, if there is an obstacle the robot decides randomly where to drive",
                                            "'autodrive' - NICE to Have - drives forward, if there is an obstacle the robot checks where to drive");

                    consoleInput = Console.ReadLine();
                    consoleInput = consoleInput.Trim();
                    var inputArray = consoleInput.Split(' ');
                    switch (inputArray[0])
                    {
                    /// Must-Haves:
                    /// auto represents our must haves, these include that Henry stops if a obstacle is
                    /// right infront of him and that he waits a certain amount of time. If the obstacle
                    /// disappeared Henry moves forward
                    case "forward":

                        Auto1 instanceAuto10 = new Auto1();

                        while (true)
                        {
                            instanceAuto10.Decide_basedonthresholdlist();
                        }

                        break;

                    /// Can Haves:
                    /// Henry drives forward. If he detects an obstacle he chooses randomly where to drive.
                    case "random":

                        Auto1 instanceAuto20 = new Auto1();

                        while (true)
                        {
                            instanceAuto20.randomDriveLeftOrRight();
                        }

                        break;

                    /// Nice to haves:
                    /// Henry drives forward. If he detects an obstacle he chooses where to drive based on his scanning data.
                    case "autodrive":

                        Auto1 instanceAuto30 = new Auto1();

                        while (true)
                        {
                            instanceAuto30.driveLeftOrRight();
                        }

                        break;


                    /*
                     * case "auto":
                     *
                     *    Auto1 instanceAuto_1 = new Auto1();
                     *    //Looping the method call infinitifely
                     *    int neverEnding = 1;
                     *    while (neverEnding == 1) {
                     *        //Calling the Method
                     *        instanceAuto_1.Decide();
                     *    }
                     *    break;
                     * //case for testing the check2() Method in order to check the thresholdlist and comparison with medianlist
                     *
                     * case "testcorridor":
                     *    Auto1 instanceAuto1_2 = new Auto1();
                     *    //var thresholdlist = new List<double>();
                     *    //thresholdlist = instanceAuto1_2.generateCorridorList();
                     *    //checking thresholdlist
                     *    //for(int i =0; i<=thresholdlist.Count()-1; i++){
                     *    //      Debug.WriteLine("Nächste Stelle in der Thresholdliste = "+ thresholdlist[i]);
                     *    // }
                     *    //checking check2() Method
                     *    //instanceAuto1_2.Check2();
                     *    int forever = 1;
                     *    while (forever==1){
                     *    //instanceAuto1_2.Check2();
                     *    instanceAuto1_2.Decide_basedonthresholdlist();
                     *    }
                     *    break;
                     *
                     * // Case for just executing the Check()-Method and its output
                     * case "testauto4":
                     *
                     *    Auto1 instanceAuto = new Auto1();
                     *    int loop_infinitely = 1;
                     *
                     *    while (loop_infinitely == 1)
                     *    {
                     *        instanceAuto.Check();
                     *    }
                     *
                     *    break;
                     *
                     * // case for executing the output of the decide() Method in the class Auto1
                     * case "auto4":
                     *
                     *    // new instance of class Auto1
                     *    Auto1 instanceAuto2 = new Auto1();
                     *
                     *    // Looping the method call infinitifely
                     *    while (true)
                     *    {
                     *        // Calling the Method
                     *        instanceAuto2.Decide();
                     *    }
                     *    break;
                     */
                    case "stop":
                        _robot.StopImmediately();
                        break;

                    case "enable":
                        _robot.Enable();
                        break;

                    case "disable":
                        _robot.Move(0);
                        _robot.Disable();
                        break;

                    case "exit":
                        _robot.Move(0);
                        _robot.Disable();
                        consoleInput = "exit";     // not needed
                        break;

                    case "movecm":
                        if (inputArray.Length > 1)
                        {
                            if (int.TryParse(inputArray[1], out var j))
                            {
                                _robot.MoveInCm(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "movev":
                        if (inputArray.Length > 1)
                        {
                            // if passed value is "1.5" the result will be j=1.5
                            // if passed value is "1,5" the result will be j=15
                            // because the system is written in english
                            if (double.TryParse(inputArray[1], NumberStyles.Number, CultureInfo.InvariantCulture, out var j))
                            {
                                _robot.Move(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "turndg":
                        if (inputArray.Length > 1)
                        {
                            if (int.TryParse(inputArray[1], out var j))
                            {
                                _robot.TurnInDegrees(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid.");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "keys":
                        ConsoleFormatter.Custom(ConsoleColor.DarkGreen,
                                                "'arrow keys' - direct the robot",
                                                "'space' - slow down robot",
                                                "'D' - disable robot",
                                                "'E' - enable robot",
                                                "'X' - terminate keys");
                        consoleInput = "";
                        var lastWalkMode = _robot.CurrentWalkMode;
                        var lastTurnMode = _robot.CurrentTurnMode;
                        Console.Clear();
                        CurrentMode(_robot.CurrentWalkMode, _robot.CurrentTurnMode);
                        while (consoleInput == "")
                        {
                            var c = Console.KeyAvailable ? Console.ReadKey(true).Key : ConsoleKey.Spacebar;
                            #region Keyswitch
                            switch (c)
                            {
                            case ConsoleKey.UpArrow:
                                ChangeWalkAndTurnMode(Direction.Up);
                                break;

                            case ConsoleKey.DownArrow:
                                ChangeWalkAndTurnMode(Direction.Down);
                                break;

                            case ConsoleKey.RightArrow:
                                ChangeWalkAndTurnMode(Direction.Right);
                                break;

                            case ConsoleKey.LeftArrow:
                                ChangeWalkAndTurnMode(Direction.Left);
                                break;

                            case ConsoleKey.Enter:
                                _robot.StopByMode();
                                break;

                            case ConsoleKey.D:
                                _robot.Disable();
                                break;

                            case ConsoleKey.E:
                                _robot.Enable();
                                break;

                            case ConsoleKey.X:
                                consoleInput = "exit";
                                ConsoleFormatter.Info("Terminated keys");
                                break;
                            }
                            #endregion

                            if (_robot.CurrentWalkMode == lastWalkMode && _robot.CurrentTurnMode == lastTurnMode)
                            {
                                continue;
                            }

                            lastWalkMode = _robot.CurrentWalkMode;
                            lastTurnMode = _robot.CurrentTurnMode;
                            Console.Clear();
                            CurrentMode(_robot.CurrentWalkMode, _robot.CurrentTurnMode);
                        }
                        consoleInput            = "";
                        Console.BackgroundColor = ConsoleColor.Black;
                        break;

                    case "divide":
                        _arm.Divide();
                        break;

                    case "join":
                        _arm.Join();
                        break;

                    case "up":
                        _arm.Up();
                        break;

                    case "down":
                        _arm.Down();
                        break;

                    case "task":
                        PracticalTask2B();
                        break;
                    }

                    Console.Clear();
                }
            }
            else
            {
                ConsoleFormatter.Error(
                    "Try to enable the robot failed.",
                    "Press enter to close the application.");
                Console.ReadLine();
            }
        }
Example #2
0
        public void Start()
        {
            if (_robot != null && _robot.Enable())
            {
                var consoleInput = "";

                while (consoleInput != "exit")
                {
                    ConsoleFormatter.Custom(ConsoleColor.DarkGreen,
                                            "'stop' - stop robot,   'exit' - terminate program",
                                            "'disable' - disable robot,   'enable' - enable robot",
                                            "'movecm <cm>',  'movev <v>'",
                                            "'turndg <dg>'",
                                            "'keys' - start arrow keys mode",
                                            "'up' - arm gets higher",
                                            "'down' - arm gets lower",
                                            "'divide' - more space between grippers",
                                            "'join' - less space between grippers",
                                            "'task' - starts the task programm");
                    consoleInput = Console.ReadLine();
                    consoleInput = consoleInput.Trim();
                    var inputArray = consoleInput.Split(' ');
                    switch (inputArray[0])
                    {
                    case "stop":
                        _robot.StopImmediately();
                        break;

                    case "enable":
                        _robot.Enable();
                        break;

                    case "disable":
                        _robot.Move(0);
                        _robot.Disable();
                        break;

                    case "exit":
                        _robot.Move(0);
                        _robot.Disable();
                        consoleInput = "exit";     // not needed
                        break;

                    case "movecm":
                        if (inputArray.Length > 1)
                        {
                            if (int.TryParse(inputArray[1], out var j))
                            {
                                _robot.MoveInCm(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "movev":
                        if (inputArray.Length > 1)
                        {
                            // if passed value is "1.5" the result will be j=1.5
                            // if passed value is "1,5" the result will be j=15
                            // because the system is written in english
                            if (double.TryParse(inputArray[1], NumberStyles.Number, CultureInfo.InvariantCulture, out var j))
                            {
                                _robot.Move(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "turndg":
                        if (inputArray.Length > 1)
                        {
                            if (int.TryParse(inputArray[1], out var j))
                            {
                                _robot.TurnInDegrees(j);
                            }
                            else
                            {
                                ConsoleFormatter.Warning("Parameter is not valid.");
                            }
                        }
                        else
                        {
                            ConsoleFormatter.Warning("Parameter expected");
                        }
                        break;

                    case "keys":
                        ConsoleFormatter.Custom(ConsoleColor.DarkGreen,
                                                "'arrow keys' - direct the robot",
                                                "'space' - slow down robot",
                                                "'D' - disable robot",
                                                "'E' - enable robot",
                                                "'X' - terminate keys");
                        consoleInput = "";
                        var lastWalkMode = _robot.CurrentWalkMode;
                        var lastTurnMode = _robot.CurrentTurnMode;
                        Console.Clear();
                        CurrentMode(_robot.CurrentWalkMode, _robot.CurrentTurnMode);
                        while (consoleInput == "")
                        {
                            var c = Console.KeyAvailable ? Console.ReadKey(true).Key : ConsoleKey.Spacebar;
                            #region Keyswitch
                            switch (c)
                            {
                            case ConsoleKey.UpArrow:
                                ChangeWalkAndTurnMode(Direction.Up);
                                break;

                            case ConsoleKey.DownArrow:
                                ChangeWalkAndTurnMode(Direction.Down);
                                break;

                            case ConsoleKey.RightArrow:
                                ChangeWalkAndTurnMode(Direction.Right);
                                break;

                            case ConsoleKey.LeftArrow:
                                ChangeWalkAndTurnMode(Direction.Left);
                                break;

                            case ConsoleKey.Enter:
                                _robot.StopByMode();
                                break;

                            case ConsoleKey.D:
                                _robot.Disable();
                                break;

                            case ConsoleKey.E:
                                _robot.Enable();
                                break;

                            case ConsoleKey.X:
                                consoleInput = "exit";
                                ConsoleFormatter.Info("Terminated keys");
                                break;
                            }
                            #endregion

                            if (_robot.CurrentWalkMode == lastWalkMode && _robot.CurrentTurnMode == lastTurnMode)
                            {
                                continue;
                            }

                            lastWalkMode = _robot.CurrentWalkMode;
                            lastTurnMode = _robot.CurrentTurnMode;
                            Console.Clear();
                            CurrentMode(_robot.CurrentWalkMode, _robot.CurrentTurnMode);
                        }
                        consoleInput            = "";
                        Console.BackgroundColor = ConsoleColor.Black;
                        break;

                    case "divide":
                        _arm.Divide();
                        break;

                    case "join":
                        _arm.Join();
                        break;

                    case "up":
                        _arm.Up();
                        break;

                    case "down":
                        _arm.Down();
                        break;

                    case "task":
                        PracticalTask2B();
                        break;
                    }

                    Console.Clear();
                }
            }
            else
            {
                ConsoleFormatter.Error(
                    "Try to enable the robot failed.",
                    "Press enter to close the application.");
                Console.ReadLine();
            }
        }