ivdecision_brain.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. #ifndef IVDECISION_BRAIN_H
  2. #define IVDECISION_BRAIN_H
  3. #include "ivdecision.h"
  4. #include "decition_type.h"
  5. #include "gps_type.h"
  6. #include "constants.h"
  7. #include <vector>
  8. #include <gnss_coordinate_convert.h>
  9. #include <adc_planner/frenet_planner.h>
  10. #include <adc_controller/pid_controller.h>
  11. #include <adc_adapter/ge3_adapter.h>
  12. #include <adc_adapter/qingyuan_adapter.h>
  13. #include <adc_adapter/vv7_adapter.h>
  14. #include <adc_adapter/zhongche_adapter.h>
  15. #include <adc_adapter/bus_adapter.h>
  16. #include <adc_adapter/hapo_adapter.h>
  17. #include <adc_adapter/zhongche_adapter.h>
  18. #include <adc_adapter/yuhesen_adapter.h>
  19. #include "common/perceptionoutput.h"
  20. #include "adc_tools/compute_00.h"
  21. #include "common/car_status.h"
  22. #include "adc_tools/gps_distance.h"
  23. #include "adc_tools/transfer.h"
  24. namespace iv {
  25. class ivdecision_brain : public ivdecision
  26. {
  27. public:
  28. enum VehState { normalRun, park, readyPark, stopObs, avoidObs, preAvoid, avoiding, backOri,preBack,
  29. waitAvoid ,shoushaTest,justRun, changingRoad, chaoche, chaocheBack, reverseCar,reversing, reverseCircle, reverseDirect,reverseArr,
  30. dRever,dRever0,dRever1,dRever2,dRever3,dRever4} mvehState;
  31. public:
  32. ivdecision_brain();
  33. public:
  34. virtual int getdecision(iv::brain::decition & xdecition,iv::brain::brainstate & xbs);
  35. private:
  36. // int getdecision_normal(iv::decition::Decition &xdecition,GPS_INS now_gps_ins,
  37. // const std::vector<GPSData> gpsMapLine,
  38. // iv::LidarGridPtr lidarGridPtr,
  39. // std::vector<iv::Perception::PerceptionOutput> lidar_per,
  40. // iv::TrafficLight trafficLight);
  41. private:
  42. std::vector<GPSData> mgpsMapLine;
  43. private:
  44. iv::decition::Decition getDecideFromGPS(GPS_INS now_gps_ins,const std::vector<GPSData> gpsMapLine,
  45. iv::LidarGridPtr lidarGridPtr,
  46. std::vector<iv::Perception::PerceptionOutput> lidar_per,
  47. iv::TrafficLight trafficLight);
  48. private:
  49. void updatev2x();
  50. void updateultra();
  51. void updateradar();
  52. private:
  53. int mnRunMode = 0;
  54. bool mbisFirstRun = true;
  55. int mnPathPoint;
  56. private:
  57. float xiuzhengCs=0;
  58. int PathPoint = -1;
  59. double minDis = iv::MaxValue;
  60. double maxAngle = iv::MinValue;
  61. //int lastGpsIndex = iv::MaxValue;
  62. int lastGpsIndex = 0;
  63. double controlSpeed = 0;
  64. double controlBrake = 0;
  65. double controlAng = 0;
  66. double Iv = 0;
  67. double lastU = 0;
  68. double lastVt = 0;
  69. double lastEv = 0;
  70. int gpsLineParkIndex = 0;
  71. int gpsMapParkIndex = 0;
  72. double lastDistance = MaxValue;
  73. double lastPreObsDistance = MaxValue;
  74. double obsDistance = -1;
  75. double obsSpeed=0;
  76. double obsDistanceAvoid = -1;
  77. double lastDistanceAvoid = -1;
  78. double lidarDistance = -1;
  79. double myesrDistance = -1;
  80. double lastLidarDis = -1;
  81. bool parkMode = false;
  82. bool readyParkMode = false;
  83. bool zhucheMode = false;
  84. bool readyZhucheMode = false;
  85. bool hasZhuched = false;
  86. double lastLidarDisAvoid = -1;
  87. double lidarDistanceAvoid = -1;
  88. int finishPointNum = -1;
  89. int zhuchePointNum = 0;
  90. ///kkcai, 2020-01-03
  91. bool isFirstRun = true;
  92. //////////////////////////////////////////////
  93. float minDecelerate=0;
  94. //bool startingFlag = true;//起步标志,在起步时需要进行frenet规划。
  95. double offset_real = 0;
  96. double realspeed;
  97. double dSpeed;
  98. double dSecSpeed;
  99. double secSpeed;
  100. double ac;
  101. iv::Point2D obsPoint;
  102. iv::Point2D obsPointAvoid;
  103. // iv::Point2D obsPoint(-1.0, -1.0);
  104. // iv::Point2D obsPointAvoid(-1, -1);
  105. int esrIndex = -1;
  106. int esrIndexAvoid = -1;
  107. double obsSpeedAvoid = 0;
  108. double esrDistance = -1;
  109. double esrDistanceAvoid = -1;
  110. int obsLostTime = 0;
  111. int obsLostTimeAvoid = 0;
  112. // double avoidTime = 0;
  113. double avoidX =0;
  114. float roadWidth = 3.5;
  115. int roadSum =10;
  116. int roadNow = 0;
  117. int roadOri =0;
  118. int roadPre = -1;
  119. int lastRoadOri = 0;
  120. int lightTimes = 0;
  121. int lastRoadNum=1;
  122. int stopCount = 0;
  123. int gpsMissCount = 0;
  124. bool rapidStop = false;
  125. bool hasTrumpeted = false;
  126. bool changeRoad=false;
  127. //实验手刹
  128. bool handFirst = true;
  129. double handTimeSpan = 0;
  130. double handStartTime = 0;
  131. double handLastTime = 0;
  132. bool handPark = false;
  133. long handParkTime=10000;
  134. //喇叭
  135. bool trumpetFirstCount=true;
  136. double trumpetTimeSpan = 0;
  137. double trumpetStartTime = 0;
  138. double trumpetLastTime = 0;
  139. //过渡
  140. bool transferFirstCount=true;
  141. double transferTimeSpan = 0;
  142. double transferStartTime = 0;
  143. double transferLastTime = 0;
  144. bool busMode = false;
  145. bool parkBesideRoad=false;
  146. bool chaocheMode = false;
  147. bool specialSignle = false;
  148. double offsetX = 0;
  149. double steerSpeed=9000;
  150. bool transferPieriod;
  151. bool transferPieriod2;
  152. double traceDevi;
  153. bool startingFlag = true; //起步标志,在起步时需要进行frenet规划。
  154. bool useFrenet = false; //标志是否启用frenet算法避障
  155. bool useOldAvoid = true; //标志是否用老方法避障
  156. // enum VehState { normalRun, park, readyPark, stopObs, avoidObs, preAvoid, avoiding, backOri,preBack,
  157. // waitAvoid ,shoushaTest,justRun, changingRoad, chaoche, chaocheBack, reverseCar,reversing, reverseCircle, reverseDirect,reverseArr,
  158. // dRever,dRever0,dRever1,dRever2,dRever3,dRever4} vehState;
  159. std::vector<iv::Point2D> gpsTraceAim; //记录变道后的目标路径,若车辆经frenet规划行驶至该路径上后,就关闭frenet规划
  160. std::vector<iv::Point2D> gpsTraceAvoid,gpsTraceNow,gpsTraceBack,gpsTracePre,gpsTraceOri,gpsTraceRear;
  161. std::vector<double> esrDisVector;
  162. std::vector<double> lidarDisVector;
  163. std::vector<double> obsDisVector;
  164. std::vector<double> obsSpeedVector;
  165. std::vector<int> obsLostTimeVector;
  166. std::vector<double> lastLidarDisVector;
  167. std::vector<double> lastDistanceVector;
  168. // std::vector<double> esrDisVector(roadSum, -1);
  169. // std::vector<double> lidarDisVector(roadSum, -1);
  170. // std::vector<double> obsDisVector(roadSum,-1);
  171. // std::vector<double> obsSpeedVector(roadSum, 0);
  172. // std::vector<int> obsLostTimeVector(roadSum, 0);
  173. // std::vector<double> lastLidarDisVector(roadSum, -1);
  174. // std::vector<double> lastDistanceVector(roadSum, -1);
  175. bool qiedianCount = false;
  176. private:
  177. // static double minDis;
  178. // static double maxAngle;
  179. // static int lastGpsIndex;
  180. // static double lidarDistance;
  181. // static double myesrDistance;
  182. // static double lastLidarDis;
  183. // static double lastLidarDisAvoid;
  184. // static double lastPreObsDistance;
  185. // static int gpsLineParkIndex;
  186. // static int gpsMapParkIndex;
  187. // static double lastDistance;
  188. // static float xiuzhengCs;
  189. // static double controlAng;
  190. // double laneAng;
  191. // static double controlSpeed;
  192. // static double controlBrake;
  193. // static bool parkMode;
  194. // static bool readyParkMode;
  195. // static bool zhucheMode;
  196. // static bool readyZhucheMode;
  197. // static bool hasZhuched;
  198. // static double Iv;
  199. // static double lastEv;
  200. // static double lastVt;
  201. // static double lastU;
  202. // static double obsDistance;
  203. // static double obsSpeed;
  204. // static double lidarDistanceAvoid;
  205. // static double obsDistanceAvoid;
  206. // static double lastDistanceAvoid;
  207. GPS_INS group_ori_gps;
  208. GPS_INS startAvoid_gps_ins;
  209. // static int finishPointNum;
  210. // static int zhuchePointNum;
  211. double avoidRunDistance=0;
  212. std::vector<iv::GPS_INS> startAvoidGpsInsVector;
  213. std::vector<double> avoidMinDistanceVector;
  214. std::vector<int> v2xTrafficVector;
  215. ///kkcai, 2020-01-03
  216. //bool isFirstRun = true;
  217. // static bool isFirstRun;
  218. /////////////////////////////////////
  219. // static bool startingFlag;//起步标志,在起步时需要进行frenet规划。
  220. // static float minDecelerate;
  221. double startTime = 0;
  222. double firstTime = 0;
  223. bool circleMode=false;
  224. int avoidTimes = 0;
  225. int backTimes = 0;
  226. int checkAvoidObsTimes = 0;
  227. int checkBackObsTimes = 0;
  228. bool hasCheckedAvoidLidar=false;
  229. bool hasCheckedBackLidar=false;
  230. bool personWaited = false;
  231. bool roadLightWaited = false;
  232. double decision_Angle = 0;
  233. double lastAngle=0;
  234. // iv::Point2D obsPoint;
  235. int checkAvoidTimes=0;
  236. int checkBackTimes=0;
  237. int chaocheCounts=0;
  238. // static int PathPoint;
  239. float lastGroupOffsetX=0.0;
  240. GPS_INS traffic_light_gps;
  241. int traffic_light_pathpoint;
  242. bool changingDangWei=false;
  243. iv::decition::BaseController *pid_Controller;
  244. iv::decition::BaseAdapter *ge3_Adapter;
  245. iv::decition::BaseAdapter *qingyuan_Adapter;
  246. iv::decition::BaseAdapter *vv7_Adapter;
  247. iv::decition::BaseAdapter *zhongche_Adapter;
  248. iv::decition::BaseAdapter *bus_Adapter;
  249. iv::decition::BaseAdapter *hapo_Adapter;
  250. iv::decition::BaseAdapter *yuhesen_Adapter;
  251. std::shared_ptr<iv::decition::BaseController> mpid_Controller;
  252. std::shared_ptr<iv::decition::BaseAdapter> mge3_Adapter;
  253. std::shared_ptr<iv::decition::BaseAdapter> mqingyuan_Adapter;
  254. std::shared_ptr<iv::decition::BaseAdapter> mvv7_Adapter;
  255. std::shared_ptr<iv::decition::BaseAdapter> mzhongche_Adapter;
  256. std::shared_ptr<iv::decition::BaseAdapter> mbus_Adapter;
  257. std::shared_ptr<iv::decition::BaseAdapter> mhapo_Adapter;
  258. std::shared_ptr<iv::decition::BaseAdapter> myuhesen_Adapter;
  259. iv::decition::FrenetPlanner *frenetPlanner;
  260. VehState vehState;
  261. // BasePlanner *laneChangePlanner;
  262. std::shared_ptr<iv::decition::FrenetPlanner> mfrenetPlanner;
  263. // std::shared_ptr<BasePlanner> mlaneChangePlanner;
  264. // Decition getDecideFromGPS(GPS_INS gpsIns, const std::vector<GPSData> navigation_data, iv::LidarGridPtr lidarGridPtr,
  265. // std::vector<iv::Perception::PerceptionOutput> lidar_per,iv::TrafficLight trafficLight);
  266. void initMethods();
  267. std::vector<Point2D> getGpsTrace(GPS_INS rp, const std::vector<GPSData> gpsMap, int lastIndex, bool circleMode);
  268. double getAngle(std::vector<Point2D> gpsTrace);
  269. double getAngle(std::vector<Point2D> gpsTrace, GPS_INS gpsIns,iv::decition::Decition decition);
  270. double getSpeed(std::vector<Point2D> gpsTrace);
  271. void getEsrObsDistance(std::vector<Point2D> gpsTrace, int roadNum);
  272. void getRearEsrObsDistance(std::vector<Point2D> gpsTrace, int roadNum);
  273. void getEsrObsDistanceAvoid();
  274. void getObsAvoid(iv::LidarGridPtr lidarGridPtr);
  275. void phaseSpeedDecition(iv::decition::Decition decition, double secSpeed, double obsDis, double obsSpeed, GPS_INS gpsIns );
  276. double limitAngle(double speed, double angle);
  277. double limitSpeed(double angle, double speed);
  278. bool checkAvoidEnable(double avoidX, iv::LidarGridPtr lidarGridPtr, int roadNum);
  279. bool checkReturnEnable(double avoidX, iv::LidarGridPtr lidarGridPtr, int roadNum);
  280. void computeObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per);
  281. void getEsrObsDistanceByFrenet(const std::vector<Point2D>& gpsTrace, iv::decition::FrenetPoint car_now_frenet_point,iv::decition::FrenetPoint &esrObs_F_Point, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps);
  282. void computeRearObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,const std::vector<GPSData> gpsMapLine);
  283. void computeObsOnRoadByFrenet(iv::LidarGridPtr lidarGridPtr,const std::vector<Point2D>& gpsTrace, double & obs, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps);
  284. void predictObsOnRoad(std::vector<iv::Perception::PerceptionOutput> lidar_per,std::vector<Point2D> gpsTrace,double realSpeed);
  285. int chooseAvoidRoad(iv::LidarGridPtr lidarGridPtr, GPS_INS now_gps_ins,std::vector<GPSData> gpsMapLine,std::vector<iv::Perception::PerceptionOutput> lidar_per);
  286. int chooseBackRoad(iv::LidarGridPtr lidarGridPtr, GPS_INS now_gps_ins, std::vector<GPSData> gpsMapLine,std::vector<iv::Perception::PerceptionOutput> lidar_per);
  287. void getMapBeside(std::vector<iv::GPSData> navigation_data, iv::GPS_INS now_gps_ins);
  288. void handBrakePark(iv::decition::Decition decition, long duringTime, GPS_INS now_gps_ins);
  289. bool checkChaoCheBack(iv::LidarGridPtr);
  290. double trumpet();
  291. double transferP();
  292. bool nearStation;
  293. void updateGroupDate(GPS_INS now_gps_ins,float realspeed,float theta,float s);
  294. void init();
  295. std::vector<Point2D> getGpsTraceOffset(std::vector<Point2D> gpsTrace, double offset);
  296. std::vector<iv::Point2D> getGpsTraceBackExa(iv::GPS_INS now_gps_ins, const std::vector<GPSData> gpsMapLine, int pathpo);
  297. float ComputeTrafficLightSpeed(int traffic_light_color, int traffic_light_time, const std::vector<GPSData> gpsMapLine,int traffic_light_pathpoint,
  298. int pathpoint,float secSpeed,float dSpeed);
  299. void getV2XTrafficPositionVector( const std::vector<GPSData> gpsMapLine);
  300. float ComputeV2XTrafficLightSpeed(iv::TrafficLight TrafficLight, const std::vector<GPSData> gpsMapLine,std::vector<int> v2xTrafficVector,
  301. int pathpoint,float secSpeed,float dSpeed,bool circleMode);
  302. float getTrafficLightSpeed(int traffic_light_color, int traffic_light_time, float dis);
  303. bool computeTrafficPass(float trafficDis,int trafficColor,float trafficTime,float realSecSpeed,float dSecSpeed);
  304. float computeTrafficSpeedLimt(float trafficDis);
  305. float computeAvoidX(int roadAim,int roadOri,GPSData gps,float vehWidth);
  306. bool adjuseultra();
  307. iv::Station getNearestStation(iv::GPS_INS now_gps_ins,std::vector<Station> station_n,std::vector<GPSData> gpsMap);
  308. void transferGpsMode2( const std::vector<GPSData> gpsMapLine);
  309. GPS_INS aim_gps_ins;
  310. GPS_INS chaoche_start_gps;
  311. bool is_arrivaled=false;
  312. double chaocheObsDis = 0;
  313. double preChaocheDis = 0;
  314. double aimObsSpeed = 0;
  315. double followSpeed = 30;
  316. double chaocheSpeed = 50;
  317. int checkChaoCheBackCounts = 0;
  318. float lastTorque=0;
  319. float splimit=-1;
  320. float ObsTimeSpan=-1;
  321. double ObsTimeStart=-1;
  322. double ObsTimeEnd=-1;
  323. float ObsTimeWidth=1500;
  324. std::vector<iv::TracePoint> planTrace;
  325. bool roadNowStart=true;
  326. private:
  327. iv::decition::Decition decision_reverseCar(iv::GPS_INS now_gps_ins);
  328. iv::decition::Decition decision_reversing(iv::GPS_INS now_gps_ins);
  329. iv::decition::Decition decision_reverseCircle(iv::GPS_INS now_gps_ins);
  330. iv::decition::Decition decision_reverseDirect(iv::GPS_INS now_gps_ins);
  331. iv::decition::Decition decision_reverseArr(iv::GPS_INS now_gps_ins);
  332. iv::decition::Decition decision_dRever(iv::GPS_INS now_gps_ins);
  333. iv::decition::Decition decision_dRever0(iv::GPS_INS now_gps_ins);
  334. iv::decition::Decition decision_dRever1(iv::GPS_INS now_gps_ins);
  335. iv::decition::Decition decision_dRever2(iv::GPS_INS now_gps_ins);
  336. iv::decition::Decition decision_dRever3(iv::GPS_INS now_gps_ins);
  337. iv::decition::Decition decision_dRever4(iv::GPS_INS now_gps_ins);
  338. void decision_firstRun(GPS_INS now_gps_ins,
  339. const std::vector<GPSData> & gpsMapLine);
  340. int decision_ParkCalc(GPS_INS now_gps_ins,iv::decition::Decition & gps_decition);
  341. void decision_readyZhucheMode(GPS_INS now_gps_ins,const std::vector<GPSData> & gpsMapLine);
  342. void decision_readyParkMode(GPS_INS now_gps_ins,const std::vector<GPSData> & gpsMapLine);
  343. void decision_speedctrl(iv::decition::Decition & gps_decition,const std::vector<GPSData> & gpsMapLine);
  344. };
  345. }
  346. #endif // IVDECISION_BRAIN_H