Skip to content

Commit

Permalink
Updated GPS querying
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Oct 19, 2023
1 parent 098e5ee commit cef67f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ These are the features actively planned for Predator and are likely to be added
- [X] Add configuration value for the number of guesses the ALPR engine should make in pre-recorded mode.
- [X] Organize configuration.
- [X] Add support for multiple license plate formats.
- [X] Test updated license plate validation in real-time mode.
- [X] Test updated license plate validation in pre-recorded mode.
- [X] Test updated license plate validation in real-time mode.
- [X] Add Phantom alert handling to updated ALPR stream.
- [ ] Complete OpenCV dashcam recording.
- [ ] Improve the efficiency of GPS location requests when many requests are made in quick succession.
- [X] Improve the efficiency of GPS location requests when many requests are made in quick succession.
- [ ] Test that improved GPS location querying behaves as expected.
22 changes: 16 additions & 6 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,25 @@ def display_shape(shape):


# Define the function that will be used to get the current GPS coordinates.
last_gps_request = {} # This is a placeholder that will store information regarding the last GPS request.
last_gps_request["time"] = 0 # This is a placeholder that will hold the time that the last GPS request was made.
last_gps_request["data"] = [] # This is a placeholder that will hold the data from the last GPS request.
def get_gps_location(): # Placeholder that should be updated at a later date.
global last_gps_request
debug_message("Fetching current GPS location")
if (config["realtime"]["gps"]["enabled"] == True): # Check to see if GPS is enabled.
try: # Don't terminate the entire script if the GPS location fails to be aquired.
gpsd.connect() # Connect to the GPS daemon.
gps_data_packet = gpsd.get_current() # Get the current information.
return gps_data_packet.position()[0], gps_data_packet.position()[1], gps_data_packet.speed(), gps_data_packet.altitude(), gps_data_packet.movement()["track"], gps_data_packet.sats # Return GPS information.
except: # If the current location can't be established, then return placeholder location data.
return 0.0000, -0.0000, 0.0, 0.0, 0.0, 0 # Return a default placeholder location.
if (time.time()-last_gps_request["time"] > 1): # Check to see if a sufficient amount of time has passed since the last time the GPS was queried before making a new request.
try: # Don't terminate the entire script if the GPS location fails to be aquired.
gpsd.connect() # Connect to the GPS daemon.
gps_data_packet = gpsd.get_current() # Query the GPS for the most recent information.
last_gps_request["time"] = time.time() # Record the current time as the last time the GPS was queried.
last_gps_request["data"] = [gps_data_packet.position()[0], gps_data_packet.position()[1], gps_data_packet.speed(), gps_data_packet.altitude(), gps_data_packet.movement()["track"], gps_data_packet.sats] # Record the current information as the last GPS query response.

return gps_data_packet.position()[0], gps_data_packet.position()[1], gps_data_packet.speed(), gps_data_packet.altitude(), gps_data_packet.movement()["track"], gps_data_packet.sats # Return GPS information.
except: # If the current location can't be established, then return placeholder location data.
return 0.0000, -0.0000, 0.0, 0.0, 0.0, 0 # Return a default placeholder location.
else: # Otherwise, the last GPS request was made too recently, so simply return the last GPS query response instead of submitting a new one to save time.
return last_gps_request["data"][0], last_gps_request["data"][1], last_gps_request["data"][2], last_gps_request["data"][3], last_gps_request["data"][4], last_gps_request["data"][5]
else: # If GPS is disabled, then this function should never be called, but return a placeholder position regardless.
return 0.0000, 0.0000, 0.0, 0.0, 0.0, 0 # Return a default placeholder location.

Expand Down

0 comments on commit cef67f4

Please sign in to comment.