mirror of https://github.com/commaai/panda.git
Ford: check second speed for mismatches (#1358)
* Add second speed
* 2.5 m/s is 9 kph, 4 kph is the max in the field
* add quality signal
* qf signal name
* comment
* checksum matches except it goes to zero when turning the car off despite counter still active
* update comments
* now test it
* spacing
* Update board/safety/safety_ford.h
* zzzz
* not needed
* whoops
* test vehicle state mismatch
* add to safety_helpers
* probably misra
* we might want to check it in both speed signals in case one doesn't exist on a car
* Revert "we might want to check it in both speed signals in case one doesn't exist on a car"
This reverts commit 3338931409
.
* fix formatting
* 2 m/s (7 kph)
* set controls_allowed directly like other safety models
remove vehicle_state_mismatch
* obv
This commit is contained in:
parent
5c21b14049
commit
f444f1554f
|
@ -123,6 +123,7 @@ static bool ford_get_quality_flag_valid(CANPacket_t *to_push) {
|
|||
#define INACTIVE_CURVATURE_RATE 4096U
|
||||
#define INACTIVE_PATH_OFFSET 512U
|
||||
#define INACTIVE_PATH_ANGLE 1000U
|
||||
#define FORD_MAX_SPEED_DELTA 2.0 // m/s
|
||||
|
||||
static bool ford_lkas_msg_check(int addr) {
|
||||
return (addr == MSG_ACCDATA_3)
|
||||
|
@ -150,6 +151,15 @@ static int ford_rx_hook(CANPacket_t *to_push) {
|
|||
vehicle_speed = ((GET_BYTE(to_push, 0) << 8) | GET_BYTE(to_push, 1)) * 0.01 / 3.6;
|
||||
}
|
||||
|
||||
if (addr == MSG_EngVehicleSpThrottle2) {
|
||||
// Disable controls if speeds from ABS and PCM ECUs are too far apart.
|
||||
// Signal: Veh_V_ActlEng
|
||||
float filtered_pcm_speed = ((GET_BYTE(to_push, 6) << 8) | GET_BYTE(to_push, 7)) * 0.01 / 3.6;
|
||||
if (ABS(filtered_pcm_speed - vehicle_speed) > FORD_MAX_SPEED_DELTA) {
|
||||
controls_allowed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Update gas pedal
|
||||
if (addr == MSG_EngVehicleSpThrottle) {
|
||||
// Pedal position: (0.1 * val) in percent
|
||||
|
|
|
@ -68,6 +68,8 @@ class TestFordSafety(common.PandaSafetyTest):
|
|||
FWD_BLACKLISTED_ADDRS = {2: [MSG_ACCDATA_3, MSG_Lane_Assist_Data1, MSG_LateralMotionControl, MSG_IPMA_Data]}
|
||||
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
||||
|
||||
MAX_SPEED_DELTA = 2.0 # m/s
|
||||
|
||||
cnt_speed = 0
|
||||
cnt_speed_2 = 0
|
||||
cnt_yaw_rate = 0
|
||||
|
@ -179,6 +181,19 @@ class TestFordSafety(common.PandaSafetyTest):
|
|||
self.assertFalse(self._rx(to_push))
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
|
||||
def test_rx_hook_speed_mismatch(self):
|
||||
# Ford relies on speed for driver curvature limiting, so it checks two sources
|
||||
for speed in np.arange(0, 40, 1):
|
||||
for speed_delta in np.arange(-5, 5, 0.1):
|
||||
speed_2 = round(max(speed + speed_delta, 0), 1)
|
||||
# Set controls allowed in between rx since first message can reset it
|
||||
self._rx(self._speed_msg(speed))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self._rx(self._speed_msg_2(speed_2))
|
||||
|
||||
within_delta = abs(speed - speed_2) <= self.MAX_SPEED_DELTA
|
||||
self.assertEqual(self.safety.get_controls_allowed(), within_delta)
|
||||
|
||||
def test_steer_allowed(self):
|
||||
path_offsets = np.arange(-5.12, 5.11, 1).round()
|
||||
path_angles = np.arange(-0.5, 0.5235, 0.1).round(1)
|
||||
|
|
Loading…
Reference in New Issue