Skip to content

Commit

Permalink
November 22nd, 2024 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogAi committed Nov 22, 2024
1 parent 3f397ae commit 235a275
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 63 deletions.
1 change: 0 additions & 1 deletion common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ std::unordered_map<std::string, uint32_t> keys = {
{"RadarlessModels", PERSISTENT},
{"RadicalTurtleDrives", PERSISTENT | FROGPILOT_CONTROLS},
{"RadicalTurtleScore", PERSISTENT | FROGPILOT_CONTROLS},
{"RainbowPath", PERSISTENT | FROGPILOT_STORAGE | FROGPILOT_VISUALS},
{"RandomEvents", PERSISTENT | FROGPILOT_STORAGE | FROGPILOT_VISUALS},
{"RecertifiedHerbalistDrives", PERSISTENT | FROGPILOT_CONTROLS},
{"RecertifiedHerbalistScore", PERSISTENT | FROGPILOT_CONTROLS},
Expand Down
18 changes: 9 additions & 9 deletions selfdrive/car/hyundai/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def calculate_speed_limit(self, cp, cp_cam):
speed_limit_bus = cp if self.CP.flags & HyundaiFlags.CANFD_HDA2 else cp_cam
return speed_limit_bus.vl["CLUSTER_SPEED_LIMIT"]["SPEED_LIMIT_1"]
else:
speed_limit_nav = cp.vl["Navi_HU"]["SpeedLim_Nav_Clu"] if self.CP.flags & FrogPilotHyundaiFlags.NAV_MSG else 0
speed_limit_cam = cp_cam.vl["LKAS12"]["CF_Lkas_TsrSpeed_Display_Clu"] if self.CP.flags & FrogPilotHyundaiFlags.LKAS12 else 0
speed_limit_nav = cp.vl["Navi_HU"]["SpeedLim_Nav_Clu"] if self.CP.flags & HyundaiFlags.NAV_MSG else 0
speed_limit_cam = cp_cam.vl["LKAS12"]["CF_Lkas_TsrSpeed_Display_Clu"] if self.CP.flags & HyundaiFlags.LKAS12 else 0
return speed_limit_cam if speed_limit_cam not in (0, 255) else speed_limit_nav

def update(self, cp, cp_cam, frogpilot_toggles):
Expand Down Expand Up @@ -188,14 +188,14 @@ def update(self, cp, cp_cam, frogpilot_toggles):
# FrogPilot CarState functions
fp_ret.brakeLights = bool(cp.vl["TCS13"]["BrakeLight"])

if self.CP.flags & FrogPilotHyundaiFlags.LKAS12 or self.CP.flags & FrogPilotHyundaiFlags.NAV_MSG:
if self.CP.flags & HyundaiFlags.LKAS12 or self.CP.flags & HyundaiFlags.NAV_MSG:
fp_ret.dashboardSpeedLimit = self.calculate_speed_limit(cp, cp_cam) * speed_conv

self.prev_distance_button = self.distance_button
self.distance_button = self.cruise_buttons[-1] == Buttons.GAP_DIST

self.lkas_previously_enabled = self.lkas_enabled
if self.CP.flags & FrogPilotHyundaiFlags.CAN_LFA_BTN:
if self.CP.flags & HyundaiFlags.CAN_LFA_BTN:
self.lkas_enabled = cp.vl["BCM_PO_11"]["LFA_Pressed"]

return ret, fp_ret
Expand Down Expand Up @@ -287,7 +287,7 @@ def update_canfd(self, cp, cp_cam, frogpilot_toggles):
# FrogPilot CarState functions
fp_ret.brakeLights = bool(cp.vl["TCS"]["DriverBraking"])

if self.CP.flags & FrogPilotHyundaiFlags.NAV_MSG:
if self.CP.flags & HyundaiFlags.NAV_MSG:
fp_ret.dashboardSpeedLimit = self.calculate_speed_limit(cp, cp_cam) * speed_factor

self.prev_distance_button = self.distance_button
Expand Down Expand Up @@ -355,7 +355,7 @@ def get_can_parser(self, CP):
else:
messages.append(("LVR12", 100))

if CP.flags & FrogPilotHyundaiFlags.CAN_LFA_BTN:
if CP.flags & HyundaiFlags.CAN_LFA_BTN:
messages.append(("BCM_PO_11", 50))

messages += [
Expand All @@ -382,7 +382,7 @@ def get_cam_can_parser(CP):
if CP.flags & HyundaiFlags.USE_FCA.value:
messages.append(("FCA11", 50))

if CP.flags & FrogPilotHyundaiFlags.LKAS12:
if CP.flags & HyundaiFlags.LKAS12:
messages.append(("LKAS12", 10))

return CANParser(DBC[CP.carFingerprint]["pt"], messages, 2)
Expand Down Expand Up @@ -421,7 +421,7 @@ def get_can_parser_canfd(self, CP):
("SCC_CONTROL", 50),
]

if CP.flags & HyundaiFlags.CANFD_HDA2 and CP.flags & FrogPilotHyundaiFlags.NAV_MSG:
if CP.flags & HyundaiFlags.CANFD_HDA2 and CP.flags & HyundaiFlags.NAV_MSG:
messages.append(("CLUSTER_SPEED_LIMIT", 10))

return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus(CP).ECAN)
Expand All @@ -437,7 +437,7 @@ def get_cam_can_parser_canfd(CP):
("SCC_CONTROL", 50),
]

if not (CP.flags & HyundaiFlags.CANFD_HDA2) and CP.flags & FrogPilotHyundaiFlags.NAV_MSG:
if not (CP.flags & HyundaiFlags.CANFD_HDA2) and CP.flags & HyundaiFlags.NAV_MSG:
messages.append(("CLUSTER_SPEED_LIMIT", 10))

return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus(CP).CAM)
8 changes: 4 additions & 4 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp
ret.flags |= HyundaiFlags.USE_FCA.value

if 0x53E in fingerprint[2]:
ret.flags |= FrogPilotHyundaiFlags.LKAS12.value
ret.flags |= HyundaiFlags.LKAS12.value

ret.steerActuatorDelay = 0.1 # Default delay
ret.steerLimitTimer = 0.4
Expand Down Expand Up @@ -116,12 +116,12 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp
ret.enableBsm = 0x1e5 in fingerprint[CAN.ECAN]

if 0x1fa in fingerprint[CAN.ECAN]:
ret.flags |= FrogPilotHyundaiFlags.NAV_MSG.value
ret.flags |= HyundaiFlags.NAV_MSG.value
else:
ret.enableBsm = 0x58b in fingerprint[0]

if 0x544 in fingerprint[0]:
ret.flags |= FrogPilotHyundaiFlags.NAV_MSG.value
ret.flags |= HyundaiFlags.NAV_MSG.value

# *** panda safety config ***
if candidate in CANFD_CAR:
Expand Down Expand Up @@ -149,7 +149,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC

if 0x391 in fingerprint[0]:
ret.flags |= FrogPilotHyundaiFlags.CAN_LFA_BTN.value
ret.flags |= HyundaiFlags.CAN_LFA_BTN.value
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HYUNDAI_LFA_BTN

if ret.openpilotLongitudinalControl:
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class HyundaiFlags(IntFlag):

MIN_STEER_32_MPH = 2 ** 23

class FrogPilotHyundaiFlags(IntFlag):
CAN_LFA_BTN = 1
LKAS12 = 2
NAV_MSG = 2 ** 2
# FrogPilot HKG flags
CAN_LFA_BTN = 2 ** 24
LKAS12 = 2 ** 25
NAV_MSG = 2 ** 26

class Footnote(Enum):
CANFD = CarFootnote(
Expand Down
63 changes: 20 additions & 43 deletions selfdrive/ui/qt/onroad/annotated_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,6 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s, f
acceleration.push_back(acceleration_const[i]);
}

float v_ego = sm["carState"].getCarState().getVEgo();
const float hue_shift_speed = 0.5; // Adjust this value to control the speed of the rainbow scroll
static float hue_base = 0.0; // Base hue that changes over time
hue_base = fmod(hue_base + v_ego * hue_shift_speed, 360.0); // Update base hue to create scrolling effect

for (int i = 0; i < max_len; ++i) {
// Some points are out of frame
int track_idx = max_len - i - 1; // flip idx to start from bottom right
Expand All @@ -367,45 +362,27 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s, f
float lin_grad_point = (height() - scene.track_vertices[track_idx].y()) / height();
float acceleration_abs = fabs(acceleration[i]);

if (acceleration_abs < 0.25 && scene.rainbow_path) {
float saturation = util::map_val(acceleration_abs, 0.0f, 1.0f, 0.6f, 0.8f); // higher saturation when acceleration_abs is 0
float lightness = util::map_val(acceleration_abs, 0.0f, 1.0f, 0.7f, 0.5f);
float alpha = util::map_val(acceleration_abs, 0.0f, 1.0f, 0.5f, 0.8f);

float perspective_factor = lin_grad_point;
float rainbow_height = 0.1 + 0.4 * perspective_factor;

for (int j = 0; j <= 50; ++j) {
float color_position = static_cast<float>(j) / 50.0;
if (color_position >= lin_grad_point - rainbow_height / 2 && color_position <= lin_grad_point + rainbow_height / 2) {
float hue = fmod(hue_base + color_position * 360.0, 360.0);
QColor rainbow_color = QColor::fromHslF(hue / 360.0, saturation, lightness, alpha);
bg.setColorAt(color_position, rainbow_color);
}
}
// If acceleration is between -0.25 and 0.25, resort to the theme color
if (std::abs(acceleration[i]) < 0.25 && !useStockColors) {
QColor color = scene.path_color;
bg.setColorAt(0.0f, color);
color.setAlphaF(0.5f);
bg.setColorAt(0.5f, color);
color.setAlphaF(0.1f);
bg.setColorAt(1.0f, color);
} else {
// If acceleration is between -0.25 and 0.25, resort to the theme color
if (acceleration_abs < 0.25 && !useStockColors) {
QColor color = scene.path_color;
bg.setColorAt(0.0f, color);
color.setAlphaF(0.5f);
bg.setColorAt(0.5f, color);
color.setAlphaF(0.1f);
bg.setColorAt(1.0f, color);
} else {
// speed up: 120, slow down: 0
float path_hue = fmax(fmin(60 + acceleration[i] * 35, 120), 0);
// FIXME: painter.drawPolygon can be slow if hue is not rounded
path_hue = int(path_hue * 100 + 0.5) / 100;

float saturation = fmin(fabs(acceleration[i] * 1.5), 1);
float lightness = util::map_val(saturation, 0.0f, 1.0f, 0.95f, 0.62f); // lighter when grey
float alpha = util::map_val(lin_grad_point, 0.75f / 2.f, 0.75f, 0.4f, 0.0f); // matches previous alpha fade
bg.setColorAt(lin_grad_point, QColor::fromHslF(path_hue / 360., saturation, lightness, alpha));

// Skip a point, unless next is last
i += (i + 2) < max_len ? 1 : 0;
}
// speed up: 120, slow down: 0
float path_hue = fmax(fmin(60 + acceleration[i] * 35, 120), 0);
// FIXME: painter.drawPolygon can be slow if hue is not rounded
path_hue = int(path_hue * 100 + 0.5) / 100;

float saturation = fmin(fabs(acceleration[i] * 1.5), 1);
float lightness = util::map_val(saturation, 0.0f, 1.0f, 0.95f, 0.62f); // lighter when grey
float alpha = util::map_val(lin_grad_point, 0.75f / 2.f, 0.75f, 0.4f, 0.0f); // matches previous alpha fade
bg.setColorAt(lin_grad_point, QColor::fromHslF(path_hue / 360., saturation, lightness, alpha));

// Skip a point, unless next is last
i += (i + 2) < max_len ? 1 : 0;
}
}

Expand Down
1 change: 0 additions & 1 deletion selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ void ui_update_frogpilot_params(UIState *s) {
scene.pedals_on_ui = scene.frogpilot_toggles.value("pedals_on_ui").toBool();
scene.radarless_model = scene.frogpilot_toggles.value("radarless_model").toBool();
scene.random_events = scene.frogpilot_toggles.value("random_events").toBool();
scene.rainbow_path = scene.frogpilot_toggles.value("rainbow_path").toBool();
scene.road_edge_width = scene.frogpilot_toggles.value("road_edge_width").toDouble();
scene.road_name_ui = scene.frogpilot_toggles.value("road_name_ui").toBool();
scene.rotating_wheel = scene.frogpilot_toggles.value("rotating_wheel").toBool();
Expand Down
1 change: 0 additions & 1 deletion selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ typedef struct UIScene {
bool parked;
bool pedals_on_ui;
bool radarless_model;
bool rainbow_path;
bool random_events;
bool red_light;
bool reverse;
Expand Down

0 comments on commit 235a275

Please sign in to comment.