// private readonly LoggingManager _log; // private readonly int _infoPin; public TrainControlStack(int unitId, LoggingManager log, INetworkDatabase network) { // _log = log; // var eh = _log.GetEntityHandle(typeof(TrainControlStack), unitId); // _infoPin = _log.GetSignalPin(eh, "info"); _scheduleController = new ScheduleController(unitId, log); _waypointController = new WaypointController(unitId, log, network); _tractionController = new TractionController(unitId, log); }
public WaypointController(int unitId, LoggingManager log, INetworkDatabase network) { _network = network; _routePlanner = new RoutePlanner(network); _log = log; var eh = _log.GetEntityHandle(this.GetType(), unitId); _infoPin = _log.GetSignalPin(eh, "info"); _statePin = _log.GetSignalPin(eh, "state"); }
static void Main(string[] args) { Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { // import GeoJSON data to SQLite if (o.ImportScenario != null) { InitializeDatabaseFrom(o.DbFile, o.ImportScenario); } // open database var db = SqliteSimDatabase.Open(o.DbFile); // simulate if (o.Simulate) { var logFileName = o.DbFile + ".csv"; using var log = new LoggingManager(logFileName); var sw = new Stopwatch(); sw.Restart(); var sim = new Simulation(db.GetCoordinateSpace(), db, db, log); var steps = 50; var dt = 1.0f; for (var i = 0; i < steps; i++) { sim.Step(dt); } Console.WriteLine($"Took {sw.ElapsedMilliseconds * 0.001:F2} s to simulate {steps * dt:F2} s"); } // render 2D/3D view if (o.RenderSvg != null) { GraphicsOutput.RenderSvg(db.GetCoordinateSpace(), db, db, o.RenderSvg); } }); }
public Simulation(SimulationCoordinateSpace coordSpace, INetworkDatabase network, IUnitDatabase units, LoggingManager log) { CoordSpace = coordSpace; Network = network; Units = units; _log = log; _currentSegmentByUnitId = new int?[units.GetNumUnits()]; _dirByUnitId = new SegmentEndpoint[units.GetNumUnits()]; _tByUnitId = new float[units.GetNumUnits()]; _unitProperties = new UnitProperties[units.GetNumUnits()]; for (var unitIndex = 0; unitIndex < Units.GetNumUnits(); unitIndex++) { var unit = Units.GetUnitByIndex(unitIndex); var result = Network.FindSegmentAt(unit.Pos, unit.Orientation, 0.2f, (float)(Math.PI * 0.25)); if (result == null) { Console.Error.WriteLine($"Simulation: could not snap unit {unitIndex} to railroad network!"); continue; } var(segmentId, dir, t) = result.Value; _currentSegmentByUnitId[unitIndex] = segmentId; _dirByUnitId[unitIndex] = dir; _tByUnitId[unitIndex] = t; var eh = _log.GetEntityHandle(_unitProperties[unitIndex].GetType(), unitIndex); _unitProperties[unitIndex] = new UnitProperties { Controller = new TrainControlStack(unitIndex, _log, Network), AccelerationPin = _log.GetSignalPin(eh, "acceleration"), VelocityPin = _log.GetSignalPin(eh, "velocity"), SegmentIdPin = _log.GetSignalPin(eh, "segmentId"), TPin = _log.GetSignalPin(eh, "t"), }; _unitProperties[unitIndex].Controller.GoAutoSchedule(); } }