Пример #1
0
        /// <summary>
        /// Executes all the primitives SM in order to perform the entire task
        /// </summary>
        /// <returns>LeaveArena state</returns>
        private int PerformCommand(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> PerformCommand state reached.");

            //exxecute all the primitives (one by one)
            foreach (string action in SMConfiguration.setOfActions)
            {
                char[] delimiters = { ' ' };
                //get the parameters for each primitive
                string   clean_action = action.Replace('\r', ' ');
                string[] parameters   = clean_action.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                //the first parameter allways is the primitive to execute
                if (parameters.Length > 0)
                {
                    switch (parameters[0])
                    {
                    case "answer_question":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: AnswerQuestion.");
                        //no parameters
                        AnswerQuestion        sm_aq          = new AnswerQuestion(this.brain, this.cmdMan, this.SMConfiguration);
                        AnswerQuestion.Status finalStatus_aq = sm_aq.Execute();
                        break;

                    case "bring_object":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: Bringobject.");
                        //1 parameter (object name)
                        BringObject        sm_bo          = new BringObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        BringObject.Status finalStatus_bo = sm_bo.Execute();
                        break;

                    case "navigate_to":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: NavigateTo.");
                        //1 parameter (location name/class)
                        NavigateTo        sm_nt          = new NavigateTo(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        NavigateTo.Status finalStatus_nt = sm_nt.Execute();
                        break;

                    case "take_object":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TakeObject.");
                        //1 parameter (object name)
                        TakeObject        sm_to          = new TakeObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        TakeObject.Status finalStatus_to = sm_to.Execute();
                        break;

                    case "tell_phrase":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TellPhrase.");
                        //1 parameter (kind of phrase to say)
                        TellPhrase        sm_tp          = new TellPhrase(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        TellPhrase.Status finalStatus_tp = sm_tp.Execute();
                        break;

                    case "find_person":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: FindPerson.");
                        //no parameters
                        //FindPerson sm_fp = new FindPerson(this.brain, this.cmdMan, this.SMConfiguration);
                        //FindPerson.Status finalStatus_fp = sm_fp.Execute();
                        break;

                    default:
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> The primitive " + parameters[0] + " was not found.");
                        break;
                    }
                }
            }
            finalStatus = Status.OK;
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> All primitives were executed.");
            //TODO:
            //Descomponer las siguientes dependencias conceptuales:

            /*
             * # take [object] from [location] and deliver to [person]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [person_location]
             *      bring
             * # take [object] from [location] and deliver to [me]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [me]
             *      bring
             * # take [object] from [location1] and deliver to [location2]
             *      navigate_to [location1]
             *      search_and_take [object]
             *      navigate_to [location2]
             *      bring
             * # go to [location] and find [person]
             *      navigate_to [location]
             *      find [person]
             * # find person in [location] and talk [phrase]
             *      navigate_to [location]
             *      find [person]
             *      tellphrase [phrase]
             */
            return((int)States.LeaveArena);
        }
Пример #2
0
        /// <summary>
        /// the robot navigate to the operator location
        /// </summary>
        /// <returns>WaitForCommand state if the navigation primiive was executed succesfully. NavigateToOperator otherwise.</returns>
        private int NavigateToOperator(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> NavigateToOperator state reached.");

            NavigateTo sm_navigation = new NavigateTo(this.brain, this.cmdMan, SMConfiguration, SMConfiguration.MVNPLN_operatorLocation);
            NavigateTo.Status navig_status = sm_navigation.Execute();
            if (navig_status == NavigateTo.Status.OK)
            {
                //if the robot reach the location then ask for a command
                cmdMan.SPG_GEN_say(SMConfiguration.SPGEN_waitforcomman, 5000);
                Thread.Sleep(1000);
                brain.recognizedSentences.Clear();

                attemptCounter = 0;
                return (int)States.WaitForCommand;
            }
            else
            {
                attemptCounter++;
                //the robot cannot navigate to
                if (attemptCounter < attemptLimit)
                {
                    TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> connot navigate to te aperator at attempt: " + attemptCounter + ". Trying again.");
                    return (int)States.NavigateToOperator;
                }
                else
                {
                    //reset the attempt counter
                    TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Cannot navigate to the operator. Try to continue with the test.");
                    attemptCounter = 0;
                    return (int)States.WaitForCommand;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Executes all the primitives SM in order to perform the entire task
        /// </summary>
        /// <returns>LeaveArena state</returns>
        private int PerformCommand(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> PerformCommand state reached.");

            //exxecute all the primitives (one by one)
            foreach (string action in SMConfiguration.setOfActions)
            {
                char[] delimiters = {' '};
                //get the parameters for each primitive
                string clean_action = action.Replace('\r',' ');
                string[] parameters = clean_action.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                //the first parameter allways is the primitive to execute
                if (parameters.Length > 0)
                {
                    switch (parameters[0])
                    {
                        case "answer_question":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: AnswerQuestion.");
                            //no parameters
                            AnswerQuestion sm_aq = new AnswerQuestion(this.brain, this.cmdMan, this.SMConfiguration);
                            AnswerQuestion.Status finalStatus_aq = sm_aq.Execute();
                            break;
                        case "bring_object":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: Bringobject.");
                            //1 parameter (object name)
                            BringObject sm_bo = new BringObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            BringObject.Status finalStatus_bo = sm_bo.Execute();
                            break;
                        case "navigate_to":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: NavigateTo.");
                            //1 parameter (location name/class)
                            NavigateTo sm_nt = new NavigateTo(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            NavigateTo.Status finalStatus_nt = sm_nt.Execute();
                            break;
                        case "take_object":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TakeObject.");
                            //1 parameter (object name)
                            TakeObject sm_to = new TakeObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            TakeObject.Status finalStatus_to = sm_to.Execute();
                            break;
                        case "tell_phrase":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TellPhrase.");
                            //1 parameter (kind of phrase to say)
                            TellPhrase sm_tp = new TellPhrase(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            TellPhrase.Status finalStatus_tp = sm_tp.Execute();
                            break;
                        case "find_person":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: FindPerson.");
                            //no parameters
                            //FindPerson sm_fp = new FindPerson(this.brain, this.cmdMan, this.SMConfiguration);
                            //FindPerson.Status finalStatus_fp = sm_fp.Execute();
                            break;
                        default:
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> The primitive " + parameters[0] + " was not found.");
                            break;
                    }
                }
            }
            finalStatus = Status.OK;
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> All primitives were executed.");
            //TODO:
            //Descomponer las siguientes dependencias conceptuales:
            /*
             * # take [object] from [location] and deliver to [person]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [person_location]
             *      bring
             * # take [object] from [location] and deliver to [me]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [me]
             *      bring
             * # take [object] from [location1] and deliver to [location2]
             *      navigate_to [location1]
             *      search_and_take [object]
             *      navigate_to [location2]
             *      bring
             * # go to [location] and find [person]
             *      navigate_to [location]
             *      find [person]
             * # find person in [location] and talk [phrase]
             *      navigate_to [location]
             *      find [person]
             *      tellphrase [phrase]
             */
            return (int)States.LeaveArena;
        }
Пример #4
0
        /// <summary>
        /// The robot leaves the arena
        /// </summary>
        /// <returns>FinalState state to finish this state</returns>
        private int LeaveArena(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> LeaveArena state reached.");

            cmdMan.SPG_GEN_say(SMConfiguration.SPGEN_leavingArena, 5000);

            NavigateTo sm_navigation = new NavigateTo(this.brain, this.cmdMan, SMConfiguration, SMConfiguration.MVNPLN_exitLocation);
            NavigateTo.Status navig_status = sm_navigation.Execute();
            if (navig_status == NavigateTo.Status.OK)
            {
                attemptCounter = 0;
                return (int)States.FinalState;
            }
            else
            {
                attemptCounter++;
                //the robot cannot navigate to exit
                if (attemptCounter < attemptLimit)
                {
                    TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Cannot navigate to the exit at attempt: " + attemptCounter + ". Trying again.");
                    return (int)States.LeaveArena;
                }
                else
                {
                    //reset the attempt counter
                    TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Cannot navigate to the exit. Try to continue with the test.");
                    attemptCounter = 0;
                    return (int)States.FinalState;
                }
            }
        }