44from opendbc .car .lateral import apply_meas_steer_torque_limits , apply_std_steer_angle_limits , common_fault_avoidance
55from opendbc .car .can_definitions import CanData
66from opendbc .car .carlog import carlog
7- from opendbc .car .common .filter_simple import FirstOrderFilter
7+ from opendbc .car .common .filter_simple import FirstOrderFilter , HighPassFilter
88from opendbc .car .common .pid import PIDController
99from opendbc .car .secoc import add_mac , build_sync_mac
1010from opendbc .car .interfaces import CarControllerBase
@@ -65,8 +65,8 @@ def __init__(self, dbc_names, CP):
6565 # *** start long control state ***
6666 self .long_pid = get_long_tune (self .CP , self .params )
6767 self .aego = FirstOrderFilter (0.0 , 0.25 , DT_CTRL * 3 )
68- self .pitch = FirstOrderFilter (0 , 0.25 , DT_CTRL )
69- self .pitch_slow = FirstOrderFilter ( 0 , 1.5 , DT_CTRL )
68+ self .pitch = FirstOrderFilter (0 , 0.5 , DT_CTRL )
69+ self .pitch_hp = HighPassFilter ( 0.0 , 0.25 , 1.5 , DT_CTRL )
7070
7171 self .accel = 0
7272 self .prev_accel = 0
@@ -76,6 +76,7 @@ def __init__(self, dbc_names, CP):
7676
7777 self .secoc_lka_message_counter = 0
7878 self .secoc_lta_message_counter = 0
79+ self .secoc_acc_message_counter = 0
7980 self .secoc_prev_reset_counter = 0
8081
8182 def update (self , CC , CS , now_nanos ):
@@ -87,7 +88,7 @@ def update(self, CC, CS, now_nanos):
8788
8889 if len (CC .orientationNED ) == 3 :
8990 self .pitch .update (CC .orientationNED [1 ])
90- self .pitch_slow .update (CC .orientationNED [1 ])
91+ self .pitch_hp .update (CC .orientationNED [1 ])
9192
9293 # *** control msgs ***
9394 can_sends = []
@@ -97,6 +98,7 @@ def update(self, CC, CS, now_nanos):
9798 if CS .secoc_synchronization ['RESET_CNT' ] != self .secoc_prev_reset_counter :
9899 self .secoc_lka_message_counter = 0
99100 self .secoc_lta_message_counter = 0
101+ self .secoc_acc_message_counter = 0
100102 self .secoc_prev_reset_counter = CS .secoc_synchronization ['RESET_CNT' ]
101103
102104 expected_mac = build_sync_mac (self .secoc_key , int (CS .secoc_synchronization ['TRIP_CNT' ]), int (CS .secoc_synchronization ['RESET_CNT' ]))
@@ -228,8 +230,7 @@ def update(self, CC, CS, now_nanos):
228230 if not stopping :
229231 # Toyota's PCM slowly responds to changes in pitch. On change, we amplify our
230232 # acceleration request to compensate for the undershoot and following overshoot
231- high_pass_pitch = self .pitch .x - self .pitch_slow .x
232- pitch_compensation = float (np .clip (math .sin (high_pass_pitch ) * ACCELERATION_DUE_TO_GRAVITY ,
233+ pitch_compensation = float (np .clip (math .sin (self .pitch_hp .x ) * ACCELERATION_DUE_TO_GRAVITY ,
233234 - MAX_PITCH_COMPENSATION , MAX_PITCH_COMPENSATION ))
234235 pcm_accel_cmd += pitch_compensation
235236
@@ -250,8 +251,19 @@ def update(self, CC, CS, now_nanos):
250251
251252 pcm_accel_cmd = float (np .clip (pcm_accel_cmd , self .params .ACCEL_MIN , self .params .ACCEL_MAX ))
252253
253- can_sends .append (toyotacan .create_accel_command (self .packer , pcm_accel_cmd , pcm_cancel_cmd , self .permit_braking , self .standstill_req , lead ,
254+ main_accel_cmd = 0. if self .CP .flags & ToyotaFlags .SECOC .value else pcm_accel_cmd
255+ can_sends .append (toyotacan .create_accel_command (self .packer , main_accel_cmd , pcm_cancel_cmd , self .permit_braking , self .standstill_req , lead ,
254256 CS .acc_type , fcw_alert , self .distance_button ))
257+ if self .CP .flags & ToyotaFlags .SECOC .value :
258+ acc_cmd_2 = toyotacan .create_accel_command_2 (self .packer , pcm_accel_cmd )
259+ acc_cmd_2 = add_mac (self .secoc_key ,
260+ int (CS .secoc_synchronization ['TRIP_CNT' ]),
261+ int (CS .secoc_synchronization ['RESET_CNT' ]),
262+ self .secoc_acc_message_counter ,
263+ acc_cmd_2 )
264+ self .secoc_acc_message_counter += 1
265+ can_sends .append (acc_cmd_2 )
266+
255267 self .accel = pcm_accel_cmd
256268
257269 else :
0 commit comments