The Drone Simulator is used to create a fleet of drones which send randomized location data to the UDP server.
The Drone simulator uses the following functions
-
createFleet
- ThecreateFleet
function uses a set of environment variables to setup a fleet of drones.- It uses the
FLEET_SIZE
environment variable to start a fleet of drones. It has a default value of 15. - For each drone it creates a random life period between 10 and 30 seconds. At the end of this period the simulated drone shuts down and sends no further location updates
- It uses the
UPDATE_INTERVAL
environment variable to decide the interval at which the drones would send updates. It is set at a default value of 1second
- It uses the
-
isOnline
- This function simulates the network connectivity status of the drone. This returns a promise that resolves with a Boolean specifying whether the drone is online. The function takes an argument to define the probability of the drone being online. The default probability is set at 0.5. -
getPosition
- This returns a promise that resolves with the current location of the Drone.The
getPosition
promise resolves to the following position object{ latitude: '' // In Decimal Degrees longitude: '' // In Decimal Degrees timestamp: '' // Unix timestamp }
The
latitude
property returns the latitude in Decimal Degrees as a String Thelongitude
property returns the longitude in Decimal Degrees as a String Thetimestamp
property returns the Unix timestamp as a NumberThe
getPosition
function takesdroneId
as a parameter and on subsequent calls returns the position for the drone along a tracjectory based on the drone's last position. -
watchPosition
- This function simulates the behavior of thewatchPosition
method of the GeoLocation API in HTML5. It takes a callback as a parameter. It then invokes the callback with a new position in a random interval of 1 to 4 seconds.