obs_predict.cpp 2.8 KB

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