コード例 #1
0
        private void LoadAndRunModel(string modelFileName)
        {
            FDMExecutive fdm = new FDMExecutive();

            fdm.AircraftPath = rootDirectory + "/aircraft";
            fdm.EnginePath   = rootDirectory + "/engine";

            fdm.LoadModel(modelFileName, true);

            InitialCondition IC = fdm.GetIC;

            IC.Load("reset00", true);

            Trim fgt = new Trim(fdm, TrimMode.Full);

            if (!fgt.DoTrim())
            {
                log.Debug("Trim Failed");
            }
            fgt.Report();

            bool result = fdm.Run();
            int  count  = 0;

            while (result && !(fdm.Holding() || fdm.State.IsIntegrationSuspended))
            {
                result = fdm.Run();
                count++;
                if (count > 10 && log.IsDebugEnabled)
                {
                    count = 0;
                    log.Debug("=> Time: " + fdm.State.SimTime);
                }
            }
        }
コード例 #2
0
ファイル: RunTests.cs プロジェクト: glareheaven/JSBSimNet
        private FDMExecutive LoadAndRunModel(string modelFileName, string IcFileName)
        {
            FDMExecutive fdm = new FDMExecutive();

            fdm.AircraftPath = AircraftPath;
            fdm.EnginePath   = EnginePath;

            fdm.LoadModel(modelFileName, true);

            InitialCondition IC = fdm.GetIC();

            IC.Load(IcFileName, true);

            Trim fgt = new Trim(fdm, TrimMode.Full);

            if (!fgt.DoTrim())
            {
                log.Debug("Trim Failed");
            }
            fgt.Report();

            bool result = fdm.Run();
            int  count  = 0;

            while (result && !(fdm.Holding() || fdm.State.IsIntegrationSuspended) && count < 10000)
            {
                result = fdm.Run();
                count++;
                if (count > 120 && log.IsDebugEnabled)
                {
                    count = 0;
                    log.Debug("Time: " + fdm.State.SimTime);
                }
            }

            log.Debug("Final Time: " + fdm.State.SimTime);
            return(fdm);
        }
コード例 #3
0
        public void Run()
        {
            if (!rootDir.EndsWith("/"))
            {
                rootDir += "/";
            }
            FDMExecutive fdm = new FDMExecutive();

            fdm.AircraftPath = rootDir + "aircraft";
            fdm.EnginePath   = rootDir + "engine";

            if (scriptName != null) // SCRIPTED CASE
            {
                scriptName = rootDir + scriptName;
                script     = new Script(fdm);
                script.LoadScript(scriptName);
                scripted = true;
            }
            else if (aircraftName != null || resetName != null)
            {        // form jsbsim <acname> <resetfile>
                aircraftName = rootDir + aircraftName;
                resetName    = rootDir + resetName;
                fdm.LoadModel(rootDir + "aircraft", rootDir + "engine", aircraftName);

                IC = fdm.GetIC;
                IC.Load(resetName, true);

                Trim fgt = new Trim(fdm, TrimMode.Full);
                if (!fgt.DoTrim())
                {
                    log.Debug("Trim Failed");
                }
                fgt.Report();
            }
            else
            {
                Console.WriteLine("  No Aircraft, Script, or Reset information given\n");
                return;
            }

            long clockTicks = 0, totalPauseTicks = 0, pauseTicks = 0;
            long initialClockTicks = System.DateTime.Now.Ticks;

            double newFiveSecondValue = 0.0;
            bool   scriptResult       = true;
            bool   result             = fdm.Run();

            if (suspend)
            {
                fdm.Hold();
            }

            //Displays a pattern defined by the universal sortable date/time pattern
            const string timeFormat = "yyyy-MM-dd HH:mm:ss.fffffff";

            //strftime(s, 99, "%A %B %D %Y %X", localtime(&tod));
            if (log.IsInfoEnabled)
            {
                log.Info("Start: " + DateTime.Now.ToString(timeFormat));
            }

            // if running realtime, throttle the execution, else just run flat-out fast
            // if suspended, then don't increment realtime counter
            while (result && scriptResult)
            {
                if (!(fdm.Holding() || fdm.State.IsIntegrationSuspended))
                {
                    if (realtime)
                    { // realtime mode
                        // track times when simulation is suspended
                        if (pauseTicks != 0)
                        {
                            totalPauseTicks += clockTicks - pauseTicks;
                            pauseTicks       = 0;
                        }

                        while ((clockTicks - totalPauseTicks) / TimeSpan.TicksPerSecond >= fdm.State.SimTime)
                        {
                            if (scripted)
                            {
                                if (!script.RunScript())
                                {
                                    scriptResult = false;
                                    break;
                                }
                            }
                            result = fdm.Run();

                            // print out status every five seconds
                            if (fdm.State.SimTime >= newFiveSecondValue)
                            {
                                if (log.IsInfoEnabled)
                                {
                                    log.Info("Simulation elapsed time: " + fdm.State.SimTime);
                                }
                                newFiveSecondValue += 5.0;
                            }
                            if (fdm.Holding())
                            {
                                break;
                            }
                        }
                    }
                    else
                    { // batch mode
                        if (scripted)
                        {
                            if (!script.RunScript())
                            {
                                scriptResult = false;
                                break;
                            }
                        }
                        result = fdm.Run();
                    }
                }
                else
                { // Suspended
                    if (pauseTicks == 0)
                    {
                        pauseTicks = System.DateTime.Now.Ticks - initialClockTicks; // remember start of pause
                        Console.WriteLine("  ... Holding ...\n\n");
                    }
                    result = fdm.Run();
                }
                clockTicks = System.DateTime.Now.Ticks - initialClockTicks;
            }
            if (log.IsInfoEnabled)
            {
                log.Info("End: " + DateTime.Now.ToString(timeFormat));
                log.Info("Seconds processor time used: " + (double)(clockTicks - totalPauseTicks) / (double)TimeSpan.TicksPerSecond + " seconds");
            }
        }