Skip to content

Commit

Permalink
Merge branch 'commaai:master' into PA-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS authored Aug 11, 2023
2 parents 2cac5ba + 2a38f38 commit f6533d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 41 deletions.
4 changes: 2 additions & 2 deletions selfdrive/car/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ def apply_std_steer_angle_limits(apply_angle, apply_angle_last, v_ego, LIMITS):
return clip(apply_angle, apply_angle_last - angle_rate_lim, apply_angle_last + angle_rate_lim)


def common_fault_avoidance(measured_value: float, max_value: float, request: bool, above_limit_frames: int,
def common_fault_avoidance(fault_condition: bool, request: bool, above_limit_frames: int,
max_above_limit_frames: int, max_mismatching_frames: int = 1):
"""
Several cars have the ability to work around their EPS limits by cutting the
request bit of their LKAS message after a certain number of frames above the limit.
"""

# Count up to max_above_limit_frames, at which point we need to cut the request for above_limit_frames to avoid a fault
if request and abs(measured_value) >= max_value:
if request and fault_condition:
above_limit_frames += 1
else:
above_limit_frames = 0
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update(self, CC, CS, now_nanos):
apply_steer = apply_driver_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.params)

# >90 degree steering fault prevention
self.angle_limit_counter, apply_steer_req = common_fault_avoidance(CS.out.steeringAngleDeg, MAX_ANGLE, CC.latActive,
self.angle_limit_counter, apply_steer_req = common_fault_avoidance(abs(CS.out.steeringAngleDeg) >= MAX_ANGLE, CC.latActive,
self.angle_limit_counter, MAX_ANGLE_FRAMES,
MAX_ANGLE_CONSECUTIVE_FRAMES)

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update(self, CC, CS, now_nanos):
apply_steer = apply_meas_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorqueEps, self.params)

# >100 degree/sec steering fault prevention
self.steer_rate_counter, apply_steer_req = common_fault_avoidance(CS.out.steeringRateDeg, MAX_STEER_RATE, CC.latActive,
self.steer_rate_counter, apply_steer_req = common_fault_avoidance(abs(CS.out.steeringRateDeg) >= MAX_STEER_RATE, CC.latActive,
self.steer_rate_counter, MAX_STEER_RATE_FRAMES)

if not CC.latActive:
Expand Down
57 changes: 21 additions & 36 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
#include "selfdrive/ui/qt/maps/map_panel.h"
#endif

static void drawIcon(QPainter &p, const QPoint &center, const QPixmap &img, const QBrush &bg, float opacity) {
p.setRenderHint(QPainter::Antialiasing);
p.setOpacity(1.0); // bg dictates opacity of ellipse
p.setPen(Qt::NoPen);
p.setBrush(bg);
p.drawEllipse(center, btn_size / 2, btn_size / 2);
p.setOpacity(opacity);
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
p.setOpacity(1.0);
}

OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setMargin(UI_BORDER_SIZE);
Expand Down Expand Up @@ -249,17 +260,8 @@ void ExperimentalButton::updateState(const UIState &s) {

void ExperimentalButton::paintEvent(QPaintEvent *event) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);

QPoint center(btn_size / 2, btn_size / 2);
QPixmap img = experimental_mode ? experimental_img : engage_img;

p.setOpacity(1.0);
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 166));
p.drawEllipse(center, btn_size / 2, btn_size / 2);
p.setOpacity((isDown() || !engageable) ? 0.6 : 1.0);
p.drawPixmap((btn_size - img_size) / 2, (btn_size - img_size) / 2, img);
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
}


Expand All @@ -275,16 +277,7 @@ MapSettingsButton::MapSettingsButton(QWidget *parent) : QPushButton(parent) {

void MapSettingsButton::paintEvent(QPaintEvent *event) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);

QPoint center(btn_size / 2, btn_size / 2);

p.setOpacity(1.0);
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 166));
p.drawEllipse(center, btn_size / 2, btn_size / 2);
p.setOpacity(isDown() ? 0.6 : 1.0);
p.drawPixmap((btn_size - img_size) / 2, (btn_size - img_size) / 2, settings_img);
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
}


Expand Down Expand Up @@ -323,6 +316,8 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
const bool nav_alive = sm.alive("navInstruction") && sm["navInstruction"].getValid();

const auto cs = sm["controlsState"].getControlsState();
const auto car_state = sm["carState"].getCarState();
const auto nav_instruction = sm["navInstruction"].getNavInstruction();

// Handle older routes where vCruiseCluster is not set
float v_cruise = cs.getVCruiseCluster() == 0.0 ? cs.getVCruise() : cs.getVCruiseCluster();
Expand All @@ -334,17 +329,17 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {

// Handle older routes where vEgoCluster is not set
float v_ego;
if (sm["carState"].getCarState().getVEgoCluster() == 0.0 && !v_ego_cluster_seen) {
v_ego = sm["carState"].getCarState().getVEgo();
if (car_state.getVEgoCluster() == 0.0 && !v_ego_cluster_seen) {
v_ego = car_state.getVEgo();
} else {
v_ego = sm["carState"].getCarState().getVEgoCluster();
v_ego = car_state.getVEgoCluster();
v_ego_cluster_seen = true;
}
float cur_speed = cs_alive ? std::max<float>(0.0, v_ego) : 0.0;
cur_speed *= s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH;

auto speed_limit_sign = sm["navInstruction"].getNavInstruction().getSpeedLimitSign();
float speed_limit = nav_alive ? sm["navInstruction"].getNavInstruction().getSpeedLimit() : 0.0;
auto speed_limit_sign = nav_instruction.getSpeedLimitSign();
float speed_limit = nav_alive ? nav_instruction.getSpeedLimit() : 0.0;
speed_limit *= (s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH);

setProperty("speedLimit", speed_limit);
Expand Down Expand Up @@ -498,16 +493,6 @@ void AnnotatedCameraWidget::drawText(QPainter &p, int x, int y, const QString &t
p.drawText(real_rect.x(), real_rect.bottom(), text);
}

void AnnotatedCameraWidget::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
p.setOpacity(1.0); // bg dictates opacity of ellipse
p.setPen(Qt::NoPen);
p.setBrush(bg);
p.drawEllipse(x - btn_size / 2, y - btn_size / 2, btn_size, btn_size);
p.setOpacity(opacity);
p.drawPixmap(x - img.size().width() / 2, y - img.size().height() / 2, img);
p.setOpacity(1.0);
}

void AnnotatedCameraWidget::initializeGL() {
CameraWidget::initializeGL();
qInfo() << "OpenGL version:" << QString((const char*)glGetString(GL_VERSION));
Expand Down Expand Up @@ -606,7 +591,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s)
int x = rightHandDM ? width() - offset : offset;
int y = height() - offset;
float opacity = dmActive ? 0.65 : 0.2;
drawIcon(painter, x, y, dm_img, blackColor(70), opacity);
drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity);

// face
QPointF face_kpts_draw[std::size(default_face_kpts_3d)];
Expand Down
1 change: 0 additions & 1 deletion selfdrive/ui/qt/onroad.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class AnnotatedCameraWidget : public CameraWidget {
MapSettingsButton *map_settings_btn;

private:
void drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity);
void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255);

// FrogPilot widgets
Expand Down

0 comments on commit f6533d6

Please sign in to comment.