zhongche_adapter.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #include <adc_adapter/zhongche_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::ZhongcheAdapter::ZhongcheAdapter(){
  9. adapter_id= 3;
  10. adapter_name="zhongche";
  11. }
  12. iv::decition::ZhongcheAdapter::~ZhongcheAdapter(){
  13. }
  14. iv::decition::Decition iv::decition::ZhongcheAdapter::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. (*decition)->grade=1;
  29. (*decition)->mode=1;
  30. (*decition)->speak=0;
  31. (*decition)->handBrake=0;
  32. (*decition)->bright=false;
  33. (*decition)->engine=0;
  34. (*decition)->brakeLight=0;
  35. if(ServiceCarStatus.bocheMode){
  36. (*decition)->dangWei=2;
  37. }else{
  38. (*decition)->dangWei=1;
  39. }
  40. if(ttc>10 && (obsDistance>10||obsDistance<0)){
  41. // if(DecideGps00::minDecelerate<0){
  42. // (*decition)->torque = 0;
  43. // (*decition)->brake = max((0-DecideGps00::minDecelerate)*90, (*decition)->brake);
  44. // dSpeed=10.0;
  45. // }else{
  46. // (*decition)->torque=90;
  47. // (*decition)->brake=0;
  48. // }
  49. if(minDecelerate<0){
  50. (*decition)->torque = 0;
  51. (*decition)->brake = max((0-minDecelerate)*90, (*decition)->brake);
  52. dSpeed=10.0;
  53. }else{
  54. (*decition)->torque=90;
  55. (*decition)->brake=0;
  56. }
  57. dSpeed=max(0.0f,dSpeed);
  58. dSpeed=min(10.0f, dSpeed);
  59. (*decition)->speed=(int)dSpeed*10+5;
  60. (*decition)->torque=min((float)100.0,(*decition)->torque);
  61. (*decition)->torque=max((float)0.0,(*decition)->torque);
  62. (*decition)->brake=min((float)100.0,(*decition)->brake);
  63. (*decition)->brake=max((float)0.0,(*decition)->brake);
  64. lastTorque=(*decition)->torque;
  65. (*decition)->wheel_angle+=ServiceCarStatus.mfEPSOff;
  66. (*decition)->wheel_angle=max((float)-550.0,(*decition)->wheel_angle);
  67. (*decition)->wheel_angle=min((float)550.0,(*decition)->wheel_angle);
  68. return *decition;
  69. }
  70. if (accAim < 0)
  71. {
  72. if(obsDistance<10 && obsDistance>0 &&ttc>3){
  73. controlBrake = (int)(u * 40.0) + 1; //(u * 14.0) + 1;
  74. } else{
  75. if(ttc<3){
  76. controlBrake = (int)(u * 60.0) + 1; //(u * 14.0) + 1;
  77. }
  78. else if(ttc<5){
  79. controlBrake = (int)(u * 40.0) + 1; //(u * 14.0) + 1;
  80. }else {
  81. controlBrake = (int)(u * 20.0) + 1; //(u * 14.0) + 1;
  82. }
  83. }
  84. (*decition)->brake = controlBrake;
  85. (*decition)->torque=0;
  86. }
  87. else
  88. {
  89. controlBrake = 0;
  90. (*decition)->brake=0;
  91. if(lastTorque==0){
  92. (*decition)->torque = u*(-30)+((0-u)-ServiceCarStatus.mfCalAcc)*1+
  93. now_gps_ins.ins_pitch_angle*10;
  94. }else{
  95. (*decition)->torque = lastTorque+((0-u)-ServiceCarStatus.mfCalAcc)*10;
  96. }
  97. if(realSpeed<10){
  98. (*decition)->torque=min((float)40.0,(*decition)->torque);
  99. }else if(realSpeed<30){
  100. (*decition)->torque=min((float)60.0,(*decition)->torque);
  101. }
  102. (*decition)->torque=min((float)99.0,(*decition)->torque);
  103. (*decition)->torque=max((float)0.0,(*decition)->torque);
  104. }
  105. //0227 10m nei xianzhi shache
  106. if(obsDistance<10 &&obsDistance>0){
  107. (*decition)->torque=0;
  108. (*decition)->brake=max((float)30.0,(*decition)->brake);
  109. }
  110. // if(DecideGps00::minDecelerate<0){
  111. // dSpeed=10;
  112. // (*decition)->torque = 0;
  113. // (*decition)->brake = min((0-DecideGps00::minDecelerate)*90, (*decition)->brake);
  114. // }
  115. if(minDecelerate<0){
  116. dSpeed=10;
  117. (*decition)->torque = 0;
  118. (*decition)->brake = min((0-minDecelerate)*90, (*decition)->brake);
  119. }
  120. (*decition)->torque=min((float)100.0,(*decition)->torque);
  121. (*decition)->torque=max((float)0.0,(*decition)->torque);
  122. (*decition)->brake=min((float)100.0,(*decition)->brake);
  123. (*decition)->brake=max((float)0.0,(*decition)->brake);
  124. lastTorque=(*decition)->torque;
  125. (*decition)->wheel_angle+=ServiceCarStatus.mfEPSOff;
  126. (*decition)->wheel_angle=max((float)-550.0,(*decition)->wheel_angle);
  127. (*decition)->wheel_angle=min((float)550.0,(*decition)->wheel_angle);
  128. dSpeed=max(0.0f,dSpeed);
  129. dSpeed=min(10.0f, dSpeed);
  130. (*decition)->speed=(int)dSpeed*10+5;
  131. std::cout<<"==========================================="<<std::endl;
  132. std::cout<<"dSpeed:"<<dSpeed<<" realSpeed:"<<realSpeed<<" acc:"<<accAim
  133. <<std::endl;
  134. std::cout<<"========================================="<<std::endl;
  135. return *decition;
  136. }