| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -15,7 +15,9 @@ class CarController(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def update(self, c, CS, frame): | 
					 | 
					 | 
					 | 
					  def update(self, c, CS, frame): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    can_sends = [] | 
					 | 
					 | 
					 | 
					    can_sends = [] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    apply_steer = 0 | 
					 | 
					 | 
					 | 
					    apply_steer = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    self.steer_rate_limited = False | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if c.enabled: | 
					 | 
					 | 
					 | 
					    if c.enabled: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      # calculate steer and also set limits due to driver torque | 
					 | 
					 | 
					 | 
					      # calculate steer and also set limits due to driver torque | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -28,20 +30,19 @@ class CarController(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds | 
					 | 
					 | 
					 | 
					        # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # Send Resume button at 20hz if we're engaged at standstill to support full stop and go! | 
					 | 
					 | 
					 | 
					        # Send Resume button at 20hz if we're engaged at standstill to support full stop and go! | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # TODO: improve the resume trigger logic by looking at actual radar data | 
					 | 
					 | 
					 | 
					        # TODO: improve the resume trigger logic by looking at actual radar data | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, Buttons.RESUME)) | 
					 | 
					 | 
					 | 
					        can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, CS.crz_btns_counter, Buttons.RESUME)) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    if c.cruiseControl.cancel or (CS.out.cruiseState.enabled and not c.enabled): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      # if brake is pressed, let us wait >20ms before trying to disable crz to avoid | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      # a race condition with the stock system, where the second cancel from openpilot | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      # will disable the crz 'main on' | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      self.brake_counter = self.brake_counter + 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      if frame % 20 == 0 and not (CS.out.brakePressed and self.brake_counter < 3): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # Cancel Stock ACC if it's enabled while OP is disengaged | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # Send at a rate of 5hz until we sync with stock ACC state | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, CS.crz_btns_counter, Buttons.CANCEL)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    else: | 
					 | 
					 | 
					 | 
					    else: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      self.steer_rate_limited = False | 
					 | 
					 | 
					 | 
					      self.brake_counter = 0 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      if CS.out.cruiseState.enabled: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # if brake is pressed, let us wait >20ms before trying to disable crz to avoid | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # a race condition with the stock system, where the second cancel from openpilot | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # will disable the crz 'main on' | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.brake_counter = self.brake_counter + 1 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if frame % 20 == 0 and not (CS.out.brakePressed and self.brake_counter < 3): | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          # Cancel Stock ACC if it's enabled while OP is disengaged | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          # Send at a rate of 5hz until we sync with stock ACC state | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, Buttons.CANCEL)) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      else: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.brake_counter = 0 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self.apply_steer_last = apply_steer | 
					 | 
					 | 
					 | 
					    self.apply_steer_last = apply_steer | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |