Skip to content

Commit

Permalink
see if this is faster
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Oct 30, 2024
1 parent 3e579f0 commit a7e1541
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions opendbc/car/ford/radar_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ def update(self, can_strings):
return None

ret = structs.RadarData()
# ret.points = list(self.pts.values())
ret.points = [structs.RadarData.RadarPoint(dRel=pt.dRelClosest, yRel=pt.yRel, vRel=pt.vRel, trackId=pt.trackId,
measured=True, aRel=float('nan'), yvRel=float('nan'))
for pt in self.clusters]

ret.points = list(self.pts.values())
# ret.points = [structs.RadarData.RadarPoint(dRel=pt.dRelClosest, yRel=pt.yRel, vRel=pt.vRel, trackId=pt.trackId,
# measured=True, aRel=float('nan'), yvRel=float('nan'))
# for pt in self.clusters]
ret.errors = errors
return ret

Expand Down Expand Up @@ -258,7 +259,7 @@ def _update_delphi_mrr(self):
self.track_id += 1

self.clusters = []
for track_id, pts in points_by_track_id.items():
for idx, (track_id, pts) in enumerate(points_by_track_id.items()):
dRel = [p[0] for p in pts]
min_dRel = min(dRel)
dRel = sum(dRel) / len(dRel)
Expand All @@ -269,8 +270,20 @@ def _update_delphi_mrr(self):
vRel = [p[2] for p in pts]
vRel = sum(vRel) / len(vRel) / 2

# Creating RadarPoint and accessing attributes are both expensive, so we store a dataclass and re-use the RadarPoint
self.clusters.append(Cluster(dRel=dRel, dRelClosest=min_dRel, yRel=yRel, vRel=vRel, trackId=track_id))

if idx not in self.pts:
self.pts[idx] = structs.RadarData.RadarPoint(measured=True, aRel=float('nan'), yvRel=float('nan'))

self.pts[idx].dRel = dRel
self.pts[idx].yRel = yRel
self.pts[idx].vRel = vRel
self.pts[idx].trackId = track_id

for idx in range(len(points_by_track_id), len(self.pts)):
del self.pts[idx]

if PLOT:
self.ax.clear()

Expand Down

0 comments on commit a7e1541

Please sign in to comment.