Skip to content

Commit

Permalink
Driver camera view when in reverse
Browse files Browse the repository at this point in the history
bug fix: use of undeclared identifier carState

bug fix: use of undeclared identifier scene

ui: update translations

bug fix: Unmatched {
  • Loading branch information
Edison-CBS committed Nov 11, 2023
1 parent fd21a44 commit a1e3c78
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 28 deletions.
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"LQR", PERSISTENT},
{"ScreenOffTimer", PERSISTENT},
{"CruiseSpeedRewrite", PERSISTENT},
{"DriverCamera", PERSISTENT},
};

} // namespace
Expand Down
7 changes: 7 additions & 0 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
"openpilot will set its maximum speed to the vehicle's current speed."),
"../assets/offroad/icon_cruise_speed_rewrite.png",
},
// DriverCamera, stolen from FrogPilot
{
"DriverCamera",
tr("Driver Camera On Reverse"),
tr("Displays the driver camera when in reverse."),
"../assets/img_driver_face_static.png",
},
{
"IsMetric",
tr("Use Metric System"),
Expand Down
65 changes: 37 additions & 28 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ void OnroadAlerts::updateAlert(const Alert &a) {
}

void OnroadAlerts::paintEvent(QPaintEvent *event) {
if (alert.size == cereal::ControlsState::AlertSize::NONE) {
const UIScene &scene = uiState()->scene;

if (alert.size == cereal::ControlsState::AlertSize::NONE || scene.show_driver_camera) {
return;
}
static std::map<cereal::ControlsState::AlertSize, const int> alert_heights = {
Expand Down Expand Up @@ -275,7 +277,9 @@ void ExperimentalButton::updateState(const UIState &s) {
void ExperimentalButton::paintEvent(QPaintEvent *event) {
QPainter p(this);
QPixmap img = experimental_mode ? experimental_img : engage_img;
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
if (!scene.show_driver_camera) {
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
}
}


Expand Down Expand Up @@ -351,7 +355,7 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
has_eu_speed_limit = (nav_alive && speed_limit_sign == cereal::NavInstruction::SpeedLimitSign::VIENNA);
is_metric = s.scene.is_metric;
speedUnit = s.scene.is_metric ? tr("km/h") : tr("mph");
hideBottomIcons = (cs.getAlertSize() != cereal::ControlsState::AlertSize::NONE);
hideBottomIcons = (cs.getAlertSize() != cereal::ControlsState::AlertSize::NONE || showDriverCamera);
status = s.status;

// update engageability/experimental mode button
Expand All @@ -363,7 +367,10 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
rightHandDM = dm_state.getIsRHD();
// DM icon transition
dm_fade_state = std::clamp(dm_fade_state+0.2*(0.5-dmActive), 0.0, 1.0);


// FrogPilot variables
showDriverCamera = scene.show_driver_camera;

// FrogPilot properties
setProperty("drivingPersonalitiesUIWheel", s.scene.driving_personalities_ui_wheel);
setProperty("personalityProfile", s.scene.personality_profile);
Expand Down Expand Up @@ -688,7 +695,7 @@ void AnnotatedCameraWidget::paintGL() {
// for replay of old routes, never go to widecam
wide_cam_requested = wide_cam_requested && s->scene.calibration_wide_valid;
}
CameraWidget::setStreamType(wide_cam_requested ? VISION_STREAM_WIDE_ROAD : VISION_STREAM_ROAD);
CameraWidget::setStreamType(showDriverCamera ? VISION_STREAM_DRIVER : wide_cam_requested ? VISION_STREAM_WIDE_ROAD : VISION_STREAM_ROAD);

s->scene.wide_cam = CameraWidget::getStreamType() == VISION_STREAM_WIDE_ROAD;
if (s->scene.calibration_valid) {
Expand All @@ -705,35 +712,37 @@ void AnnotatedCameraWidget::paintGL() {
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);

if (s->worldObjectsVisible()) {
if (sm.rcv_frame("modelV2") > s->scene.started_frame) {
update_model(s, model, sm["uiPlan"].getUiPlan());
if (sm.rcv_frame("radarState") > s->scene.started_frame) {
update_leads(s, radar_state, model.getPosition());
if (!showDriverCamera) {
if (s->worldObjectsVisible()) {
if (sm.rcv_frame("modelV2") > s->scene.started_frame) {
update_model(s, model, sm["uiPlan"].getUiPlan());
if (sm.rcv_frame("radarState") > s->scene.started_frame) {
update_leads(s, radar_state, model.getPosition());
}
}
}

drawLaneLines(painter, s);

if (s->scene.longitudinal_control) {
auto lead_one = radar_state.getLeadOne();
auto lead_two = radar_state.getLeadTwo();
if (lead_one.getStatus()) {
drawLead(painter, lead_one, s->scene.lead_vertices[0]);
}
if (lead_two.getStatus() && (std::abs(lead_one.getDRel() - lead_two.getDRel()) > 3.0)) {
drawLead(painter, lead_two, s->scene.lead_vertices[1]);
drawLaneLines(painter, s);

if (s->scene.longitudinal_control) {
auto lead_one = radar_state.getLeadOne();
auto lead_two = radar_state.getLeadTwo();
if (lead_one.getStatus()) {
drawLead(painter, lead_one, s->scene.lead_vertices[0]);
}
if (lead_two.getStatus() && (std::abs(lead_one.getDRel() - lead_two.getDRel()) > 3.0)) {
drawLead(painter, lead_two, s->scene.lead_vertices[1]);
}
}
}
}

// DMoji
if (!hideBottomIcons && (sm.rcv_frame("driverStateV2") > s->scene.started_frame)) {
update_dmonitoring(s, sm["driverStateV2"].getDriverStateV2(), dm_fade_state, rightHandDM);
drawDriverState(painter, s);
}
// DMoji
if (!hideBottomIcons && (sm.rcv_frame("driverStateV2") > s->scene.started_frame)) {
update_dmonitoring(s, sm["driverStateV2"].getDriverStateV2(), dm_fade_state, rightHandDM);
drawDriverState(painter, s);
}

drawHud(painter);
drawHud(painter);
}

double cur_draw_t = millis_since_boot();
double dt = cur_draw_t - prev_draw_t;
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/onroad.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class AnnotatedCameraWidget : public CameraWidget {
// FrogPilot variables
bool drivingPersonalitiesUIWheel;
int personalityProfile;
bool showDriverCamera;
QVector<std::pair<QPixmap, QString>> profile_data;

protected:
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/widgets/cameraview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void CameraWidget::updateFrameMat() {
if (active_stream_type == VISION_STREAM_DRIVER) {
if (stream_width > 0 && stream_height > 0) {
frame_mat = get_driver_view_transform(w, h, stream_width, stream_height);
frame_mat.v[0] *= -1.0;
}
} else {
// Project point at "infinity" to compute x and y offsets
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,14 @@ This may take up to a minute.</source>
<source>Enable the openpilot longitudinal control (alpha) toggle to allow Experimental mode.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,14 @@ Cela peut prendre jusqu&apos;à une minute.</translation>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,14 @@ This may take up to a minute.</source>
<source>Enable the openpilot longitudinal control (alpha) toggle to allow Experimental mode.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_th.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,14 @@ This may take up to a minute.</source>
3 bars = Relaxed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Driver Camera On Reverse</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Displays the driver camera when in reverse.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
7 changes: 7 additions & 0 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ static void update_state(UIState *s) {
if (sm.updated("carParams")) {
scene.longitudinal_control = sm["carParams"].getCarParams().getOpenpilotLongitudinalControl();
}
if (sm.updated("carState")) {
const auto carState = sm["carState"].getCarState();
if (scene.driver_camera) {
scene.show_driver_camera = carState.getGearShifter() == cereal::CarState::GearShifter::REVERSE;
}
}
if (sm.updated("wideRoadCameraState")) {
auto cam_state = sm["wideRoadCameraState"].getWideRoadCameraState();
float scale = (cam_state.getSensor() == cereal::FrameData::ImageSensor::AR0231) ? 6.0f : 1.0f;
Expand All @@ -218,6 +224,7 @@ void ui_update_params(UIState *s) {
// FrogPilot variables
UIScene &scene = s->scene;
scene.driving_personalities_ui_wheel = params.getBool("DrivingPersonalitiesUIWheel");
scene.driver_camera = params.getBool("DriverCamera");
}

void ui_live_update_params(UIState *s) {
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ typedef struct UIScene {
// FrogPilot variables
int personality_profile;
bool driving_personalities_ui_wheel;
bool driver_camera;
bool show_driver_camera;

} UIScene;

Expand Down

0 comments on commit a1e3c78

Please sign in to comment.