vv7_adapter.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <adc_adapter/vv7_adapter.h>
  2. #include <common/constants.h>
  3. #include <common/car_status.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <fstream>
  7. using namespace std;
  8. iv::decition::VV7Adapter::VV7Adapter(){
  9. adapter_id= 2;
  10. adapter_name="vv7";
  11. }
  12. iv::decition::VV7Adapter::~VV7Adapter(){
  13. }
  14. iv::decition::Decition iv::decition::VV7Adapter::getAdapterDeciton(GPS_INS now_gps_ins, std::vector<Point2D> trace , float dSpeed, float obsDistance ,
  15. float obsSpeed,float accAim,float accNow ,bool changingDangWei,Decition *decition){
  16. float controlSpeed=accAim;
  17. float controlBrake=0;
  18. float u = 0- accAim;
  19. float realSpeed = now_gps_ins.speed;
  20. float ttc = 0-(obsDistance/obsSpeed);
  21. bool turn_around=false;
  22. if(now_gps_ins.roadMode==14||now_gps_ins.roadMode==15||now_gps_ins.roadMode==16||now_gps_ins.roadMode==17){
  23. turn_around=true;
  24. }
  25. if(ttc<0){
  26. ttc=15;
  27. }
  28. if (accAim < 0)
  29. {
  30. //0110
  31. if(changingDangWei){
  32. controlSpeed=min(-0.5f,controlSpeed);
  33. }
  34. // else if((obsDistance<0 ||obsDistance>50)&&(abs(dSpeed-realSpeed)<3)){
  35. // controlSpeed=max(-0.2f,controlSpeed);
  36. // }
  37. }
  38. else
  39. {
  40. controlSpeed=min(1.0f,controlSpeed);
  41. }
  42. //0227 10m nei xianzhi shache
  43. if(obsDistance<10 &&obsDistance>0){
  44. controlSpeed=min(controlSpeed,-0.8f);
  45. }
  46. // if(DecideGps00::minDecelerate<0){
  47. // controlSpeed = min(DecideGps00::minDecelerate, controlSpeed);
  48. // }
  49. if(minDecelerate<0){
  50. controlSpeed = min(minDecelerate, controlSpeed);
  51. }
  52. controlSpeed = limitSpeed(realSpeed, controlBrake, dSpeed, controlSpeed);
  53. (*decition)->accelerator=controlSpeed;
  54. if((*decition)->leftlamp){
  55. (*decition)->directLight=1;
  56. }else if((*decition)->rightlamp){
  57. (*decition)->directLight=2;
  58. }else{
  59. (*decition)->directLight=0;
  60. }
  61. (*decition)->wheel_angle+=ServiceCarStatus.mfEPSOff;
  62. (*decition)->wheel_angle=max((float)-500.0,(*decition)->wheel_angle);
  63. (*decition)->wheel_angle=min((float)500.0,(*decition)->wheel_angle);
  64. if((*decition)->accelerator>=0){
  65. (*decition)->torque= (*decition)->accelerator;
  66. (*decition)->brake=0;
  67. }else{
  68. (*decition)->torque=0;
  69. (*decition)->brake=0-(*decition)->accelerator;
  70. }
  71. std::cout<<"==========================================="<<std::endl;
  72. std::cout<<"dSpeed:"<<dSpeed<<" realSpeed:"<<realSpeed<<" acc:"<<accAim
  73. <<std::endl;
  74. std::cout<<"========================================="<<std::endl;
  75. return *decition;
  76. }
  77. float iv::decition::VV7Adapter::limitBrake(float realSpeed, float controlBrake,float dSpeed,float obsDistance , float ttc){
  78. //刹车限制
  79. //刹车限制
  80. float vs =realSpeed*3.6;
  81. int BrakeIntMax = 10;
  82. if (vs < 10.0 / 3.6) BrakeIntMax = 4;
  83. else if (vs < 20.0 / 3.6) BrakeIntMax = 6;
  84. //`
  85. if(ttc>10){
  86. BrakeIntMax = 2;
  87. }else if(ttc>6){
  88. BrakeIntMax = 3;
  89. }else if(ttc>3){
  90. BrakeIntMax = 4;
  91. }else if(ttc>1.6){
  92. BrakeIntMax = 5;
  93. }else if(ttc>0.8){
  94. BrakeIntMax = 8;
  95. }else{
  96. BrakeIntMax = 10;
  97. }
  98. if(obsDistance>0 && obsDistance<10){
  99. BrakeIntMax=max(BrakeIntMax,3);
  100. }
  101. if (controlBrake > BrakeIntMax) controlBrake = BrakeIntMax;
  102. controlBrake=min(10.0f,controlBrake);
  103. controlBrake=max(0.0f,controlBrake);
  104. return controlBrake;
  105. }
  106. float iv::decition::VV7Adapter::limitSpeed(float realSpeed, float controlBrake,float dSpeed,float controlSpeed ){
  107. controlSpeed=min((float)5.0,controlSpeed);
  108. controlSpeed=max((float)-7.0,controlSpeed);
  109. return controlSpeed;
  110. }