yuhesen_adapter.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include <adc_adapter/yuhesen_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::YuHeSenAdapter::YuHeSenAdapter(){
  9. adapter_id= 7;
  10. adapter_name="yuhesen";
  11. }
  12. iv::decition::YuHeSenAdapter::~YuHeSenAdapter(){
  13. }
  14. iv::decition::Decition iv::decition::YuHeSenAdapter::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)-40.0,(*decition)->wheel_angle);
  63. (*decition)->wheel_angle=min((float)40.0,(*decition)->wheel_angle);
  64. (*decition)->brake=0;
  65. std::cout<<"==========================================="<<std::endl;
  66. std::cout<<"dSpeed:"<<dSpeed<<" realSpeed:"<<realSpeed<<" acc:"<<accAim
  67. <<std::endl;
  68. std::cout<<"========================================="<<std::endl;
  69. (*decition)->speed = dSpeed/3.6;
  70. (*decition)->wheel_angle=(*decition)->wheel_angle*0.1;
  71. (*decition)->wheel_angle=max((float)-40.0,(*decition)->wheel_angle);
  72. (*decition)->wheel_angle=min((float)40.0,(*decition)->wheel_angle);
  73. (*decition)->mode=1;
  74. (*decition)->dangWei=1;
  75. if((*decition)->brake>0){
  76. (*decition)->speed=0;
  77. }
  78. return *decition;
  79. }
  80. float iv::decition::YuHeSenAdapter::limitBrake(float realSpeed, float controlBrake,float dSpeed,float obsDistance , float ttc){
  81. //刹车限制
  82. //刹车限制
  83. float vs =realSpeed*3.6;
  84. int BrakeIntMax = 10;
  85. if (vs < 10.0 / 3.6) BrakeIntMax = 4;
  86. else if (vs < 20.0 / 3.6) BrakeIntMax = 6;
  87. //`
  88. if(ttc>10){
  89. BrakeIntMax = 2;
  90. }else if(ttc>6){
  91. BrakeIntMax = 3;
  92. }else if(ttc>3){
  93. BrakeIntMax = 4;
  94. }else if(ttc>1.6){
  95. BrakeIntMax = 5;
  96. }else if(ttc>0.8){
  97. BrakeIntMax = 8;
  98. }else{
  99. BrakeIntMax = 10;
  100. }
  101. if(obsDistance>0 && obsDistance<10){
  102. BrakeIntMax=max(BrakeIntMax,3);
  103. }
  104. if (controlBrake > BrakeIntMax) controlBrake = BrakeIntMax;
  105. controlBrake=min(10.0f,controlBrake);
  106. controlBrake=max(0.0f,controlBrake);
  107. return controlBrake;
  108. }
  109. float iv::decition::YuHeSenAdapter::limitSpeed(float realSpeed, float controlBrake,float dSpeed,float controlSpeed ){
  110. controlSpeed=min((float)5.0,controlSpeed);
  111. controlSpeed=max((float)-7.0,controlSpeed);
  112. return controlSpeed;
  113. }