ge3_adapter.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include <adc_adapter/ge3_adapter.h>
  2. #include <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::Ge3Adapter::Ge3Adapter(){
  9. adapter_id=0;
  10. adapter_name="ge3";
  11. }
  12. iv::decition::Ge3Adapter::~Ge3Adapter(){
  13. }
  14. iv::decition::Decition iv::decition::Ge3Adapter::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=0;
  17. float controlBrake=0;
  18. float realSpeed = now_gps_ins.speed;
  19. float ttc = 0-(obsDistance/obsSpeed);
  20. if(ttc<0){
  21. ttc=15;
  22. }
  23. if (accAim < 0)
  24. {
  25. if(obsDistance<10 && obsDistance>0 ){
  26. if(ttc>3){
  27. controlBrake = (int)((0-accAim) * 40.0) + 1; //(u * 14.0) + 1;
  28. }else{
  29. controlBrake = (int)((0-accAim) * 60.0) + 1; //(u * 14.0) + 1;
  30. }
  31. } else{
  32. if(ttc<5){
  33. controlBrake = (int)((0-accAim) * 40.0) + 1; //(u * 14.0) + 1;
  34. }else {
  35. controlBrake = (int)((0-accAim) * 20.0) + 1; //(u * 14.0) + 1;
  36. }
  37. }
  38. controlSpeed = 0;
  39. if(obsDistance>50 && ttc>8 &&abs(realSpeed-dSpeed)<3){
  40. controlBrake=0;
  41. controlSpeed=max(lastTorque-10.0,0.0);
  42. }
  43. }
  44. else
  45. {
  46. controlBrake = 0;
  47. if(lastTorque==0){
  48. controlSpeed=100;
  49. }else{
  50. controlSpeed = lastTorque+(accAim-accNow)*500*0.1;
  51. }
  52. }
  53. if(ServiceCarStatus.bocheMode){
  54. if(dSpeed<6){
  55. controlSpeed=min(1.0f,controlSpeed);
  56. controlBrake=min(5.0f,controlBrake);
  57. if(abs(dSpeed-realSpeed)<2 && controlBrake>0){
  58. controlBrake=0;
  59. }
  60. }
  61. }
  62. controlBrake=limitBrake(realSpeed,controlBrake,dSpeed,obsDistance,ttc);
  63. controlSpeed = limitSpeed(realSpeed, controlBrake, dSpeed, controlSpeed);
  64. // if(DecideGps00::minDecelerate<0){
  65. // controlBrake = max((0-DecideGps00::minDecelerate)*30,controlBrake);
  66. // controlSpeed=0;
  67. // }
  68. if(minDecelerate<0){
  69. controlBrake = max((0-minDecelerate)*30,controlBrake);
  70. controlSpeed=0;
  71. }
  72. controlBrake=min(controlBrake,100.0f);
  73. controlBrake=max(controlBrake,0.0f);
  74. (*decition)->brake = controlBrake;
  75. (*decition)->torque= controlSpeed;
  76. lastTorque=(*decition)->torque;
  77. (*decition)->grade=1;
  78. (*decition)->mode=1;
  79. (*decition)->speak=0;
  80. (*decition)->handBrake=0;
  81. (*decition)->bright=false;
  82. (*decition)->engine=0;
  83. if(ServiceCarStatus.bocheMode){
  84. (*decition)->dangWei=2;
  85. }else{
  86. (*decition)->dangWei=1;
  87. }
  88. (*decition)->wheel_angle=max((float)-500.0,float((*decition)->wheel_angle+ServiceCarStatus.mfEPSOff));
  89. (*decition)->wheel_angle=min((float)500.0,(*decition)->wheel_angle);
  90. (*decition)->air_enable=true;
  91. return *decition;
  92. }
  93. float iv::decition::Ge3Adapter::limitBrake(float realSpeed, float controlBrake,float dSpeed,float obsDistance , float ttc){
  94. //刹车限制
  95. int BrakeIntMax = 0;
  96. if (realSpeed < 10.0 / 3.6) BrakeIntMax = 40;
  97. else if (realSpeed < 20.0 / 3.6) BrakeIntMax = 60;
  98. else BrakeIntMax = 100;
  99. if (controlBrake > BrakeIntMax) controlBrake = BrakeIntMax;
  100. if ((obsDistance>0 && obsDistance < 6) || dSpeed == 0)
  101. {
  102. controlBrake = max(30.0f, controlBrake);
  103. }
  104. if (obsDistance>0 && obsDistance<10&&obsDistance>0)
  105. {
  106. controlBrake = max(20.0f, controlBrake);
  107. }
  108. if (obsDistance<10&&obsDistance>0 &&ttc<8)
  109. {
  110. controlBrake = max(30.0f, controlBrake);
  111. }
  112. if (obsDistance<10&&obsDistance>0 &&ttc<5)
  113. {
  114. controlBrake = max(40.0f, controlBrake);
  115. }
  116. if (obsDistance<10&&obsDistance>0 &&ttc<1.6)
  117. {
  118. controlBrake = max(60.0f, controlBrake);
  119. }
  120. if(obsDistance<5 && obsDistance>0 ){
  121. controlBrake = max(60.0f, controlBrake);
  122. }
  123. if(obsDistance<5 && obsDistance>0 &&ttc<8){
  124. controlBrake = max(80.0f, controlBrake);
  125. }
  126. controlBrake=min(100.0f,controlBrake);
  127. return controlBrake;
  128. }
  129. float iv::decition::Ge3Adapter::limitSpeed(float realSpeed, float controlBrake,float dSpeed,float controlSpeed ){
  130. if(controlBrake>0){
  131. controlSpeed=0;
  132. }
  133. if(realSpeed<10){
  134. controlSpeed=min((float)400.0,controlSpeed);
  135. }else if(realSpeed<30){
  136. controlSpeed =min((float)600.0,controlSpeed);
  137. }
  138. if(controlSpeed>0){
  139. if(controlSpeed>lastTorque){
  140. controlSpeed=min(float(lastTorque+5.0),controlSpeed);
  141. }
  142. }
  143. if(dSpeed <= 3)
  144. {
  145. controlSpeed = min(controlSpeed,20.0f);
  146. }
  147. controlSpeed=min((float)1200.0,controlSpeed);
  148. controlSpeed=max((float)0.0,controlSpeed);
  149. return controlSpeed;
  150. }