Beispiel #1
0
        /// <summary>
        /// Moves the specified drone across all its navigation points
        /// </summary>
        /// <param name="drone"></param>
        /// <param name="droneShutdownToken"></param>
        private void PerformNavigationRoutine(Drone drone, CancellationToken droneShutdownToken)
        {
            foreach (RoutePoint routePoint in drone.Route)
            {
                //If shutdown signal sent, send drone to origin point and shut it down
                if (droneShutdownToken.IsCancellationRequested)
                {
                    drone.MoveToOrigin();
                    Console.WriteLine("Navigation Routine for drone " + drone.Id + " canceled");
                    return;
                }

                drone.Move(routePoint);
                Console.WriteLine("[" + routePoint.Time.ToLongTimeString() + "] Drone " + drone.Id + " moved to lat=" + drone.CurrentRoutePoint.Latitude + ", lng=" + drone.CurrentRoutePoint.Longitude);

                //Report traffic conditions if tube station near
                TubeStation tubeStationNear = FirstTubeStationNearLocation(drone.CurrentRoutePoint.Latitude, drone.CurrentRoutePoint.Longitude);
                if (tubeStationNear != null)
                {
                    ReportTrafficInfo(drone, tubeStationNear);
                }

                //Send shut down signal if 8:10 or later
                if (routePoint.Time.Hour >= 8 && routePoint.Time.Minute >= 10)
                {
                    ShutDownDrones();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reports the current position traffic info
        /// </summary>
        private void ReportTrafficInfo(Drone drone, TubeStation tubeStation)
        {
            double distanceTraveled = drone.LastRoutePoint.GetGeoCoordinate().GetDistanceTo(drone.CurrentRoutePoint.GetGeoCoordinate());
            double speed            = distanceTraveled / (drone.CurrentRoutePoint.Time - drone.LastRoutePoint.Time).TotalSeconds;

            Console.WriteLine("[TRAFFIC REPORT BY DRONE " + drone.Id + "] " +
                              "Location: " + tubeStation.StreetName +
                              ", Time: " + drone.CurrentRoutePoint.Time.ToShortTimeString() +
                              ", Speed: " + Math.Round(speed, 2) + "m/s" +
                              ", Traffic: " + drone.GetTrafficConditionsInCurrentPosition());
        }