Beispiel #1
0
        /// <summary>
        /// Initialises the drive priority element.
        /// 
        /// The log domain is set to [AgentName].DP.[drive_name]
        /// </summary>
        /// <param name="agent">The element's agent.</param>
        /// <param name="driveName">The name of the associated drive.</param>
        /// <param name="elements">The drive elements of the priority element.</param>
        public DrivePriorityElement(Agent agent, string driveName, DriveElement [] elements)
            : base(string.Format("DP.{0}", driveName), agent)
        {
            name = driveName;
            this.elements = new List<DriveElement>(elements);
            timer = agent.getTimer();
            this.agent = agent;

            log.Debug("Created");
        }
Beispiel #2
0
        /// <summary>
        /// Builds the drive collection and returns it.
        ///
        /// This method builds the drive collection, of which the structure has
        /// been set by setDriveCollection. Additionally, its
        /// assigns the agent a timer, as specified by the drive collection
        /// (i.e. a stepped timer, in the case of an SDC drive, and a
        /// real-time timer in the case of an SRDC drive). If the timer is
        /// a real-time timer, then it is initialised with a loop frequency of
        /// 50Hz.
        ///
        /// Only drives of type 'SDC' and 'SRDC' are accepted. In any other case
        /// a TypeError is raised.
        /// </summary>
        /// <param name="agent">The agent that the drive collection is built for.</param>
        /// <param name="competences">A competence object dictionary.</param>
        /// <param name="actionPatterns">An action pattern dictionary.</param>
        /// <exception cref="TypeLoadException">For drives of types other than SDC or SRDC.</exception>
        /// <returns>The drive collection.</returns>
        internal DriveCollection buildDriveCollection(Agent agent, Dictionary <string, Competence> competences, Dictionary <string, ActionPattern> actionPatterns)
        {
            string dcType = driveCollection.First;
            string dcName = driveCollection.Second;
            List <DrivePriorityElement> priorityElements = new List <DrivePriorityElement>();

            // create the agent timer
            switch (dcType)
            {
            case "SDC":
                agent.setTimer(new SteppedTimer());
                break;

            case "SRDC":
                agent.setTimer(new RealTimeTimer((long)(1000.00 / 30.0)));
                break;

            default:
                throw new TypeLoadException(string.Format("Drive collection of type '{0}' not " +
                                                          "supported (only supporting SDC and SRDC).", dcType));
            }
            Trigger goal = buildGoal(agent, driveCollection.Third);

            foreach (Tuple <string, List <object>, string, long>[] priorityElement in driveCollection.Forth)
            {
                List <DriveElement> elementList = new List <DriveElement>();

                foreach (Tuple <string, List <object>, string, long> element in priorityElement)
                {
                    DriveElement driveElement = buildDriveElement(element, agent, competences, actionPatterns);
                    driveElement.isLatched = false;

                    foreach (POSHSense sense in driveElement.trigger.senses)
                    {
                        if (sense.behaviour.GetType().IsSubclassOf(typeof(LatchedBehaviour)))
                        {
                            driveElement.isLatched = true;
                            break;
                        }
                    }
                    elementList.Add(driveElement);
                }
                priorityElements.Add(new DrivePriorityElement(agent, dcName, elementList.ToArray()));
            }

            return(new DriveCollection(agent, dcType, dcName, priorityElements.ToArray(), goal));
        }