Пример #1
0
        /// <summary>
        /// one-way (drill down) recursion, no wait allowed
        /// </summary>
        /// <param name="iter">Task iterator</param>
        /// <returns>null when yield break or end of method is encountered</returns>
        private IEnumerator <ISubsumptionTask> iterate(IEnumerator <ISubsumptionTask> iter)
        {
            //Debug.WriteLine("TaskDispatcher: iterate()    type: " + iter.GetType());

            if (iter != null && iter.MoveNext())
            {
                ISubsumptionTask task = iter.Current;

                //Debug.WriteLine("...iterating...   task: " + task);

                bool doContinie = task == RobotTask.Continue;

                if (doContinie)
                {
                    //Debug.WriteLine("TaskDispatcher: iterate() - task: " + task + "     Task.Continue - doing nothing");

                    return(iter);
                }

                iter = task.Execute();

                //Debug.WriteLine("TaskDispatcher: iterate() - task: " + task + " - iterating inside inner loop");

                return(iterate(iter));
            }

            //Debug.WriteLine("TaskDispatcher: iterate() finished task");

            return(null);
        }
        /// <summary>
        /// adds a task to the list of active tasks
        /// </summary>
        /// <param name="task"></param>
        public void Dispatch(ISubsumptionTask task)
        {
            Debug.WriteLine("TaskDispatcher: Dispatch: " + tasks.Count + " tasks, adding: " + task.name);

            tasks.Add(task);

            //lock(iStates)
            {
                iStates.Add(new IteratorState() { taskName = task.name, iterator = task.Execute() });
            }
        }
Пример #3
0
        /// <summary>
        /// adds a task to the list of active tasks
        /// </summary>
        /// <param name="task"></param>
        public void Dispatch(ISubsumptionTask task)
        {
            Debug.WriteLine("TaskDispatcher: Dispatch: " + tasks.Count + " tasks, adding: " + task.name);

            tasks.Add(task);

            //lock(iStates)
            {
                iStates.Add(new IteratorState()
                {
                    taskName = task.name, iterator = task.Execute()
                });
            }
        }
Пример #4
0
        private BehaviorsCoordinatorData coordinatorData = BehaviorBase.getCoordinatorData();  // get the singleton

        /// <summary>
        /// behaviors in dispatcher may all exit, which will require producing a new behaviors combo.
        /// </summary>
        private void MonitorDispatcherActivity()
        {
            // ActiveTasksCount is indicator of behaviors completed or removed. Zero count means we may need new behaviors combo.
            int dispatcherActiveTasksCount = subsumptionTaskDispatcher.ActiveTasksCount;

            if (dispatcherActiveTasksCount != lastActiveTasksCount)
            {
                Debug.WriteLine("Warning: ShortyTheRobot: Process: active tasks count: " + dispatcherActiveTasksCount);

                if (dispatcherActiveTasksCount == 0)
                {
                    this.SafePose(); // ensure the robot is stopped when all behaviors have exited
                    speaker.Speak("active tasks count zero");
                }
                else if (lastActiveTasksCount <= 0)
                {
                    speaker.Speak(string.Format("{0} tasks", dispatcherActiveTasksCount));
                }

                lastActiveTasksCount = dispatcherActiveTasksCount;
            }

            // clear the grab, if any:
            string gbn = coordinatorData.GrabbingBehaviorName;

            if (!string.IsNullOrWhiteSpace(gbn))
            {
                ISubsumptionTask grabber = (from b in subsumptionTaskDispatcher.Tasks where b.name == gbn select b).FirstOrDefault();

                if (grabber != null)
                {
                    BehaviorBase bBase = (BehaviorBase)grabber;
                    if (!bBase.FiredOn)
                    {
                        // Grabbing behavior is not firing any more, can clear the grab:
                        coordinatorData.ClearGrabbingBehavior();
                    }
                }
            }
        }