@@ -2,7 +2,7 @@ int toyota_giraffe_switch_1 = 0; // is giraffe switch 1 high?
2
2
int toyota_camera_forwarded = 0 ; // should we forward the camera bus?
3
3
4
4
// global torque limit
5
- const int TOYOTA_MAX_TORQUE = 1500 ; // max torque cmd allowed ever
5
+ const int TOYOTA_MAX_TORQUE = 1800 ; // max torque cmd allowed ever
6
6
7
7
// rate based torque limit + stay within actually applied
8
8
// packet is sent at 100hz, so this limit is 1000/sec
@@ -16,8 +16,8 @@ const int TOYOTA_MAX_RT_DELTA = 375; // max delta torque allowed for real t
16
16
const int TOYOTA_RT_INTERVAL = 250000 ; // 250ms between real time checks
17
17
18
18
// longitudinal limits
19
- const int TOYOTA_MAX_ACCEL = 1500 ; // 1.5 m/s2
20
- const int TOYOTA_MIN_ACCEL = -3000 ; // 3.0 m/s2
19
+ const int TOYOTA_MAX_ACCEL = 1800 ; // 1.8 m/s2
20
+ const int TOYOTA_MIN_ACCEL = -3600 ; // 3.6 m/s2
21
21
22
22
// global actuation limit state
23
23
int toyota_actuation_limits = 1 ; // by default steer limits are imposed
@@ -28,10 +28,17 @@ int toyota_desired_torque_last = 0; // last desired steer torque
28
28
int toyota_rt_torque_last = 0 ; // last desired torque for real time check
29
29
uint32_t toyota_ts_last = 0 ;
30
30
int toyota_cruise_engaged_last = 0 ; // cruise state
31
+ int ego_speed_toyota = 0 ; // speed
31
32
struct sample_t toyota_torque_meas ; // last 3 motor torques produced by the eps
32
33
33
34
34
35
static void toyota_rx_hook (CAN_FIFOMailBox_TypeDef * to_push ) {
36
+ // sample speed
37
+ if ((to_push -> RIR >>21 ) == 0xb4 ) {
38
+ // Middle bytes needed
39
+ ego_speed_toyota = (to_push -> RDHR >> 8 ) & 0xFFFF ; //Speed is 100x
40
+ }// Special thanks to Willem Melching for the code
41
+
35
42
// get eps motor torque (0.66 factor in dbc)
36
43
if ((to_push -> RIR >>21 ) == 0x260 ) {
37
44
int torque_meas_new = (((to_push -> RDHR ) & 0xFF00 ) | ((to_push -> RDHR >> 16 ) & 0xFF ));
@@ -100,11 +107,20 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
100
107
uint32_t ts = TIM2 -> CNT ;
101
108
102
109
// only check if controls are allowed and actuation_limits are imposed
103
- if (controls_allowed && toyota_actuation_limits ) {
110
+ if (toyota_actuation_limits ) {
104
111
105
112
// *** global torque limit check ***
106
- violation |= max_limit_check (desired_torque , TOYOTA_MAX_TORQUE , - TOYOTA_MAX_TORQUE );
107
-
113
+
114
+ if (!toyota_cruise_engaged_last ){
115
+ if (ego_speed_toyota > 4500 ){
116
+ violation |= max_limit_check (desired_torque , 805 , -805 );
117
+ } else {
118
+ violation = 1 ;
119
+ }
120
+
121
+ } else {
122
+ violation |= max_limit_check (desired_torque , TOYOTA_MAX_TORQUE , - TOYOTA_MAX_TORQUE );
123
+ }
108
124
// *** torque rate limit check ***
109
125
violation |= dist_to_meas_check (desired_torque , toyota_desired_torque_last ,
110
126
& toyota_torque_meas , TOYOTA_MAX_RATE_UP , TOYOTA_MAX_RATE_DOWN , TOYOTA_MAX_TORQUE_ERROR );
@@ -124,12 +140,12 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
124
140
}
125
141
126
142
// no torque if controls is not allowed
127
- if (!controls_allowed && (desired_torque != 0 )) {
128
- violation = 1 ;
129
- }
143
+ // if (!controls_allowed && (desired_torque != 0)) {
144
+ // violation = 1;
145
+ // }
130
146
131
147
// reset to 0 if either controls is not allowed or there's a violation
132
- if (violation || ! controls_allowed ) {
148
+ if (violation ) {
133
149
toyota_desired_torque_last = 0 ;
134
150
toyota_rt_torque_last = 0 ;
135
151
toyota_ts_last = ts ;
0 commit comments