Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got rid of openpilot.common.numpy_fast as per https://github.com/commaai/openpilot/issues/34331 #1626

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opendbc/car/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from opendbc.car import structs
from opendbc.car.can_definitions import CanData
from opendbc.car.docs_definitions import CarDocs, ExtraCarDocs
from opendbc.car.common.numpy_fast import clip, interp
from numpy import clip, interp
Sammohana marked this conversation as resolved.
Show resolved Hide resolved

# set up logging
carlog = logging.getLogger('carlog')
Expand Down
22 changes: 0 additions & 22 deletions opendbc/car/common/numpy_fast.py

This file was deleted.

15 changes: 6 additions & 9 deletions opendbc/car/common/pid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import numpy as np
from numbers import Number

from opendbc.car.common.numpy_fast import clip, interp


class PIDController:
def __init__(self, k_p, k_i, k_f=0., k_d=0., pos_limit=1e308, neg_limit=-1e308, rate=100):
self._k_p = k_p
Expand All @@ -28,15 +25,15 @@ def __init__(self, k_p, k_i, k_f=0., k_d=0., pos_limit=1e308, neg_limit=-1e308,

@property
def k_p(self):
return interp(self.speed, self._k_p[0], self._k_p[1])
return np.interp(self.speed, self._k_p[0], self._k_p[1])

@property
def k_i(self):
return interp(self.speed, self._k_i[0], self._k_i[1])
return np.interp(self.speed, self._k_i[0], self._k_i[1])

@property
def k_d(self):
return interp(self.speed, self._k_d[0], self._k_d[1])
return np.interp(self.speed, self._k_d[0], self._k_d[1])

@property
def error_integral(self):
Expand Down Expand Up @@ -64,10 +61,10 @@ def update(self, error, error_rate=0.0, speed=0.0, override=False, feedforward=0

# Clip i to prevent exceeding control limits
control_no_i = self.p + self.d + self.f
control_no_i = clip(control_no_i, self.neg_limit, self.pos_limit)
self.i = clip(self.i, self.neg_limit - control_no_i, self.pos_limit - control_no_i)
control_no_i = np.clip(control_no_i, self.neg_limit, self.pos_limit)
self.i = np.clip(self.i, self.neg_limit - control_no_i, self.pos_limit - control_no_i)

control = self.p + self.i + self.d + self.f

self.control = clip(control, self.neg_limit, self.pos_limit)
self.control = np.clip(control, self.neg_limit, self.pos_limit)
return self.control
2 changes: 1 addition & 1 deletion opendbc/car/ford/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opendbc.car import ACCELERATION_DUE_TO_GRAVITY, Bus, DT_CTRL, apply_std_steer_angle_limits, structs
from opendbc.car.ford import fordcan
from opendbc.car.ford.values import CarControllerParams, FordFlags
from opendbc.car.common.numpy_fast import clip, interp
from numpy import clip, interp
from opendbc.car.interfaces import CarControllerBase, V_CRUISE_MAX

LongCtrlState = structs.CarControl.Actuators.LongControlState
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/ford/interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from panda import Panda
from opendbc.car.common.numpy_fast import interp
from numpy import interp
from opendbc.car import Bus, get_safety_config, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.ford.fordcan import CanBus
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opendbc.car.gm import gmcan
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.gm.values import DBC, CanBus, CarControllerParams, CruiseButtons
from opendbc.car.common.numpy_fast import interp
from numpy import interp
from opendbc.car.interfaces import CarControllerBase

VisualAlert = structs.CarControl.HUDControl.VisualAlert
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/gm/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opendbc.can.parser import CANParser
from opendbc.car import Bus, create_button_events, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import mean
from numpy import mean
from opendbc.car.interfaces import CarStateBase
from opendbc.car.gm.values import DBC, AccState, CruiseButtons, STEER_THRESHOLD, SDGM_CAR, ALT_ACCS

Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from opendbc.can.packer import CANPacker
from opendbc.car import Bus, DT_CTRL, rate_limit, make_tester_present_msg, structs
from opendbc.car.common.numpy_fast import clip, interp
from numpy import clip, interp
from opendbc.car.honda import hondacan
from opendbc.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams
from opendbc.car.interfaces import CarControllerBase
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/honda/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from opendbc.can.parser import CANParser
from opendbc.car import Bus, create_button_events, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import interp
from numpy import interp
from opendbc.car.honda.hondacan import CanBus, get_cruise_speed_conversion
from opendbc.car.honda.values import CAR, DBC, STEER_THRESHOLD, HONDA_BOSCH, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS, \
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from panda import Panda
from opendbc.car import get_safety_config, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import interp
from numpy import interp
from opendbc.car.honda.hondacan import CanBus
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HONDA_BOSCH, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, DT_CTRL, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import clip
from numpy import clip
from opendbc.car.hyundai import hyundaicanfd, hyundaican
from opendbc.car.hyundai.carstate import CarState
from opendbc.car.hyundai.hyundaicanfd import CanBus
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/hyundai/hyundaicanfd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from opendbc.car import CanBusBase
from opendbc.car.common.numpy_fast import clip
from numpy import clip
from opendbc.car.hyundai.values import HyundaiFlags


Expand Down
3 changes: 1 addition & 2 deletions opendbc/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from opendbc.car.common.basedir import BASEDIR
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.simple_kalman import KF1D, get_kalman_gain
from opendbc.car.common.numpy_fast import clip
from opendbc.car.values import PLATFORMS
from opendbc.can.parser import CANParser

Expand Down Expand Up @@ -320,7 +319,7 @@ def update_blinker_from_lamp(self, blinker_time: int, left_blinker_lamp: bool, r
def update_steering_pressed(self, steering_pressed, steering_pressed_min_count):
"""Applies filtering on steering pressed for noisy driver torque signals."""
self.steering_pressed_cnt += 1 if steering_pressed else -1
self.steering_pressed_cnt = clip(self.steering_pressed_cnt, 0, steering_pressed_min_count * 2)
self.steering_pressed_cnt = np.clip(self.steering_pressed_cnt, 0, steering_pressed_min_count * 2)
return self.steering_pressed_cnt > steering_pressed_min_count

def update_blinker_from_stalk(self, blinker_time: int, left_blinker_stalk: bool, right_blinker_stalk: bool):
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/nissan/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from opendbc.can.packer import CANPacker
from opendbc.car.common.numpy_fast import clip
from numpy import clip
from opendbc.car import Bus, apply_std_steer_angle_limits, structs
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.nissan import nissancan
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/subaru/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg
from opendbc.car.common.numpy_fast import clip, interp
from numpy import clip, interp
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.subaru import subarucan
from opendbc.car.subaru.values import DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/tesla/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from opendbc.car.common.numpy_fast import clip
from numpy import clip
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, apply_std_steer_angle_limits
from opendbc.car.interfaces import CarControllerBase
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
make_tester_present_msg, rate_limit, structs, ACCELERATION_DUE_TO_GRAVITY, DT_CTRL
from opendbc.car.can_definitions import CanData
from opendbc.car.common.filter_simple import FirstOrderFilter
from opendbc.car.common.numpy_fast import clip, interp
from numpy import clip, interp
from opendbc.car.common.pid import PIDController
from opendbc.car.secoc import add_mac, build_sync_mac
from opendbc.car.interfaces import CarControllerBase
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from opendbc.car import Bus, DT_CTRL, create_button_events, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.filter_simple import FirstOrderFilter
from opendbc.car.common.numpy_fast import mean
from numpy import mean
from opendbc.car.interfaces import CarStateBase
from opendbc.car.toyota.values import ToyotaFlags, CAR, DBC, STEER_THRESHOLD, NO_STOP_TIMER_CAR, \
TSS2_CAR, RADAR_ACC_CAR, EPS_SCALE, UNSUPPORTED_DSU_CAR
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/volkswagen/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, DT_CTRL, apply_driver_steer_torque_limits, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import clip
from numpy import clip
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.volkswagen import mqbcan, pqcan
from opendbc.car.volkswagen.values import CANBUS, CarControllerParams, VolkswagenFlags
Expand Down
Loading