Commit 83bcaa3 1 parent 9d92bf2 commit 83bcaa3 Copy full SHA for 83bcaa3
File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,14 @@ int cruise_engaged_last = 0; // cruise state
32
32
static void toyota_rx_hook (CAN_FIFOMailBox_TypeDef * to_push ) {
33
33
// get eps motor torque (0.66 factor in dbc)
34
34
if ((to_push -> RIR >>21 ) == 0x260 ) {
35
- int16_t torque_meas_new_16 = (((to_push -> RDHR ) & 0xFF00 ) | ((to_push -> RDHR >> 16 ) & 0xFF ));
35
+ int torque_meas_new = (((to_push -> RDHR ) & 0xFF00 ) | ((to_push -> RDHR >> 16 ) & 0xFF ));
36
+ torque_meas_new = to_signed (torque_meas_new , 16 );
37
+
38
+ // scale by dbc_factor
39
+ torque_meas_new *= dbc_eps_torque_factor / 100 ;
36
40
37
41
// increase torque_meas by 1 to be conservative on rounding
38
- int torque_meas_new = (( int )( torque_meas_new_16 ) * dbc_eps_torque_factor / 100 ) + ( torque_meas_new_16 > 0 ? 1 : -1 );
42
+ torque_meas_new + = (torque_meas_new > 0 ? 1 : -1 );
39
43
40
44
// update array of sample
41
45
update_sample (& torque_meas , torque_meas_new );
@@ -88,7 +92,6 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
88
92
if (desired_torque < - MAX_TORQUE ) violation = 1 ;
89
93
if (desired_torque > MAX_TORQUE ) violation = 1 ;
90
94
91
-
92
95
// *** torque rate limit check ***
93
96
int16_t highest_allowed_torque = max (desired_torque_last , 0 ) + MAX_RATE_UP ;
94
97
int16_t lowest_allowed_torque = min (desired_torque_last , 0 ) - MAX_RATE_UP ;
You can’t perform that action at this time.
0 commit comments