From 33daa313018fb4b714841bf46b4d9322c9539dc2 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 26 Jun 2024 21:27:10 -0700 Subject: [PATCH] GM torque control: robust sig function (#32847) tricky old-commit-hash: b7695c00e87819dd6aac49cfec78e438dfc15d16 --- selfdrive/car/gm/interface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 5ea2b19891..d088050482 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -53,7 +53,12 @@ class CarInterface(CarInterfaceBase): friction = get_friction(lateral_accel_error, lateral_accel_deadzone, FRICTION_THRESHOLD, torque_params, friction_compensation) def sig(val): - return 1 / (1 + exp(-val)) - 0.5 + # https://timvieira.github.io/blog/post/2014/02/11/exp-normalize-trick + if val >= 0: + return 1 / (1 + exp(-val)) - 0.5 + else: + z = exp(val) + return z / (1 + z) - 0.5 # The "lat_accel vs torque" relationship is assumed to be the sum of "sigmoid + linear" curves # An important thing to consider is that the slope at 0 should be > 0 (ideally >1)