obs_predict.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <decision/obs_predict.h>
  2. #include <decision/decition_type.h>
  3. #include <common/gps_type.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <decision/adc_tools/transfer.h>
  8. #include "perception/perceptionoutput.h"
  9. #include<common/constants.h>
  10. using namespace std;
  11. #define PI (3.1415926535897932384626433832795)
  12. double iv::decition::PredictObsDistance( double realSpeed,std::vector<Point2D> gpsTrace,std::vector<iv::Perception::PerceptionOutput> lidar_per){
  13. double crashDistance=200;
  14. for(int i=0;i<lidar_per.size();i++){
  15. if(lidar_per[i].life>300 && (lidar_per[i].velocity.x!=0 || lidar_per[i].velocity.y!=0)){
  16. if(lidar_per[i].location.y>20 && lidar_per[i].velocity.y>0){
  17. }
  18. else if(lidar_per[i].location.y<0 && lidar_per[i].velocity.y<0){
  19. }
  20. else if(lidar_per[i].location.x>20 && lidar_per[i].velocity.x>0){
  21. }else if(lidar_per[i].location.x<-20 && lidar_per[i].velocity.x<0){
  22. }else{
  23. double crashDis = getCrashDis(realSpeed,gpsTrace,lidar_per[i]);
  24. crashDistance=min(crashDis,crashDistance);
  25. }
  26. }
  27. }
  28. return crashDistance;
  29. }
  30. double iv::decition::getCrashDis(double realSpeed,std::vector<Point2D> gpsTrace,iv::Perception::PerceptionOutput obs){
  31. double dis=0;
  32. int length=min(300,(int)gpsTrace.size());
  33. int step=10;
  34. int size =length/step;
  35. for(int i=1; i<size;i++){
  36. double time = getTime( realSpeed, gpsTrace, i*step,&dis);
  37. double obsX= obs.location.x+obs.velocity.x*time;
  38. double obsY= obs.location.y+obs.velocity.y*time;
  39. Point2D obsP(obsX,obsY);
  40. double obsDis= GetDistance(obsP,gpsTrace[i*10]);
  41. if(obsDis<0.7*(ServiceCarStatus.msysparam.vehWidth+obs.size.x) ){
  42. return dis;
  43. }
  44. }
  45. return 200;
  46. }
  47. int iv::decition::getFrameCount(double realSpeed,std::vector<Point2D> gpsTrace){
  48. double lenth=0;
  49. for(int i =0 ; i<gpsTrace.size()-1;i++){
  50. lenth +=GetDistance(gpsTrace[i],gpsTrace[i+1]);
  51. }
  52. int frame= lenth/realSpeed;
  53. frame = min(frame,50);
  54. return frame;
  55. }
  56. int iv::decition::getPoiIndex(double realSpeed,std::vector<Point2D> gpsTrace,int frame){
  57. double d =realSpeed*0.1*frame;
  58. int index=0;
  59. for(int j=0;j<gpsTrace.size()-1;j++){
  60. double dis;
  61. dis+=GetDistance(gpsTrace[j],gpsTrace[j+1]);
  62. if(dis>d){
  63. index=j;
  64. break;
  65. }
  66. index=j;
  67. }
  68. return index;
  69. }
  70. double iv::decition::getTime(double realSpeed,std::vector<Point2D> gpsTrace,int frame ,double *dis){
  71. int size=gpsTrace.size()-1;
  72. int f=min(frame,size);
  73. for(int i=0;i<=f;i++){
  74. *dis+=GetDistance(gpsTrace[0],gpsTrace[f]);
  75. }
  76. double time = *dis/realSpeed;
  77. return time;
  78. }