Skip to content

Commit

Permalink
ui: Display DM camera when reversing (commaai#69)
Browse files Browse the repository at this point in the history
* ui: show driver monitoring camera in reverse gear

* oops

* hide extra UIs if toggle enabled
  • Loading branch information
sunnyhaibin authored Apr 25, 2023
1 parent 0d6d336 commit a3f4c24
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 48 deletions.
6 changes: 4 additions & 2 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, CP, CarController, CarState):
self.gac_button_counter = 0
self.gac_min = -1
self.gac_max = -1
self.reverse_dm_cam = self.param_s.get_bool("ReverseDmCam")

@staticmethod
def get_pid_accel_limits(CP, current_speed, cruise_speed):
Expand Down Expand Up @@ -282,9 +283,9 @@ def create_common_events(self, cs_out, c, extra_gears=None, pcm_enable=True, all
else:
events.add(EventName.wrongGear)
if cs_out.gearShifter == GearShifter.reverse:
if cs_out.vEgo < 5:
if not self.reverse_dm_cam and cs_out.vEgo < 5:
events.add(EventName.spReverseGear)
else:
elif cs_out.vEgo >= 5:
events.add(EventName.reverseGear)
if not cs_out.cruiseState.available:
events.add(EventName.wrongCarMode)
Expand Down Expand Up @@ -542,6 +543,7 @@ def sp_update_params(self, CS):
self._frame = 0
self.gac = self.param_s.get_bool("GapAdjustCruise")
self.gac_mode = round(float(self.param_s.get("GapAdjustCruiseMode", encoding="utf8")))
self.reverse_dm_cam = self.param_s.get_bool("ReverseDmCam")

class RadarInterfaceBase(ABC):
def __init__(self, CP):
Expand Down
10 changes: 10 additions & 0 deletions selfdrive/ui/qt/offroad/sunnypilot_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,16 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : QWidget(parent) {
));


// Visuals: Display DM Camera in Reverse Gear
main_layout->addWidget(horizontal_line());
main_layout->addWidget(new ParamControl(
"ReverseDmCam",
tr("Display DM Camera in Reverse Gear"),
tr("Show Driver Monitoring camera while the car is in reverse gear."),
"../assets/offroad/icon_road.png"
));


// Visuals: OSM: Show debug UI elements
main_layout->addWidget(horizontal_line());
main_layout->addWidget(new ParamControl(
Expand Down
100 changes: 54 additions & 46 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
setProperty("curveSign", lp.getTurnSign());
}

setProperty("reversing", int(car_state.getGearShifter()) == 4);

// DM icon transition
dm_fade_state = fmax(0.0, fmin(1.0, dm_fade_state+0.2*(0.5-(float)(dmActive))));
}
Expand Down Expand Up @@ -746,60 +748,62 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
drawText(p, rect().center().x(), 290, speedUnit, 200);
}

// ####### 1 ROW #######
QRect bar_rect1(rect().left(), rect().bottom() - 60, rect().width(), 61);
if (devUiEnabled && !mapVisible && devUiInfo == 1) {
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 100));
p.drawRect(bar_rect1);
drawNewDevUi2(p, bar_rect1.left(), bar_rect1.center().y());
}
if (!reversing) {
// ####### 1 ROW #######
QRect bar_rect1(rect().left(), rect().bottom() - 60, rect().width(), 61);
if (devUiEnabled && !mapVisible && devUiInfo == 1) {
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 100));
p.drawRect(bar_rect1);
drawNewDevUi2(p, bar_rect1.left(), bar_rect1.center().y());
}

// ####### 1 COLUMN ########
QRect rc2(rect().right() - (bdr_s * 2), bdr_s * 1.5, 184, 152);
if (devUiEnabled) {
drawRightDevUi(p, rect().right() - 184 - bdr_s * 2, bdr_s * 2 + rc2.height());
}
// ####### 1 COLUMN ########
QRect rc2(rect().right() - (bdr_s * 2), bdr_s * 1.5, 184, 152);
if (devUiEnabled) {
drawRightDevUi(p, rect().right() - 184 - bdr_s * 2, bdr_s * 2 + rc2.height());
}

int rn_btn = 0;
rn_btn = devUiEnabled && !mapVisible && devUiInfo == 1 ? 30 : 0;
uiState()->scene.rn_offset = rn_btn;
int rn_btn = 0;
rn_btn = devUiEnabled && !mapVisible && devUiInfo == 1 ? 30 : 0;
uiState()->scene.rn_offset = rn_btn;

// Dynamic Lane Profile Button
if (dynamicLaneProfileToggle) {
drawDlpButton(p, bdr_s * 2 + 220, (rect().bottom() - footer_h / 2 - 75) - rn_btn, 150, 150);
}
// Dynamic Lane Profile Button
if (dynamicLaneProfileToggle) {
drawDlpButton(p, bdr_s * 2 + 220, (rect().bottom() - footer_h / 2 - 75) - rn_btn, 150, 150);
}

if (gac) {
drawGacButton(p, bdr_s * 2 + 220 + 180, (rect().bottom() - footer_h / 2 - 75) - rn_btn, 150, 150);
}
if (gac) {
drawGacButton(p, bdr_s * 2 + 220 + 180, (rect().bottom() - footer_h / 2 - 75) - rn_btn, 150, 150);
}

// Stand Still Timer
if (standStillTimer && standStill) {
drawStandstillTimer(p, rect().right() - 650, 30 + 160 + 250);
}
// Stand Still Timer
if (standStillTimer && standStill) {
drawStandstillTimer(p, rect().right() - 650, 30 + 160 + 250);
}

// V-TSC
if (showDebugUI && showVTC) {
drawVisionTurnControllerUI(p, rect().right() - 184 - bdr_s, int(bdr_s * 1.5), 184, vtcColor, vtcSpeed, 100);
}
// V-TSC
if (showDebugUI && showVTC) {
drawVisionTurnControllerUI(p, rect().right() - 184 - bdr_s, int(bdr_s * 1.5), 184, vtcColor, vtcSpeed, 100);
}

// Bottom bar road name
if (showDebugUI && !roadName.isEmpty()) {
const int h = 38;
QRect bar_rc(rect().left(), rect().top(), rect().width(), h);
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 100));
p.drawRect(bar_rc);
configFont(p, "Inter", 28, "Bold");
drawCenteredText(p, bar_rc.center().x(), bar_rc.center().y(), roadName, QColor(255, 255, 255, 200));
}
// Bottom bar road name
if (showDebugUI && !roadName.isEmpty()) {
const int h = 38;
QRect bar_rc(rect().left(), rect().top(), rect().width(), h);
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 100));
p.drawRect(bar_rc);
configFont(p, "Inter", 28, "Bold");
drawCenteredText(p, bar_rc.center().x(), bar_rc.center().y(), roadName, QColor(255, 255, 255, 200));
}

// Turn Speed Sign
if (showTurnSpeedLimit) {
QRect rc = speed_sgn_rc;
rc.moveTop(speed_sgn_rc.bottom() + bdr_s);
drawTrunSpeedSign(p, rc, turnSpeedLimit, tscSubText, curveSign, tscActive);
// Turn Speed Sign
if (showTurnSpeedLimit) {
QRect rc = speed_sgn_rc;
rc.moveTop(speed_sgn_rc.bottom() + bdr_s);
drawTrunSpeedSign(p, rc, turnSpeedLimit, tscSubText, curveSign, tscActive);
}
}
p.restore();
}
Expand Down Expand Up @@ -1636,6 +1640,10 @@ void AnnotatedCameraWidget::paintEvent(QPaintEvent *event) {
}
CameraWidget::setStreamType(wide_cam_requested ? VISION_STREAM_WIDE_ROAD : VISION_STREAM_ROAD);

if (reversing && s->scene.reverse_dm_cam) {
CameraWidget::setStreamType(VISION_STREAM_DRIVER);
}

s->scene.wide_cam = CameraWidget::getStreamType() == VISION_STREAM_WIDE_ROAD;
if (s->scene.calibration_valid) {
auto calib = s->scene.wide_cam ? s->scene.view_from_wide_calib : s->scene.view_from_calib;
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/ui/qt/onroad.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class AnnotatedCameraWidget : public CameraWidget {

Q_PROPERTY(float btnPerc MEMBER btnPerc);

Q_PROPERTY(bool reversing MEMBER reversing);

public:
explicit AnnotatedCameraWidget(VisionStreamType type, QWidget* parent = 0);
void updateState(const UIState &s);
Expand Down Expand Up @@ -267,6 +269,8 @@ class AnnotatedCameraWidget : public CameraWidget {

float btnPerc;

bool reversing;

protected:
void paintGL() override;
void initializeGL() override;
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void ui_update_params(UIState *s) {
s->scene.dev_ui_enabled = params.getBool("DevUI");
s->scene.dev_ui_info = std::atoi(params.get("DevUIInfo").c_str());
s->scene.button_auto_hide = params.getBool("ButtonAutoHide");
s->scene.reverse_dm_cam = params.getBool("ReverseDmCam");

if (s->scene.onroadScreenOff > 0) {
s->scene.osoTimer = s->scene.onroadScreenOff * 60 * UI_FREQ;
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ typedef struct UIScene {
bool sleep_btn_fading_in = false;
int sleep_btn_opacity = 20;
bool button_auto_hide;

bool reverse_dm_cam;
} UIScene;

class UIState : public QObject {
Expand Down

0 comments on commit a3f4c24

Please sign in to comment.