Ejemplo n.º 1
0
        /**
         * This method ticks <code>executor</code> {@value #NUM_TICKS_LONG_TICK} times. If the executor
         * finishes earlier, it is not ticked anymore, and the ticking process stops.
         *
         * @param executor
         *            the IBTExecutor that is ticked.
         */

        private void longTick(IBTExecutor executor)
        {
            if (executor.GetStatus() == Status.Running || executor.GetStatus() == Status.Uninitialized)
            {
                int counter = 0;
                do
                {
                    executor.Tick();
                    counter++;
                } while (executor.GetStatus() == Status.Running && counter < NumTicksLongTick);
            }
        }
 public static void RunInterrupterBranch(IBTExecutor executor, int numTicks)
 {
     var counter = 0;
     do
     {
         executor.Tick();
         counter++;
     } while (executor.GetStatus() == Status.Running && counter < numTicks);
 }
Ejemplo n.º 3
0
        public static void RunInterrupterBranch(IBTExecutor executor, int numTicks)
        {
            var counter = 0;

            do
            {
                executor.Tick();
                counter++;
            } while (executor.GetStatus() == Status.Running && counter < numTicks);
        }
Ejemplo n.º 4
0
        /**
         * Evaluate all the guards that have not finished yet, that is, those whose
         * result in {@link #guardsResults} is {@link Status#RUNNING}, by ticking
         * them.
         * <p>
         * If all the guards have finished in failure, this method returns a Tuple
         * whose first element is {@link Status#FAILURE}. If there is at least one
         * guard still being evaluated, the first element of the Tuple contains
         * {@link Status#RUNNING}. If all the guards have been evaluated and at
         * least one has succeeded, the first element of the Tuple is
         * {@link Status#SUCCESS}, and the second one is the index, over the list of
         * guards ({@link #guardsExecutors}) , of the first guard (that with the
         * highest priority) that has succeeded.
         *
         */

        private Tuple <Status, int> evaluateGuards()
        {
            bool oneRunning = false;

            /* First, evaluate all the guards that have not finished yet. */
            for (int i = 0; i < _guardsExecutors.Count; i++)
            {
                IBTExecutor guardExecutor = _guardsExecutors[i];
                if (guardExecutor != null)
                {
                    if (guardsResults[i] == Status.Running)
                    {
                        guardExecutor.Tick();
                        guardsResults[i] = guardExecutor.GetStatus();
                        if (guardsResults[i] == Status.Running)
                        {
                            oneRunning = true;
                        }
                    }
                }
            }

            /* If there is at least one still running... */
            if (oneRunning)
            {
                return(new Tuple <Status, int>(Status.Running, -1));
            }

            /* If all of them have finished we check which one succeeded first. */
            for (int i = 0; i < guardsResults.Count; i++)
            {
                if (guardsResults[i] == Status.Success)
                {
                    return(new Tuple <Status, int>(Status.Success, i));
                }
            }

            /* Otherwise, the evaluation has failed. */
            return(new Tuple <Status, int>(Status.Failure, -1));
        }
Ejemplo n.º 5
0
        /**
         * Evaluate all the guards that have not finished yet, that is, those whose result in
         * {@link #guardsResults} is {@link Status#RUNNING}, by ticking them.
         * <p>
         * If all the guards have finished in failure, this method returns a Tuple whose first element is
         * {@link Status#FAILURE}. If guards' evaluation has not completed yet, the first element of the
         * Tuple contains {@link Status#RUNNING}. If all the guards have been evaluated and at least one
         * has succeeded, the first element of the Tuple is {@link Status#SUCCESS}, and the second one is
         * the index, over the list of guards ({@link #guardsExecutors}) , of the first guard (that with
         * the highest priority) that has succeeded.
         *
         */

        private Tuple <Status, int> EvaluateGuards()
        {
            /*
             * Tick all the guards that are still running. If one changes its status to SUCCESS and it
             * matches the guard associated to "indexMostRelevantGuard", then the guards' evaluation is
             * over and that is the selected guard.
             */
            for (int i = 0; i < _guardsExecutors.Count; i++)
            {
                IBTExecutor guardExecutor = _guardsExecutors[i];

                if (guardExecutor != null)
                {
                    if (_guardsResults[i] == Status.Running)
                    {
                        longTick(guardExecutor);

                        _guardsResults[i] = guardExecutor.GetStatus();

                        if (guardExecutor.GetStatus() != Status.Running)
                        {
                            /*
                             * If the guard has finished, we check if it matches the
                             * "most relevant guard".
                             */
                            if (i == _indexMostRelevantGuard)
                            {
                                if (guardExecutor.GetStatus() == Status.Success)
                                {
                                    return(new Tuple <Status, int>(Status.Success, i));
                                }

                                /*
                                 * If the guard failed, we have to find the next
                                 * "most relevant guard" and update "indexMostRelevantGuard"
                                 * accordingly. For that we check the status of the following
                                 * guards. If we find a successful guard before any running guard,
                                 * then the guards' evaluation is over, and that is the selected
                                 * guard. If we find a running guard before, then that's the new
                                 * "most relevant guard". Otherwise, the evaluation has failed, and
                                 * there is no successful guard.
                                 */
                                bool oneRunning = false;

                                for (int k = _indexMostRelevantGuard + 1; k < _guardsExecutors.Count; k++)
                                {
                                    if (_guardsExecutors[k] != null)
                                    {
                                        Status currentResult = _guardsExecutors[k].GetStatus();
                                        if (currentResult == Status.Running)
                                        {
                                            _indexMostRelevantGuard = k;
                                            oneRunning = true;
                                            break;
                                        }
                                        if (currentResult == Status.Success)
                                        {
                                            return(new Tuple <Status, int>(Status.Success, k));
                                        }
                                    }
                                    else
                                    {
                                        return(new Tuple <Status, int>(Status.Success, k));
                                    }
                                }

                                if (!oneRunning)
                                {
                                    return(new Tuple <Status, int>(Status.Failure, -1));
                                }
                            }
                        }
                    }
                }
                else
                {
                    /* Remember, null guard means successful evaluation. */
                    if (i == _indexMostRelevantGuard)
                    {
                        return(new Tuple <Status, int>(Status.Success, i));
                    }
                }
            }

            return(new Tuple <Status, int>(Status.Running, -1));
        }
 /**
  * This method ticks <code>executor</code> {@value #NUM_TICKS_LONG_TICK} times. If the executor
  * finishes earlier, it is not ticked anymore, and the ticking process stops.
  *
  * @param executor
  *            the IBTExecutor that is ticked.
  */
 private void longTick(IBTExecutor executor)
 {
     if (executor.GetStatus() == Status.Running || executor.GetStatus() == Status.Uninitialized)
     {
         int counter = 0;
         do
         {
             executor.Tick();
             counter++;
         } while (executor.GetStatus() == Status.Running && counter < NumTicksLongTick);
     }
 }