@ -46,18 +46,25 @@ class ParamsLearner: 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    self . yaw_rate_std  =  0.0   
					 
					 
					 
					    self . yaw_rate_std  =  0.0   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    self . roll  =  0.0   
					 
					 
					 
					    self . roll  =  0.0   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    self . steering_angle  =  0.0   
					 
					 
					 
					    self . steering_angle  =  0.0   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    self . roll_valid  =  False   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  def  handle_log ( self ,  t ,  which ,  msg ) :   
					 
					 
					 
					  def  handle_log ( self ,  t ,  which ,  msg ) :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  which  ==  ' livePose ' :   
					 
					 
					 
					    if  which  ==  ' livePose ' :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      device_pose  =  Pose . from_live_pose ( msg )   
					 
					 
					 
					      device_pose  =  Pose . from_live_pose ( msg )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      calibrated_pose  =  self . calibrator . build_calibrated_pose ( device_pose )   
					 
					 
					 
					      calibrated_pose  =  self . calibrator . build_calibrated_pose ( device_pose )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      yaw_rate_valid  =  msg . angularVelocityDevice . valid  and  self . calibrator . calib_valid   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      yaw_rate_valid  =  yaw_rate_valid  and  0  <  self . yaw_rate_std  <  10   # rad/s   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      yaw_rate_valid  =  yaw_rate_valid  and  abs ( self . yaw_rate )  <  1   # rad/s   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      if  yaw_rate_valid :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        self . yaw_rate ,  self . yaw_rate_std  =  calibrated_pose . angular_velocity . z ,  calibrated_pose . angular_velocity . z_std   
					 
					 
					 
					        self . yaw_rate ,  self . yaw_rate_std  =  calibrated_pose . angular_velocity . z ,  calibrated_pose . angular_velocity . z_std   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      else :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        # This is done to bound the yaw rate estimate when localizer values are invalid or calibrating   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        self . yaw_rate ,  self . yaw_rate_std  =  0.0 ,  np . radians ( 1 )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      localizer_roll ,  localizer_roll_std  =  device_pose . orientation . x ,  device_pose . orientation . x_std   
					 
					 
					 
					      localizer_roll ,  localizer_roll_std  =  device_pose . orientation . x ,  device_pose . orientation . x_std   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      localizer_roll_std  =  np . radians ( 1 )  if  np . isnan ( localizer_roll_std )  else  localizer_roll_std   
					 
					 
					 
					      localizer_roll_std  =  np . radians ( 1 )  if  np . isnan ( localizer_roll_std )  else  localizer_roll_std   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      self . roll_valid  =  ( localizer_roll_std  <  ROLL_STD_MAX )  and  ( ROLL_MIN  <  localizer_roll  <  ROLL_MAX )  and  msg . sensorsOK   
					 
					 
					 
					      roll_valid  =  ( localizer_roll_std  <  ROLL_STD_MAX )  and  ( ROLL_MIN  <  localizer_roll  <  ROLL_MAX )  and  msg . sensorsOK   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  self . roll_valid :   
					 
					 
					 
					      if  roll_valid :   
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        roll  =  localizer_roll   
					 
					 
					 
					        roll  =  localizer_roll   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # Experimentally found multiplier of 2 to be best trade-off between stability and accuracy or similar?   
					 
					 
					 
					        # Experimentally found multiplier of 2 to be best trade-off between stability and accuracy or similar?   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        roll_std  =  2  *  localizer_roll_std   
					 
					 
					 
					        roll_std  =  2  *  localizer_roll_std   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -67,14 +74,8 @@ class ParamsLearner: 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        roll_std  =  np . radians ( 10.0 )   
					 
					 
					 
					        roll_std  =  np . radians ( 10.0 )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      self . roll  =  np . clip ( roll ,  self . roll  -  ROLL_MAX_DELTA ,  self . roll  +  ROLL_MAX_DELTA )   
					 
					 
					 
					      self . roll  =  np . clip ( roll ,  self . roll  -  ROLL_MAX_DELTA ,  self . roll  +  ROLL_MAX_DELTA )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      yaw_rate_valid  =  msg . angularVelocityDevice . valid  and  self . calibrator . calib_valid   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      yaw_rate_valid  =  yaw_rate_valid  and  0  <  self . yaw_rate_std  <  10   # rad/s   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      yaw_rate_valid  =  yaw_rate_valid  and  abs ( self . yaw_rate )  <  1   # rad/s   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  self . active :   
					 
					 
					 
					      if  self . active :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if  msg . posenetOK :   
					 
					 
					 
					        if  msg . posenetOK :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          if  yaw_rate_valid :   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          self . kf . predict_and_observe ( t ,   
					 
					 
					 
					          self . kf . predict_and_observe ( t ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                                      ObservationKind . ROAD_FRAME_YAW_RATE ,   
					 
					 
					 
					                                      ObservationKind . ROAD_FRAME_YAW_RATE ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                                      np . array ( [ [ - self . yaw_rate ] ] ) ,   
					 
					 
					 
					                                      np . array ( [ [ - self . yaw_rate ] ] ) ,