ivdecision_brain.h 16 KB

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