Created
November 11, 2024 10:21
-
-
Save joaofig/9eeb8a326c0aa4d33755c0113a362c4b to your computer and use it in GitHub Desktop.
Dead reckoning function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dead_reckon(gps_segment: GpsSegment, | |
distances: np.ndarray, | |
gps_ids: np.ndarray, | |
timestamps: np.ndarray) -> List[DeadReckon]: | |
locations: List[DeadReckon] = [ | |
DeadReckon(signal_id = int(gps_ids[0]), | |
latitude=gps_segment.points[0].lat, | |
longitude=gps_segment.points[0].lon, | |
t=float(timestamps[0])) | |
] | |
d = 0.0 | |
i_gps = 1 | |
i_dx = 0 | |
for distance, signal_id in zip(distances, gps_ids[1:]): | |
d += distance | |
if d >= gps_segment.distances[i_dx]: | |
d -= gps_segment.distances[i_dx] | |
i_dx += 1 | |
if i_dx >= len(gps_segment.distances): | |
while i_gps < len(gps_ids) - 1: | |
locations.append(DeadReckon(signal_id = int(gps_ids[i_gps]), | |
latitude=gps_segment.points[i_dx-1].lat, | |
longitude=gps_segment.points[i_dx-1].lon, | |
t=float(timestamps[i_gps]))) | |
i_gps += 1 | |
break | |
if i_gps < len(gps_ids) - 1: | |
lat, lon = delta_location(*gps_segment.points[i_dx].to_tuple(), | |
gps_segment.bearings[i_dx], d) | |
locations.append( | |
DeadReckon(signal_id = int(signal_id), latitude = lat, longitude = lon, | |
t = float(timestamps[i_gps])) | |
) | |
i_gps += 1 | |
return locations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment