|  |  |  | #!/usr/bin/env python3
 | 
					
						
							|  |  |  | from cereal import car
 | 
					
						
							|  |  |  | from openpilot.common.params import Params
 | 
					
						
							|  |  |  | from openpilot.common.realtime import Priority, config_realtime_process
 | 
					
						
							|  |  |  | from openpilot.common.swaglog import cloudlog
 | 
					
						
							|  |  |  | from openpilot.selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner
 | 
					
						
							|  |  |  | import cereal.messaging as messaging
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def plannerd_thread():
 | 
					
						
							|  |  |  |   config_realtime_process(5, Priority.CTRL_LOW)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cloudlog.info("plannerd is waiting for CarParams")
 | 
					
						
							|  |  |  |   params = Params()
 | 
					
						
							|  |  |  |   CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams)
 | 
					
						
							|  |  |  |   cloudlog.info("plannerd got CarParams: %s", CP.carName)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   longitudinal_planner = LongitudinalPlanner(CP)
 | 
					
						
							|  |  |  |   pm = messaging.PubMaster(['longitudinalPlan'])
 | 
					
						
							|  |  |  |   sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2'],
 | 
					
						
							|  |  |  |                            poll='modelV2', ignore_avg_freq=['radarState'])
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while True:
 | 
					
						
							|  |  |  |     sm.update()
 | 
					
						
							|  |  |  |     if sm.updated['modelV2']:
 | 
					
						
							|  |  |  |       longitudinal_planner.update(sm)
 | 
					
						
							|  |  |  |       longitudinal_planner.publish(sm, pm)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main():
 | 
					
						
							|  |  |  |   plannerd_thread()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__":
 | 
					
						
							|  |  |  |   main()
 |