Skip to content

Commit

Permalink
November 10th, 2024 Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogAi committed Nov 10, 2024
1 parent ae98341 commit 07b6ac1
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 431 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FrogPilot is a fully open-sourced fork of openpilot, featuring clear and concise
------
FrogPilot was last updated on:

**November 1st, 2024**
**November 10th, 2024**

Features
------
Expand Down
17 changes: 9 additions & 8 deletions selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ def __init__(self, CI=None):

num_pandas = len(messaging.recv_one_retry(self.sm.sock['pandaStates']).pandaStates)
disable_openpilot_long = self.params.get_bool("DisableOpenpilotLongitudinal")
experimental_long_allowed = not disable_openpilot_long and self.params.get_bool("ExperimentalLongitudinalEnabled")
experimental_long_allowed = self.params.get_bool("ExperimentalLongitudinalEnabled")
self.CI, self.CP = get_car(self.can_sock, self.pm.sock['sendcan'], disable_openpilot_long, experimental_long_allowed, self.params, num_pandas)
else:
self.CI, self.CP = CI, CI.CP

# set alternative experiences from parameters
self.disengage_on_accelerator = self.params.get_bool("DisengageOnAccelerator")
self.CP.alternativeExperience = 0
if not self.disengage_on_accelerator:
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS

openpilot_enabled_toggle = self.params.get_bool("OpenpilotEnabledToggle")

controller_available = self.CI.CC is not None and openpilot_enabled_toggle and not self.CP.dashcamOnly
Expand All @@ -77,16 +83,11 @@ def __init__(self, CI=None):
# FrogPilot variables
self.frogpilot_toggles = get_frogpilot_toggles(True)

# set alternative experiences from parameters
self.disengage_on_accelerator = self.params.get_bool("DisengageOnAccelerator")
self.CP.alternativeExperience = 0
if not self.disengage_on_accelerator:
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS

if self.params.get_bool("AlwaysOnLateral"):
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.ALWAYS_ON_LATERAL
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS

if self.params.get_int("AccelerationProfile") == 3:
if self.frogpilot_toggles.acceleration_profile == 3:
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX

# Write CarParams for controls and radard
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from openpilot.system.hardware import HARDWARE

from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_acceleration import get_max_allowed_accel
from openpilot.selfdrive.frogpilot.frogpilot_variables import CRUISING_SPEED, NON_DRIVING_GEARS, get_frogpilot_toggles
from openpilot.selfdrive.frogpilot.frogpilot_variables import NON_DRIVING_GEARS, get_frogpilot_toggles

SOFT_DISABLE_TIME = 3 # seconds
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
Expand Down Expand Up @@ -569,7 +569,7 @@ def state_control(self, CS):
# Update VehicleModel
lp = self.sm['liveParameters']
x = max(lp.stiffnessFactor, 0.1)
sr = max(self.frogpilot_toggles.steer_ratio, 0.1) if self.frogpilot_toggles.use_custom_steer_ratio else max(lp.steerRatio, 0.1)
sr = max(self.frogpilot_toggles.steer_ratio if self.frogpilot_toggles.use_custom_steer_ratio else lp.steerRatio, 0.1)
self.VM.update_params(x, sr)

# Update Torque Params
Expand Down Expand Up @@ -624,7 +624,7 @@ def state_control(self, CS):
t_since_plan = (self.sm.frame - self.sm.recv_frame['longitudinalPlan']) * DT_CTRL
actuators.accel = self.LoC.update_old_long(CC.longActive, CS, long_plan, pid_accel_limits, t_since_plan)
else:
actuators.accel = self.LoC.update(CC.longActive, CS, long_plan.aTarget, long_plan.shouldStop or self.sm['frogpilotPlan'].forcingStopLength <= 0, pid_accel_limits)
actuators.accel = self.LoC.update(CC.longActive, CS, long_plan.aTarget, long_plan.shouldStop or self.sm['frogpilotPlan'].forcingStopLength == 0, pid_accel_limits)

if len(long_plan.speeds):
actuators.speed = long_plan.speeds[-1]
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/controls/lib/desire_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
# FrogPilot variables
self.lane_change_completed = False

self.lane_change_wait_timer = 0.0
self.lane_change_wait_timer = 0

self.turn_direction = TurnDirection.none

Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/lib/drive_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from cereal import car, log
from openpilot.common.conversions import Conversions as CV
from openpilot.common.numpy_fast import clip, interp
from openpilot.common.params import Params
from openpilot.common.realtime import DT_CTRL

# WARNING: this value was determined based on the model's training distribution,
Expand Down
1 change: 1 addition & 0 deletions selfdrive/controls/lib/latcontrol_torque.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import deque

import math
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/controls/lib/longcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def long_control_state_trans_old_long(CP, active, long_control_state, v_ego, v_t
class LongControl:
def __init__(self, CP):
self.CP = CP
self.long_control_state = LongCtrlState.off # initialized to off
self.long_control_state = LongCtrlState.off
self.pid = PIDController((CP.longitudinalTuning.kpBP, CP.longitudinalTuning.kpV),
(CP.longitudinalTuning.kiBP, CP.longitudinalTuning.kiV),
k_f=CP.longitudinalTuning.kf, rate=1 / DT_CTRL)
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/controls/plannerd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def plannerd_thread():
longitudinal_planner = LongitudinalPlanner(CP)
pm = messaging.PubMaster(['longitudinalPlan', 'uiPlan'])
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'liveParameters', 'radarState', 'modelV2',
'frogpilotCarControl', 'frogpilotCarState', 'frogpilotPlan'],
'frogpilotCarState', 'frogpilotPlan'],
poll='modelV2', ignore_avg_freq=['radarState'])

# FrogPilot variables
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/frogpilot/assets/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def fetch_all_model_sizes(repo_url):
elif "gitlab" in repo_url:
api_url = f"https://gitlab.com/api/v4/projects/{urllib.parse.quote_plus(project_path)}/repository/tree?ref={branch}"
else:
raise ValueError(f"Unsupported repository URL format: {repo_url}. Supported formats are GitHub and GitLab URLs.")
return {}

try:
response = requests.get(api_url)
Expand All @@ -72,8 +72,8 @@ def fetch_all_model_sizes(repo_url):
return model_sizes
else:
return {file['name'].replace('.thneed', ''): file['size'] for file in thneed_files if 'size' in file}

except:
except Exception as e:
raise ConnectionError(f"Failed to fetch model sizes from {'GitHub' if 'github' in repo_url else 'GitLab'}: {e}")
return {}

@staticmethod
Expand Down
10 changes: 4 additions & 6 deletions selfdrive/frogpilot/frogpilot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def frogpilot_boot_functions(build_metadata, params, params_storage):

def setup_frogpilot(build_metadata, params):
remount_persist = ["sudo", "mount", "-o", "remount,rw", "/persist"]
if not run_cmd(remount_persist, "Successfully remounted /persist as read-write.", "Failed to remount /persist."):
HARDWARE.reboot()
run_cmd(remount_persist, "Successfully remounted /persist as read-write.", "Failed to remount /persist.")

os.makedirs("/persist/params", exist_ok=True)
os.makedirs(MODELS_PATH, exist_ok=True)
Expand Down Expand Up @@ -248,14 +247,14 @@ def setup_frogpilot(build_metadata, params):
copy_if_exists(frog_steering_wheel_source, frog_steering_wheel_destination, single_file_name="frog.png")

remount_root = ["sudo", "mount", "-o", "remount,rw", "/"]
if not run_cmd(remount_root, "File system remounted as read-write.", "Failed to remount file system."):
HARDWARE.reboot()
run_cmd(remount_root, "File system remounted as read-write.", "Failed to remount file system.")

boot_logo_location = "/usr/comma/bg.jpg"
boot_logo_save_location = os.path.join(BASEDIR, "selfdrive", "frogpilot", "assets", "other_images", "original_bg.jpg")
frogpilot_boot_logo = os.path.join(BASEDIR, "selfdrive", "frogpilot", "assets", "other_images", "frogpilot_boot_logo.png")

if not filecmp.cmp(frogpilot_boot_logo, boot_logo_location, shallow=False):
run_cmd(["sudo", "cp", boot_logo_location, boot_logo_save_location], "Successfully backed up original bg.jpg.", "Failed to back up original boot logo.")
run_cmd(["sudo", "cp", frogpilot_boot_logo, boot_logo_location], "Successfully replaced bg.jpg with frogpilot_boot_logo.png.", "Failed to replace boot logo.")

if build_metadata.channel == "FrogPilot-Development":
Expand All @@ -267,7 +266,6 @@ def uninstall_frogpilot():
boot_logo_restore_location = os.path.join(BASEDIR, "selfdrive", "frogpilot", "assets", "other_images", "original_bg.jpg")

copy_cmd = ["sudo", "cp", boot_logo_restore_location, boot_logo_location]
if not run_cmd(copy_cmd, "Successfully restored the original boot logo.", "Failed to restore the original boot logo."):
HARDWARE.reboot()
run_cmd(copy_cmd, "Successfully restored the original boot logo.", "Failed to restore the original boot logo.")

HARDWARE.uninstall()
23 changes: 10 additions & 13 deletions selfdrive/frogpilot/frogpilot_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_road_curvature(modelData, v_ego):
orientation_rate = np.abs(modelData.orientationRate.z)
velocity = modelData.velocity.x
max_pred_lat_acc = np.amax(orientation_rate * velocity)
return max_pred_lat_acc / v_ego**2
return max_pred_lat_acc / max(v_ego, 1)**2

def copy_if_exists(source, destination, single_file_name=None):
if not os.path.exists(source):
Expand Down Expand Up @@ -71,18 +71,15 @@ def is_url_pingable(url, timeout=5):
print(f"Failed to ping {url}: {e}")
return False

def run_cmd(cmd, success_message, fail_message, retries=5, delay=1):
for attempt in range(retries):
try:
subprocess.check_call(cmd)
print(success_message)
return True
except Exception as e:
print(f"Unexpected error occurred (attempt {attempt + 1} of {retries}): {e}")
time.sleep(delay)

print(fail_message)
return False
def run_cmd(cmd, success_message, fail_message):
try:
subprocess.check_call(cmd)
print(success_message)
return True
except Exception as e:
print(f"Unexpected error occurred: {e}")
print(fail_message)
return False

class MovingAverageCalculator:
def __init__(self):
Expand Down
Loading

0 comments on commit 07b6ac1

Please sign in to comment.