Open Street Maps integration

Added OSM to openpilot to use speed limits and road names.

Credit goes to Pfeiferj!

https: //github.com/pfeiferj
Co-Authored-By: Jacob Pfeifer <jacob@pfeifer.dev>
This commit is contained in:
FrogAi
2024-01-12 22:39:30 -07:00
parent 672a0e05e2
commit 88dad9d306
12 changed files with 888 additions and 6 deletions

View File

@@ -279,7 +279,7 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) {
int margin = 40;
int radius = 30;
int offset = scene.always_on_lateral || scene.conditional_experimental ? 25 : 0;
int offset = scene.always_on_lateral || scene.conditional_experimental || scene.road_name_ui ? 25 : 0;
if (alert.size == cereal::ControlsState::AlertSize::FULL) {
margin = 0;
radius = 0;
@@ -819,7 +819,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s)
// base icon
int offset = UI_BORDER_SIZE + btn_size / 2;
offset += alwaysOnLateral || conditionalExperimental ? 25 : 0;
offset += alwaysOnLateral || conditionalExperimental || roadNameUI ? 25 : 0;
int x = rightHandDM ? width() - offset : offset;
int y = height() - offset;
float opacity = dmActive ? 0.65 : 0.2;
@@ -1109,6 +1109,7 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets(QPainter &p) {
muteDM = scene.mute_dm;
obstacleDistance = scene.obstacle_distance;
obstacleDistanceStock = scene.obstacle_distance_stock;
roadNameUI = scene.road_name_ui;
showDriverCamera = scene.show_driver_camera;
stoppedEquivalence = scene.stopped_equivalence;
turnSignalLeft = scene.turn_signal_left;
@@ -1120,7 +1121,7 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets(QPainter &p) {
drawLeadInfo(p);
}
if (alwaysOnLateral || conditionalExperimental) {
if (alwaysOnLateral || conditionalExperimental || roadNameUI) {
drawStatusBar(p);
}
@@ -1409,6 +1410,8 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
p.setOpacity(1.0);
p.drawRoundedRect(statusBarRect, 30, 30);
QString roadName = roadNameUI ? QString::fromStdString(paramsMemory.get("RoadName")) : QString();
QMap<int, QString> conditionalStatusMap = {
{0, "Conditional Experimental Mode ready"},
{1, "Conditional Experimental overridden"},
@@ -1434,8 +1437,8 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
newStatus = conditionalStatusMap.contains(conditionalStatus) && status != STATUS_DISENGAGED ? conditionalStatusMap[conditionalStatus] : conditionalStatusMap[0];
}
// Check if status has changed
if (newStatus != lastShownStatus) {
// Check if status has changed or if the road name is empty
if (newStatus != lastShownStatus || roadName.isEmpty()) {
displayStatusText = true;
lastShownStatus = newStatus;
timer.restart();
@@ -1452,10 +1455,15 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
p.setRenderHint(QPainter::TextAntialiasing);
// Calculate text opacity
static qreal roadNameOpacity;
static qreal statusTextOpacity;
int elapsed = timer.elapsed();
if (displayStatusText) {
statusTextOpacity = qBound(0.0, 1.0 - (elapsed - textDuration) / fadeDuration, 1.0);
roadNameOpacity = 1.0 - statusTextOpacity;
} else {
roadNameOpacity = qBound(0.0, elapsed / fadeDuration, 1.0);
statusTextOpacity = 1.0 - roadNameOpacity;
}
// Draw the status text
@@ -1464,6 +1472,14 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) {
textRect.moveBottom(statusBarRect.bottom() - 50);
p.drawText(textRect, Qt::AlignCenter | Qt::TextWordWrap, newStatus);
// Draw the road name with the calculated opacity
if (!roadName.isEmpty()) {
p.setOpacity(roadNameOpacity);
textRect = p.fontMetrics().boundingRect(statusBarRect, Qt::AlignCenter | Qt::TextWordWrap, roadName);
textRect.moveBottom(statusBarRect.bottom() - 50);
p.drawText(textRect, Qt::AlignCenter | Qt::TextWordWrap, roadName);
}
p.restore();
}