Skip to content

Commit

Permalink
Increase max speed by 5 for Toyota vehicles on short press
Browse files Browse the repository at this point in the history
Added function to increase the value of the max speed by 5 instead of 1 by taping the "Max" speed icon in the onroad UI.
  • Loading branch information
FrogAi committed Aug 20, 2023
1 parent d7e8ac1 commit a1cbffe
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ struct CarControl {
rightBlinker @16: Bool;

# FrogPilot CarControls
reverseCruise @18: Bool;

# Any car specific rate limits or quirks applied by
# the CarController are reflected in actuatorsOutput
Expand Down
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"RecordFront", PERSISTENT},
{"RecordFrontLock", PERSISTENT}, // for the internal fleet
{"ReplayControlsState", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"ReverseCruiseIncrease", PERSISTENT},
{"RoadEdgesWidth", PERSISTENT},
{"RotatingWheel", PERSISTENT},
{"ScreenBrightness", PERSISTENT},
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def update(self, CC, CS, now_nanos):
if pcm_cancel_cmd and self.CP.carFingerprint in UNSUPPORTED_DSU_CAR:
can_sends.append(create_acc_cancel_command(self.packer))
elif self.CP.openpilotLongitudinalControl:
can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type))
can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, CC.reverseCruise))
self.accel = pcm_accel_cmd
else:
can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type))
can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, CC.reverseCruise))

if self.frame % 2 == 0 and self.CP.enableGasInterceptor and self.CP.openpilotLongitudinalControl:
# send exactly zero if gas cmd is zero. Interceptor will send the max between read value and gas cmd.
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/toyota/toyotacan.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create_lta_steer_command(packer, steer_angle, steer_req, frame, setme_x64):
return packer.make_can_msg("STEERING_LTA", 0, values)


def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type):
def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type, reverse_cruise):
# TODO: find the exact canceling bit that does not create a chime
values = {
"ACCEL_CMD": accel,
Expand All @@ -37,7 +37,7 @@ def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_ty
"PERMIT_BRAKING": 1,
"RELEASE_STANDSTILL": not standstill_req,
"CANCEL_REQ": pcm_cancel,
"ALLOW_LONG_PRESS": 1,
"ALLOW_LONG_PRESS": 2 if reverse_cruise else 1,
}
return packer.make_can_msg("ACC_CONTROL", 0, values)

Expand Down
6 changes: 6 additions & 0 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, sm=None, pm=None, can_sock=None, CI=None):
# FrogPilot variables
frog_theme = self.params.get_bool("FrogTheme")
self.frog_sounds = frog_theme and self.params.get_bool("FrogSounds")
self.reverse_cruise_increase = self.params.get_bool("ReverseCruiseIncrease")

# detect sound card presence and ensure successful init
sounds_available = HARDWARE.get_sound_card_online()
Expand Down Expand Up @@ -591,6 +592,11 @@ def state_control(self, CS):
CC = car.CarControl.new_message()
CC.enabled = self.enabled

# Check the value of "reverse_cruise_increase" just in case the user changed its value mid drive
if long_plan.frogpilotTogglesUpdated:
self.reverse_cruise_increase = self.params.get_bool("ReverseCruiseIncrease")
CC.reverseCruise = self.reverse_cruise_increase

# Check which actuators can be enabled
standstill = CS.vEgo <= max(self.CP.minSteerSpeed, MIN_LATERAL_CONTROL_SPEED) or CS.standstill
CC.latActive = self.active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \
Expand Down
24 changes: 21 additions & 3 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,30 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
const int x_offset = scene.mute_dm ? 50 : 250;
bool rightHandDM = sm["driverMonitoringState"].getDriverMonitoringState().getIsRHD();

// Change cruise control increments button
const QRect maxSpeedRect(0, 0, 350, 350);
const bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()) && isToyotaCar;

// Hide speed button
const QRect speedRect(rect().center().x() - 175, 50, 350, 350);
const bool isSpeedClicked = speedRect.contains(e->pos());

// Check if the click was within the max speed area
if (isMaxSpeedClicked) {
const bool currentReverseCruiseIncrease = params.getBool("ReverseCruiseIncrease");
reverseCruiseIncrease = !currentReverseCruiseIncrease;
params.putBool("ReverseCruiseIncrease", reverseCruiseIncrease);
params_memory.putBool("FrogPilotTogglesUpdated", true);
propagateEvent = false;
// Check if the click was within the speed text area
if (isSpeedClicked) {
} else if (isSpeedClicked) {
const bool currentVisibility = params.getBool("HideSpeed");
speedHidden = !currentVisibility;
params.putBool("HideSpeed", speedHidden);
propagateEvent = false;
}

const bool clickedOnWidget = isSpeedClicked;
const bool clickedOnWidget = isMaxSpeedClicked || isSpeedClicked;

#ifdef ENABLE_MAPS
if (map != nullptr) {
Expand Down Expand Up @@ -333,6 +344,9 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
if (params.getBool("HideSpeed")) {
speedHidden = true;
}
if (params.getBool("ReverseCruiseIncrease")) {
reverseCruiseIncrease = true;
}

// FrogPilot images
engage_img = loadPixmap("../assets/img_chffr_wheel.png", {img_size, img_size});
Expand Down Expand Up @@ -452,7 +466,11 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
int bottom_radius = has_eu_speed_limit ? 100 : 32;

QRect set_speed_rect(QPoint(60 + (default_size.width() - set_speed_size.width()) / 2, 45), set_speed_size);
p.setPen(QPen(whiteColor(75), 6));
if (reverseCruiseIncrease) {
p.setPen(QPen(QColor(0, 150, 255), 6));
} else {
p.setPen(QPen(whiteColor(75), 6));
}
p.setBrush(blackColor(166));
drawRoundedRect(p, set_speed_rect, top_radius, top_radius, bottom_radius, bottom_radius);

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 @@ -14,6 +14,7 @@ const int img_size = (btn_size / 4) * 3;

// FrogPilot global variables
static bool map_open;
static bool reverseCruiseIncrease;
static bool speedHidden;


Expand Down

0 comments on commit a1cbffe

Please sign in to comment.