qingyuan_adapter.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #include <adc_adapter/qingyuan_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::QingYuanAdapter::QingYuanAdapter(){
  9. adapter_id=1;
  10. adapter_name="qingyuan";
  11. }
  12. iv::decition::QingYuanAdapter::~QingYuanAdapter(){
  13. }
  14. iv::decition::Decition iv::decition::QingYuanAdapter::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 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. controlSpeed=0;
  31. controlBrake=u; //102
  32. if(obsDistance>0 && obsDistance<10){
  33. controlBrake= u*1.5;
  34. }
  35. if(abs(dSpeed-realSpeed)<3 &&(obsDistance>40 || obsDistance<0)&&ttc>8 && dSpeed>0 && !turn_around){
  36. controlBrake=0;
  37. controlSpeed=max(0.0,ServiceCarStatus.torque_st-10.0);
  38. }else if(abs(dSpeed-realSpeed)<3 &&(obsDistance>40 || obsDistance<0)&&ttc>8 && dSpeed>0 && turn_around){
  39. controlBrake=0;
  40. controlSpeed=0;
  41. }else if(abs(realSpeed)<15 &&(obsDistance>40 || obsDistance<0)&&ttc>8 && dSpeed>0 && turn_around){
  42. controlBrake=min(controlBrake,0.5f);
  43. controlSpeed=0;
  44. }
  45. else if(abs(dSpeed-realSpeed)>=3 &&abs(dSpeed-realSpeed)<5&&(obsDistance>40 || obsDistance<0)&&ttc>8
  46. && dSpeed>0 && !turn_around ){
  47. controlBrake=0;
  48. controlSpeed=0;
  49. }else if(abs(dSpeed-realSpeed)>=5 &&abs(dSpeed-realSpeed)<10&&(obsDistance>40 || obsDistance<0)&&ttc>8
  50. && dSpeed>0 && !turn_around ){
  51. controlBrake=min(controlBrake,0.3f);
  52. controlSpeed=0;
  53. }
  54. else if(abs(dSpeed-realSpeed)>=10 &&abs(dSpeed-realSpeed)<15&&(obsDistance>40 || obsDistance<0)&&ttc>8
  55. && dSpeed>0 && !turn_around ){
  56. controlBrake=min(controlBrake,0.5f);
  57. controlSpeed=0;
  58. }
  59. //0110
  60. if(changingDangWei){
  61. controlBrake=max(0.5f,controlBrake);
  62. }
  63. //斜坡刹车加大 lsn 0217
  64. if (abs(now_gps_ins.ins_pitch_angle)>2.5 &&(controlBrake>0||dSpeed==0)){
  65. controlBrake=max(2.0f,controlBrake);
  66. }
  67. //斜坡刹车加大 end
  68. }
  69. else
  70. {
  71. controlBrake = 0;
  72. if(ServiceCarStatus.torque_st==0){
  73. controlSpeed = (u*(-16)+((0-u)-ServiceCarStatus.mfCalAcc)*10)*0.7; //*1.0
  74. controlSpeed =min( controlSpeed,1.0f);
  75. }else{
  76. controlSpeed= ServiceCarStatus.torque_st+((0-u)-ServiceCarStatus.mfCalAcc)*10;//1115 *10
  77. }
  78. // if(((gpsIns.ins_pitch_angle>-2.5 && ServiceCarStatus.daocheMode)||
  79. // (gpsIns.ins_pitch_angle<2.5 && !ServiceCarStatus.daocheMode))){
  80. // if(realSpeed<5 ){
  81. // controlSpeed=min((float)25.0,controlSpeed); //youmenxianxiao 30
  82. // }else if(realSpeed<10){
  83. // controlSpeed=min((float)25.0,controlSpeed); //40
  84. // }
  85. // }
  86. // controlSpeed = min((float)(ServiceCarStatus.torque_st+1.0),controlSpeed); //1115 5.0
  87. if(controlSpeed>ServiceCarStatus.torque_st){
  88. controlSpeed = ServiceCarStatus.torque_st+1.0;
  89. }else if(controlSpeed<ServiceCarStatus.torque_st){
  90. controlSpeed = ServiceCarStatus.torque_st-1.0;
  91. }
  92. //Seizing
  93. if((ServiceCarStatus.torque_st==controlSpeed-1)&&dSpeed>1&&realSpeed<0.5){
  94. seizingCount++;
  95. }else{
  96. seizingCount=0;
  97. }
  98. if(seizingCount>=10){
  99. controlSpeed=ServiceCarStatus.torque_st+2;
  100. }
  101. //seizing end
  102. // 斜坡加大油门 0217 lsn
  103. if(((now_gps_ins.ins_pitch_angle<-2.5 && ServiceCarStatus.daocheMode)||
  104. (now_gps_ins.ins_pitch_angle>2.5 && !ServiceCarStatus.daocheMode))
  105. && abs(realSpeed)<1.0){
  106. controlSpeed=max((float)20.0,controlSpeed);
  107. controlSpeed=min((float)40.0,controlSpeed);
  108. }
  109. // 斜坡加大油门 end
  110. else if(((now_gps_ins.ins_pitch_angle<-2.5 && ServiceCarStatus.daocheMode)||
  111. (now_gps_ins.ins_pitch_angle>2.5 && !ServiceCarStatus.daocheMode))
  112. && abs(realSpeed)<10.0){
  113. controlSpeed=min((float)25.0,controlSpeed); //youmenxianxiao 30
  114. }
  115. }
  116. //0227 10m nei xianzhi shache
  117. if(obsDistance<10 &&obsDistance>0){
  118. controlSpeed=0;
  119. controlBrake=max(controlBrake,0.8f);
  120. }
  121. // if(DecideGps00::minDecelerate<0){
  122. // controlBrake = max((0-DecideGps00::minDecelerate),controlBrake);
  123. // controlSpeed=0;
  124. // }
  125. if(minDecelerate<0){
  126. controlBrake = max((0-minDecelerate),controlBrake);
  127. controlSpeed=0;
  128. }
  129. controlBrake=limitBrake(realSpeed,controlBrake,dSpeed,obsDistance,ttc);
  130. controlSpeed = limitSpeed(realSpeed, controlBrake, dSpeed, controlSpeed);
  131. (*decition)->brake = controlBrake;
  132. (*decition)->torque=controlSpeed;
  133. lastTorque=(*decition)->torque;
  134. (*decition)->grade=1;
  135. (*decition)->mode=1;
  136. (*decition)->speak=0;
  137. (*decition)->handBrake=1; // 0: laqi 1: shifang
  138. (*decition)->bright=false;
  139. (*decition)->engine=0;
  140. (*decition)->dangweiEnable=true;
  141. (*decition)->angleEnable=true;
  142. (*decition)->speedEnable=true;
  143. (*decition)-> brakeEnable=true;
  144. (*decition)->driveMode=1;
  145. (*decition)->brakeType=0;
  146. (*decition)->angSpeed=60;
  147. (*decition)->topLight=0;
  148. if(ServiceCarStatus.bocheMode ||ServiceCarStatus.daocheMode){
  149. (*decition)->dangWei=3;
  150. (*decition)->backLight=1;
  151. }
  152. //1220
  153. else{
  154. (*decition)->dangWei=4;
  155. (*decition)->backLight=0;
  156. }
  157. if((*decition)->brake>0){
  158. (*decition)->brakeLight=1;
  159. }else{
  160. (*decition)->brakeLight=0;
  161. }
  162. if((*decition)->leftlamp){
  163. (*decition)->directLight=1;
  164. }else if((*decition)->rightlamp){
  165. (*decition)->directLight=2;
  166. }else{
  167. (*decition)->directLight=0;
  168. }
  169. (*decition)->wheel_angle+=ServiceCarStatus.mfEPSOff;
  170. (*decition)->wheel_angle=max((float)-570.0,(*decition)->wheel_angle);
  171. (*decition)->wheel_angle=min((float)570.0,(*decition)->wheel_angle);
  172. //dangweiTrasfer
  173. // if((decition_gps->dangWei!=ServiceCarStatus.dangwei_st && ServiceCarStatus.dangwei_st!=0)){
  174. // decition_gps->dangWei=2;
  175. // decition_gps->torque=0;
  176. // }
  177. lastDangWei= (*decition)->dangWei;
  178. (*decition)->topLight=0; //1116
  179. (*decition)->nearLight=0;
  180. (*decition)->farLight=0;
  181. //(*decition)->door=3;
  182. std::cout<<"==========================================="<<std::endl;
  183. std::cout<<"dSpeed:"<<dSpeed<<" realSpeed:"<<realSpeed<<" acc:"<<accAim<<" torque_st:"<<ServiceCarStatus.torque_st
  184. <<" decideTorque:"<<(*decition)->torque
  185. <<std::endl;
  186. std::cout<<"========================================="<<std::endl;
  187. return *decition;
  188. }
  189. float iv::decition::QingYuanAdapter::limitBrake(float realSpeed, float controlBrake,float dSpeed,float obsDistance , float ttc){
  190. //刹车限制
  191. //刹车限制
  192. float vs =realSpeed*3.6;
  193. int BrakeIntMax = 10;
  194. if (vs < 10.0 / 3.6) BrakeIntMax = 4;
  195. else if (vs < 20.0 / 3.6) BrakeIntMax = 6;
  196. //`
  197. if(ttc>10){
  198. BrakeIntMax = 2;
  199. }else if(ttc>6){
  200. BrakeIntMax = 3;
  201. }else if(ttc>3){
  202. BrakeIntMax = 4;
  203. }else if(ttc>1.6){
  204. BrakeIntMax = 5;
  205. }else if(ttc>0.8){
  206. BrakeIntMax = 8;
  207. }else{
  208. BrakeIntMax = 10;
  209. }
  210. if(obsDistance>0 && obsDistance<10){
  211. BrakeIntMax=max(BrakeIntMax,3);
  212. }
  213. if (controlBrake > BrakeIntMax) controlBrake = BrakeIntMax;
  214. controlBrake=min(10.0f,controlBrake);
  215. controlBrake=max(0.0f,controlBrake);
  216. return controlBrake;
  217. }
  218. float iv::decition::QingYuanAdapter::limitSpeed(float realSpeed, float controlBrake,float dSpeed,float controlSpeed ){
  219. controlSpeed=min((float)100.0,controlSpeed);
  220. controlSpeed=max((float)0.0,controlSpeed);
  221. return controlSpeed;
  222. }