Exemple #1
0
        public async void Put(string vehicleId, [FromBody] SimulatedCar car)
        {
            var proxy = ActorProxy.Create <ICarActor>(new ActorId($"SimulatedCar:{car.VehicleId}"));

            if (car.Running)
            {
                await proxy.StartAsync(car.VehicleId, car.StartLatitude, car.StartLongitude, CancellationToken.None);
            }
            else
            {
                await proxy.StopAsync(CancellationToken.None);
            }
        }
Exemple #2
0
        private async Task MakeOneCarDrive(Random random, TrafficSegmentConfiguration trafficConfiguration, TrafficSegmentSituation segmentSituation, IEventTransmitter startCameraEventTransmitter, IEventTransmitter endCameraEventTransmitter, CancellationToken cancellationToken)
        {
            // Wait random short interval to add randomness
            await Task.Delay(TimeSpan.FromMilliseconds(random.Next(2000)), cancellationToken);

            var car = SimulatedCar.Randomize
                      (
                random, segmentSituation
                      );

            try
            {
                //regenerate new license plate for every run
                var carTimespan = car.CalculateTime(trafficConfiguration.CameraDistance, _simulationSettings.TimeSimulationAccelerator);
                await startCameraEventTransmitter.Transmit(
                    new CameraEvent
                {
                    TrajectId = trafficConfiguration.SegmentId,
                    CameraId  = CameraType.Camera1.ToString(),
                    EventTime = SimulatedClock.Time,
                    Car       = car,
                    Lane      = LaneCalculator.CalculateLane(trafficConfiguration, segmentSituation, car)
                }, cancellationToken);

                _logger.Trace($"{car.Color} {car.Make} with license plate {car.LicensePlate} detected by camera 01 (limit {segmentSituation.SpeedLimit})");
                await Task.Delay(carTimespan, cancellationToken);

                await endCameraEventTransmitter.Transmit(
                    new CameraEvent
                {
                    TrajectId = trafficConfiguration.SegmentId,
                    CameraId  = CameraType.Camera2.ToString(),
                    EventTime = SimulatedClock.Time,
                    Car       = car,
                    Lane      = LaneCalculator.CalculateLane(trafficConfiguration, segmentSituation, car)
                }, cancellationToken);

                _logger.Trace($"{car.Color} {car.Make} with license plate {car.LicensePlate} detected by camera 02 (limit {segmentSituation.SpeedLimit})");
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error happened in one of the simulation threads");
            }
        }