示例#1
0
        private void InitializeSimulatedTestBench(TestType testType)
        {
            // get the behavior for the simulators, based on test type.
            var engine     = new SimulatorEngine(new Stopwatch());
            var torqueCell = new SimulatedTorqueCell(engine);
            var servoDrive = new SimulatedServoDrive(engine);

            TestBench.Initialize(torqueCell, servoDrive);
        }
        public void ElapsedTimeCountsDownForMultipleTestConditions()
        {
            // initialize the simulated test bench
            var engine     = new SimulatorEngine(new Stopwatch());
            var torqueCell = new SimulatedTorqueCell(engine);
            var servoDrive = new SimulatedServoDrive(engine);

            TestBench.Initialize(torqueCell, servoDrive);

            // create a fatigue test and add a condition.
            var fatigueTest = new FatigueTest();

            engine.CurrentCondition = SingleFatigueTestCondition();
            fatigueTest.TestConditions.Add(engine.CurrentCondition);
            fatigueTest.TestConditions.AddRange(MultipleFatigueTestConditions());

            // load the test.
            TestBench.Singleton.LoadTest(fatigueTest);
            TestBench.Singleton.BeginCurrentTest();

            TimeSpan start = new TimeSpan(0, 0, 0);

            for (int i = 0; i < 1000; i++)
            {
                if (i == 0)
                {
                    start = fatigueTest.EstimatedCompletionTime;
                }
                torqueCell.RefreshTorque();
                servoDrive.StoreParameter(ServoDriveEnums.RegisterAddress.TorqueValue, (int)torqueCell.Torque);
                servoDrive.RefreshPosition();
                System.Threading.Thread.Sleep(10);
            }
            TimeSpan finish = fatigueTest.EstimatedCompletionTime;

            Console.WriteLine($"The estimated completion for the duty cycle is {finish.Days}:{finish.Hours}:{finish.Minutes}:{finish.Seconds}");
            var totalSeconds = start.Subtract(finish).TotalSeconds;

            Assert.GreaterOrEqual(totalSeconds, 10);
        }
示例#3
0
        static async Task RunSimulationAsync(string csvOutputFile, AppSettings appSettings)
        {
            SimulatorConfiguration           simConfig;
            SimulatorEngine                  simEngine;
            IList <SimulatorEmployeeContact> allEmployeeContacts;
            SimulatorResult                  simulatorResult;

            try
            {
                simConfig = await CreateConfiguration(appSettings);

                simEngine           = new SimulatorEngine(simConfig);
                allEmployeeContacts = new List <SimulatorEmployeeContact>();
                simulatorResult     = new SimulatorResult();
                simEngine.InitializeSimulation();
            }
            catch (Exception exc)
            {
                LogMessage("ERROR", "Unable to configure and initialize the simulation: " + exc.ToString());
                throw exc;
            }

            try
            {
                LogMessage("INFO", "Starting simulation.");
                do
                {
                    simulatorResult = simEngine.RunNext();
                    allEmployeeContacts.AddRange(simulatorResult.EmployeeContacts);
                }while (!simulatorResult.IsSimulatorComplete && !simulatorResult.HasError);
                LogMessage("DEBUG", "Simulation complete. Creating output CSV file.");
                await ExportMethods.CreateSimulatorCsvLogAsync(allEmployeeContacts, simConfig.Employees, simConfig.WorkplaceRooms, simConfig.VirusStages, csvOutputFile);
            }
            catch (Exception exc)
            {
                LogMessage("ERROR", "Unable to complete simulation: " + exc.ToString());
                throw exc;
            }
        }
示例#4
0
        public void Init()
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            _engine = new SimulatorEngine(stopwatch);
            var condition = new FatigueTestCondition()
            {
                CounterclockwiseTorque = -1000,
                ClockwiseTorque        = 2500,
                CyclesPerSecond        = 3,
                CalibrationInterval    = 100,
                CyclesRequired         = 1000000,
                FatigueTestId          = 5,
                Id = 1
            };

            _engine.CurrentCondition = condition;
            _torqueCell           = new SimulatedTorqueCell(_engine);
            _servoDrive           = new SimulatedServoDrive(_engine);
            _servoDrive.Stiffness = 525;

            _engine.StartSimulate();
        }
示例#5
0
        public void Step60SecondsTest()
        {
            var map = new Map.Infrastructure.Map(1, 3);

            map.AddElement(0, 0, new Road());
            map.AddElement(0, 1, new Crossroad());
            map.AddElement(0, 2, new Road());
            map.SetConnected(0, 0, 0, 1);
            map.SetConnected(0, 1, 0, 2);

            var trafficFlow = new TrafficFlow();

            trafficFlow.TrafficDensity = 0.1;
            trafficFlow.TrafficSpeed   = 10;
            trafficFlow.Path.Add(new Location(0, 0));
            trafficFlow.Path.Add(new Location(0, 1));
            trafficFlow.Path.Add(new Location(0, 2));

            var trafficManager = new TrafficManager(map);

            trafficManager.AddTrafficFlow(trafficFlow);

            var engine = new SimulatorEngine(trafficManager);

            var crossroad = (ICrossroad)map.GetElement(0, 1);

            Assert.AreEqual(crossroad.LeftToRightTrafficLight.State, TrafficLightState.Red);
            Assert.AreEqual(crossroad.LeftToRightTrafficData.TrafficDensity, trafficFlow.TrafficDensity, Epsilon);
            Assert.AreEqual(crossroad.LeftToRightTrafficData.TrafficSpeed, trafficFlow.TrafficSpeed, Epsilon);

            engine.Step(60);

            Assert.AreEqual(TrafficLightState.Green, crossroad.LeftToRightTrafficLight.State);
            engine.Step(60);

            Assert.AreEqual(TrafficLightState.Green, crossroad.LeftToRightTrafficLight.State);
        }
示例#6
0
        public void step60OnceMore()
        {
            /* Initialize next map
             *
             *    | | |
             *   -+-+-+-
             *   || | ||
             *   -+-+-+-
             *    | | |
             */

            var map = new Map.Infrastructure.Map(5, 7);

            map.AddElement(0, 1, new Road());
            map.AddElement(0, 3, new Road());
            map.AddElement(0, 5, new Road());

            map.AddElement(1, 0, new Turn());
            map.AddElement(1, 1, new Crossroad());
            map.AddElement(1, 2, new Road());
            map.AddElement(1, 3, new Crossroad());
            map.AddElement(1, 4, new Road());
            map.AddElement(1, 5, new Crossroad());
            map.AddElement(1, 6, new Turn());

            map.AddElement(2, 0, new Road());
            map.AddElement(2, 1, new Road());
            map.AddElement(2, 3, new Road());
            map.AddElement(2, 5, new Road());
            map.AddElement(2, 6, new Road());

            map.AddElement(3, 0, new Turn());
            map.AddElement(3, 1, new Crossroad());
            map.AddElement(3, 2, new Road());
            map.AddElement(3, 3, new Crossroad());
            map.AddElement(3, 4, new Road());
            map.AddElement(3, 5, new Crossroad());
            map.AddElement(3, 6, new Turn());

            map.AddElement(4, 1, new Road());
            map.AddElement(4, 3, new Road());
            map.AddElement(4, 5, new Road());

            map.SetConnected(0, 1, 1, 1);
            map.SetConnected(0, 3, 1, 3);
            map.SetConnected(0, 5, 1, 5);

            map.SetConnected(1, 0, 1, 1);
            map.SetConnected(1, 0, 2, 0);
            map.SetConnected(1, 1, 1, 0);
            map.SetConnected(1, 1, 2, 1);
            map.SetConnected(1, 1, 1, 2);
            map.SetConnected(1, 2, 1, 3);
            map.SetConnected(1, 3, 2, 3);
            map.SetConnected(1, 3, 1, 4);
            map.SetConnected(1, 4, 1, 5);
            map.SetConnected(1, 5, 2, 5);
            map.SetConnected(1, 5, 1, 6);
            map.SetConnected(1, 6, 2, 6);

            map.SetConnected(2, 0, 3, 0);
            map.SetConnected(2, 1, 3, 1);
            map.SetConnected(2, 3, 3, 3);
            map.SetConnected(2, 3, 3, 3);
            map.SetConnected(2, 5, 3, 5);
            map.SetConnected(2, 6, 3, 6);

            map.SetConnected(3, 0, 3, 1);
            map.SetConnected(3, 1, 4, 1);
            map.SetConnected(3, 1, 3, 2);
            map.SetConnected(3, 2, 3, 3);
            map.SetConnected(3, 3, 4, 3);
            map.SetConnected(3, 3, 3, 4);
            map.SetConnected(3, 4, 3, 5);
            map.SetConnected(3, 5, 4, 5);
            map.SetConnected(3, 5, 3, 6);

            var trafficFlow = new TrafficFlow();

            trafficFlow.TrafficDensity = 0.1;
            trafficFlow.TrafficSpeed   = 60;
            trafficFlow.Path.Add(new Location(0, 1));
            trafficFlow.Path.Add(new Location(1, 1));
            trafficFlow.Path.Add(new Location(2, 1));
            trafficFlow.Path.Add(new Location(3, 1));
            trafficFlow.Path.Add(new Location(3, 2));
            trafficFlow.Path.Add(new Location(3, 3));
            trafficFlow.Path.Add(new Location(3, 4));

            var trafficFlow1 = new TrafficFlow();

            trafficFlow1.TrafficDensity = 0.6;
            trafficFlow1.TrafficSpeed   = 30;
            trafficFlow1.Path.Add(new Location(0, 1));
            trafficFlow1.Path.Add(new Location(1, 1));
            trafficFlow1.Path.Add(new Location(1, 2));
            trafficFlow1.Path.Add(new Location(1, 3));
            trafficFlow1.Path.Add(new Location(2, 3));
            trafficFlow1.Path.Add(new Location(3, 3));
            trafficFlow1.Path.Add(new Location(3, 4));

            var trafficManager = new TrafficManager(map);

            trafficManager.AddTrafficFlow(trafficFlow);
            trafficManager.AddTrafficFlow(trafficFlow1);

            var engine = new SimulatorEngine(trafficManager);

            var crossroad = (ICrossroad)map.GetElement(1, 1);

            Assert.AreEqual(crossroad.UpToDownTrafficLight.State, TrafficLightState.Red);
            Assert.AreEqual(crossroad.UpToRightTrafficLight.State, TrafficLightState.Red);
            engine.Step(60);
            engine.Step(60);
            engine.Step(60);
            engine.Step(60);

            Assert.AreEqual(TrafficLightState.Green, crossroad.UpToDownTrafficLight.State);
            Assert.AreEqual(TrafficLightState.Green, crossroad.UpToRightTrafficLight.State);

            engine.Step(60);
            Assert.AreEqual(TrafficLightState.Green, crossroad.UpToDownTrafficLight.State);
            Assert.AreEqual(TrafficLightState.Green, crossroad.UpToRightTrafficLight.State);
        }
示例#7
0
 public void Cleanup()
 {
     _engine.StopSimulate();
     _engine = null;
 }