Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup ford radar #1408

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opendbc/car/ford/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.carName = "ford"
ret.dashcamOnly = bool(ret.flags & FordFlags.CANFD)

ret.radarUnavailable = True
ret.radarUnavailable = False
ret.steerControlType = structs.CarParams.SteerControlType.angle
ret.steerActuatorDelay = 0.2
ret.steerLimitTimer = 1.0
Expand Down
22 changes: 19 additions & 3 deletions opendbc/car/ford/radar_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _create_delphi_mrr_radar_can_parser(CP) -> CANParser:
msg = f"MRR_Detection_{i:03d}"
messages += [(msg, 33)]

return CANParser(RADAR.DELPHI_MRR, messages, CanBus(CP).radar)
return CANParser(RADAR.DELPHI_MRR, messages + [('MRR_Header_InformationDetections', 33)], CanBus(CP).radar)


class RadarInterface(RadarInterfaceBase):
Expand All @@ -45,6 +45,7 @@ def __init__(self, CP):
elif self.radar == RADAR.DELPHI_MRR:
self.rcp = _create_delphi_mrr_radar_can_parser(CP)
self.trigger_msg = DELPHI_MRR_RADAR_START_ADDR + DELPHI_MRR_RADAR_MSG_COUNT - 1
print('trigger_msg:', self.trigger_msg)
else:
raise ValueError(f"Unsupported radar: {self.radar}")

Expand All @@ -55,7 +56,9 @@ def update(self, can_strings):
vls = self.rcp.update_strings(can_strings)
self.updated_messages.update(vls)

if self.trigger_msg not in self.updated_messages:
# print('updated_messages:', self.updated_messages)
# if self.trigger_msg not in self.updated_messages:
if 368 not in self.updated_messages:
Copy link
Contributor Author

@sshane sshane Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All track message's LSB scan index signals always match the header counter's 2 LSB when waiting for it now, before it would usually have a few messages that mismatched every cycle (so we should have waited a bit longer for the header message to have the most up to date detection/track messages)

return None

ret = structs.RadarData()
Expand All @@ -68,6 +71,10 @@ def update(self, can_strings):
self._update_delphi_esr()
elif self.radar == RADAR.DELPHI_MRR:
self._update_delphi_mrr()
print('pts', len(self.pts), self.rcp.vl['MRR_Header_InformationDetections']['CAN_NUMBER_OF_DET'])
Copy link
Contributor Author

@sshane sshane Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAN_NUMBER_OF_DET was always lower by 3-6 times from our number of points, now they match exactly!

It was originally thought that CAN_SCAN_INDEX_2LSB_xx was a sort of multiplexing signal, but it makes more sense that along with the header message it's used to ensure that the latest updates are kept up to sync.

Will have to look into the flickering that was noticed in the original PR (commaai/openpilot#24296) though, perhaps some more robust track switching logic is needed, or maybe it's not a problem since Harald added it after the original PR.

if len(self.pts) != self.rcp.vl['MRR_Header_InformationDetections']['CAN_NUMBER_OF_DET']:
print('mismatch!')
# raise Exception

ret.points = list(self.pts.values())
self.updated_messages.clear()
Expand Down Expand Up @@ -103,13 +110,22 @@ def _update_delphi_esr(self):
del self.pts[ii]

def _update_delphi_mrr(self):
print()
header = self.rcp.vl['MRR_Header_InformationDetections']
scan_index = header['CAN_SCAN_INDEX']
# print('scan_index', int(scan_index) & 0b11, scan_index)

for ii in range(1, DELPHI_MRR_RADAR_MSG_COUNT + 1):
msg = self.rcp.vl[f"MRR_Detection_{ii:03d}"]

# SCAN_INDEX rotates through 0..3 on each message
# treat these as separate points
scanIndex = msg[f"CAN_SCAN_INDEX_2LSB_{ii:02d}"]
i = (ii - 1) * 4 + scanIndex
i = ii # (ii - 1) * 4 + scanIndex
# print('pt scanIndex', scanIndex)
if scanIndex != int(scan_index) & 0b11:
print('doesn\'t match!', scanIndex, int(scan_index) & 0b11, scan_index)
# raise Exception

if i not in self.pts:
self.pts[i] = structs.RadarData.RadarPoint()
Expand Down
Loading