ivdecision_brain.h 16 KB

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