Exemple #1
0
        /// <summary>
        /// Create a new FullStrategy object from file
        /// Filename : contains path to file to load
        /// PatternFilename : contains path to pattern file to load
        /// </summary>
        public FullStrategy(string Filename, string PatternFilename)
        {
            if ((Filename == null) || (PatternFilename == null))
            {
                throw(new Exception("Invalid Filename/PatternFilename"));
            }

            // Read files
            StructuredFile StrategyFile = new StructuredFile(Filename);
            StrategyFile.Parse(PatternFilename);

            // Store data into private data
            // Store PATTERN_STRATEGY_NAME
            _StrategyName = StrategyFile.GetValue("PATTERN_STRATEGY_NAME", "Undefined");
            _DefaultSpeed = StrategyFile.GetValue("PATTERN_DEFAULT_SPEED", "50");

            // Store initial cmd (setpos)
            EnumCmd CurrentCmd = Command.GetCmdFromString(StrategyFile.GetValue("PATTERN_INIT_CMD", "App_SetNewPos"));
            EnumCmdType CurrentCmdType = Command.GetCmdTypeFromString(StrategyFile.GetValue("PATTERN_INIT_CMD_TYPE", "NonBlocking"));
            String ParamX = StrategyFile.GetValue("PATTERN_INIT_POS_X", "0");
            String ParamY = StrategyFile.GetValue("PATTERN_INIT_POS_Y", "0");
            String ParamAngle = StrategyFile.GetValue("PATTERN_INIT_POS_ANGLE", "0.0");
            EnumStrategyFlag ActiveSensors = Command.GetSensorsFlagFromString(StrategyFile.GetValue("PATTERN_INIT_ACTIVE_SENSORS", "APP_PARAM_APPFLAG_NONE"));

            _InitialCmd = new Command(CurrentCmd, CurrentCmdType, null, ParamX, ParamY, ParamAngle, ActiveSensors);

            // Read other items (Loops)
            // Try to read all loops
            for (int iLoop = 0; iLoop <= StrategyFile.GetMaxLoopID(); iLoop++)
            {
                for (int iCount = 0; iCount <= StrategyFile.GetMaxGID(iLoop); iCount++)
                {
                    // Read ActionID and NextActionID
                    int ActionID = StrategyFile.GetActionID(iLoop, iCount);
                    int NextActionID = StrategyFile.GetNextActionID(iLoop, iCount);
                    int TimeoutID = StrategyFile.GetTimeoutID(iLoop, iCount);

                    // If current action is valid
                    if (ActionID >= 0)
                    {
                        // Read command data from StratgeyFile
                        Command ReadCommand = StrategyFile.GetCommand(iLoop, iCount);

                        // If current command is valid, we store it
                        if (ReadCommand != null)
                        {
                            // If current list is empty, we create it
                            if (_Strategy == null)
                                _Strategy = new List<StrategyItem>();

                            // Create new entry
                            _Strategy.Add(new StrategyItem(ReadCommand, ActionID, NextActionID, TimeoutID));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private String _StrategyName; // Nom de la strategie pour le #define

        #endregion Fields

        #region Constructors

        // Constructor ----------------------------------------------------------------------------
        /// <summary>
        /// Default constructor : Create an empty strategy
        /// </summary>
        public FullStrategy(String StrategyName)
        {
            if ((StrategyName != null) && (StrategyName != ""))
            {
                _StrategyName = StrategyName;
                _DefaultSpeed = "50";
                _InitialCmd = new Command(EnumCmd.App_SetNewPos, EnumCmdType.NonBlocking, null, "1500", "1000", "0");
                _Strategy = null;
            }
        }
Exemple #3
0
        private int _TimeoutID; // Contient l'ID pour les actions lors d'un Timeout

        #endregion Fields

        #region Constructors

        public StrategyItem(Command Action, int ActionID, int NextActionID, int TimeoutID)
        {
            if ((Action == null) || (_ActionID < 0))
            {
                throw (new Exception("Invalid params"));
            }

            // Création de l'objet
            _Cmd = Action;
            _ActionID = ActionID;
            _NextActionID = NextActionID;
            _TimeoutID = TimeoutID;
        }
Exemple #4
0
        public RobotPos(int x, int y, int angle, Command CurrentCmd, int Index)
        {
            _PosX = x;
            _PosY = y;
            _PosAngle = angle;

            _ComputedPosX = _PosX;
            _ComputedPosY = _PosY;
            _ComputedPosAngle = _PosAngle;

            _Index = Index;

            UpdateCmd(CurrentCmd);
        }
        /// <summary>
        /// Récupère la commande complète d'après la Loop et le GID
        /// </summary>
        /// <param name="LoopID">Identifiant de la boucle</param>
        /// <param name="GID">Identifiant du GID</param>
        /// <returns>La commande complétée de toutes les infos de la LoopID + GID</returns>
        public Command GetCommand(int LoopID, int GID)
        {
            Command ReadCommand = null;
            EnumCmd CmdFromFile = EnumCmd.NotSet;
            EnumCmdType CmdTypeFromFile = EnumCmdType.NotSet;
            string [] ParamsFromFile = null;
            EnumStrategyFlag ActiveSensorsFromFile = EnumStrategyFlag.STRATEGYFLAG_NONE;

            // Lecture de toute la liste pour trouver la bonne LoopID et GID
            for (int i = 0; i < _Items.Count(); i++)
            {
                // Si nous sommes dans la bonne LoopID et GID
                if ((_Items[i].GetLoopID() == LoopID) && (_Items[i].GetGID() == GID))
                {
                    // Lecture des informations
                    // Lecture de la commande
                    if (_Items[i].GetName() == "PATTERN_CMD")
                        CmdFromFile = Command.GetCmdFromString(_Items[i].GetValue());

                    // Lecture du type de la commande
                    if (_Items[i].GetName() == "PATTERN_CMD_TYPE")
                        CmdTypeFromFile = Command.GetCmdTypeFromString(_Items[i].GetValue());

                    // Lecture des flags des sensors
                    if (_Items[i].GetName() == "PATTERN_ACTIVE_SENSORS_FLAG")
                        ActiveSensorsFromFile = Command.GetSensorsFlagFromString(_Items[i].GetValue());

                    // Lecture des paramètres
                    if (_Items[i].GetName() == "PATTERN_PARAMS")
                    {
                        ParamsFromFile = Command.GetParamsListFromString(_Items[i].GetValue());
                    }
                }
            }

            // Creation de l'objet de retour
            if (CmdFromFile != EnumCmd.NotSet)
            {
                ReadCommand = new Command(CmdFromFile, CmdTypeFromFile, ParamsFromFile[0], ParamsFromFile[1], ParamsFromFile[2], ParamsFromFile[3], ActiveSensorsFromFile);
            }

            return ReadCommand;
        }
Exemple #6
0
 public void UpdateCmd(Command CurrentCmd)
 {
     _CurrentCommand = CurrentCmd;
     ComputeNewPos();
 }
Exemple #7
0
        public void InsertNewCmd_Before(int Index, EnumCmd CmdToAdd, int NewCmdID)
        {
            int FreeActionID = -1;
            if (Index <= 0)
                throw (new Exception("Invalid Param"));

            if (_Strategy == null)
                throw (new Exception("Invalid Param"));

            if (Index > _Strategy.Count)
                throw (new Exception("Invalid Param"));

            Command NewCommand = new Command(CmdToAdd);

            if (NewCmdID > 1)
                FreeActionID = GetPrevFreeActionID(NewCmdID + 1);
            else
                FreeActionID = GetPrevFreeActionID(_Strategy[Index - 1].ActionID);

             StrategyItem NewStrategyItem = new StrategyItem(NewCommand, FreeActionID, -1, -1);
            _Strategy.Insert(Index - 1, NewStrategyItem);
        }
Exemple #8
0
        public void InsertNewCmd_After(int Index, EnumCmd CmdToAdd, int NewCmdID)
        {
            int FreeActionID = -1;
            if (Index < 0)
                throw (new Exception("Invalid Param"));

            if (_Strategy == null)
            {
                _Strategy = new List<StrategyItem>();
            }

            if (Index > _Strategy.Count)
                throw (new Exception("Invalid Param"));

            Command NewCommand = new Command(CmdToAdd);

            if (_Strategy.Count == 0)
                FreeActionID = 1;
            else
            {
                if (NewCmdID > 1)
                    FreeActionID = GetNextFreeActionID(NewCmdID - 1);
                else
                    FreeActionID = GetNextFreeActionID(_Strategy[Index - 1].ActionID);
            }

            StrategyItem NewStrategyItem = new StrategyItem(NewCommand, FreeActionID, -1, -1);
            _Strategy.Insert(Index, NewStrategyItem);
        }
Exemple #9
0
        public Boolean InsertCmd(Command CommandToAdd, int CmdIDToAdd, int NextCmdIDToAdd, int TimeoutID)
        {
            int CheckID = 0;
            int i = 0;

            if((CommandToAdd == null) || (CmdIDToAdd <= 0))
                return false;

            while(i < _Strategy.Count && CheckID < CmdIDToAdd)
            {
                CheckID = _Strategy[i].ActionID;
                i++;
            }

            if(CheckID == CmdIDToAdd)
                return false;

            // We can add the new command to the current ID
            _Strategy.Insert(i, new StrategyItem(CommandToAdd, CmdIDToAdd, NextCmdIDToAdd, TimeoutID));

            return true;
        }