hapo_adapter.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #include <adc_adapter/hapo_adapter.h>
  2. #include <common/constants.h>
  3. #include <common/car_status.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <QTime>
  8. QTime doorOpenTime;
  9. using namespace std;
  10. iv::decition::HapoAdapter::HapoAdapter(){
  11. adapter_id=5;
  12. adapter_name="hapo";
  13. }
  14. iv::decition::HapoAdapter::~HapoAdapter(){
  15. }
  16. #include "ivlog.h"
  17. extern iv::Ivlog * givlog;
  18. iv::decition::Decition iv::decition::HapoAdapter::getAdapterDeciton(GPS_INS now_gps_ins, std::vector<Point2D> trace , float dSpeed, float obsDistance ,
  19. float obsSpeed,float accAim,float accNow ,bool changingDangWei,Decition *decition){
  20. accAim=min(0.7f,accAim);
  21. float controlSpeed=0;
  22. float controlBrake=0;
  23. float u = 0- accAim;
  24. float realSpeed = now_gps_ins.speed;
  25. float ttc = 0-(obsDistance/obsSpeed);
  26. bool turn_around=false;
  27. if(now_gps_ins.roadMode==14||now_gps_ins.roadMode==15||now_gps_ins.roadMode==16||now_gps_ins.roadMode==17){
  28. turn_around=true;
  29. }
  30. if(ttc<0){
  31. ttc=15;
  32. }
  33. if (accAim < 0)
  34. {
  35. controlSpeed=0;
  36. controlBrake=u; //102
  37. if(obsDistance>0 && obsDistance<6){
  38. controlBrake= u*1.5;
  39. }
  40. if(abs(dSpeed-realSpeed)<3 &&(obsDistance>40 || obsDistance<0)&&ttc>5 && dSpeed>0 && turn_around
  41. && dSpeed>0 && lastBrake==0){
  42. controlBrake=0;
  43. controlSpeed=0;
  44. }else if(abs(realSpeed)<15 &&(obsDistance>40 || obsDistance<0)&&ttc>5 && dSpeed>0 && turn_around){
  45. controlBrake=min(controlBrake,0.5f);
  46. controlSpeed=0;
  47. }
  48. else if(abs(dSpeed-realSpeed)>=5 &&abs(dSpeed-realSpeed)<10&&(obsDistance>40 || obsDistance<0)&&ttc>5
  49. && !turn_around ){
  50. controlBrake=min(controlBrake,0.3f);
  51. controlSpeed=0;
  52. }
  53. else if(abs(dSpeed-realSpeed)>=10 &&abs(dSpeed-realSpeed)<15&&(obsDistance>40 || obsDistance<0)&&ttc>5
  54. && dSpeed>0 && !turn_around ){
  55. controlBrake=min(controlBrake,0.5f);
  56. controlSpeed=0;
  57. }
  58. else if(abs(dSpeed-realSpeed)<3 &&(obsDistance>40 || obsDistance<0)&&ttc>=15
  59. && dSpeed>0 && !turn_around ){
  60. controlBrake=0;
  61. controlSpeed= 2.0* (realSpeed/15.0);
  62. }
  63. //0110
  64. if(changingDangWei){
  65. controlBrake=max(0.5f,controlBrake);
  66. }
  67. //斜坡刹车加大 lsn 0217
  68. if (abs(now_gps_ins.ins_pitch_angle)>2.5 &&(controlBrake>0||dSpeed==0)){
  69. controlBrake=max(2.0f,controlBrake);
  70. }
  71. //斜坡刹车加大 end
  72. }
  73. else
  74. {
  75. controlBrake = 0;
  76. if(ServiceCarStatus.torque_st==0){
  77. controlSpeed = (u*(-16)+((0-u)-ServiceCarStatus.mfCalAcc)*10)*0.7; //*1.0
  78. controlSpeed =min( controlSpeed,2.0f);
  79. controlSpeed =max( controlSpeed,1.0f);
  80. }else{
  81. controlSpeed= ServiceCarStatus.torque_st+((0-u)-ServiceCarStatus.mfCalAcc)*20;//1115 *10
  82. }
  83. // if(((gpsIns.ins_pitch_angle>-2.5 && ServiceCarStatus.daocheMode)||
  84. // (gpsIns.ins_pitch_angle<2.5 && !ServiceCarStatus.daocheMode))){
  85. // if(realSpeed<5 ){
  86. // controlSpeed=min((float)25.0,controlSpeed); //youmenxianxiao 30
  87. // }else if(realSpeed<10){
  88. // controlSpeed=min((float)25.0,controlSpeed); //40
  89. // }
  90. // }
  91. // controlSpeed = min((float)(ServiceCarStatus.torque_st+1.0),controlSpeed); //1115 5.0
  92. // if(accAim>0 && ServiceCarStatus.mfCalAcc>0 && realSpeed>1 ){
  93. // if(controlSpeed>0){
  94. // controlSpeed = ServiceCarStatus.torque_st;
  95. // }
  96. // }else if(accAim<0 && ServiceCarStatus.mfCalAcc<0 && dSpeed>0){
  97. // if(controlSpeed>0 ){
  98. // controlSpeed = ServiceCarStatus.torque_st;
  99. // }
  100. // }
  101. if(controlSpeed>ServiceCarStatus.torque_st){
  102. controlSpeed = min(ServiceCarStatus.torque_st+2.0f,controlSpeed);
  103. }else if(controlSpeed<ServiceCarStatus.torque_st){
  104. controlSpeed = ServiceCarStatus.torque_st-1.0f;
  105. }
  106. //Seizing
  107. if((ServiceCarStatus.torque_st==controlSpeed-1)&&dSpeed>1){
  108. seizingCount++;
  109. }else{
  110. seizingCount=0;
  111. }
  112. if(seizingCount>=10){
  113. controlSpeed=ServiceCarStatus.torque_st+2;
  114. }
  115. if(controlSpeed==2.0 && ServiceCarStatus.torque_st<2){
  116. controlSpeed=2.4;
  117. }
  118. //seizing end
  119. // 斜坡加大油门 0217 lsn
  120. // if(((now_gps_ins.ins_pitch_angle<-2.5 && ServiceCarStatus.daocheMode)||
  121. // (now_gps_ins.ins_pitch_angle>2.5 && !ServiceCarStatus.daocheMode))
  122. // && abs(realSpeed)<1.0){
  123. // controlSpeed=max((float)20.0,controlSpeed);
  124. // controlSpeed=min((float)40.0,controlSpeed);
  125. // }
  126. // 斜坡加大油门 end
  127. // else if(((now_gps_ins.ins_pitch_angle<-2.5 && ServiceCarStatus.daocheMode)||
  128. // (now_gps_ins.ins_pitch_angle>2.5 && !ServiceCarStatus.daocheMode))
  129. // && abs(realSpeed)<10.0){
  130. // controlSpeed=min((float)25.0,controlSpeed); //youmenxianxiao 30
  131. // }
  132. }
  133. //0125
  134. if(controlSpeed>0){
  135. controlSpeed=max(controlSpeed,2.4f);
  136. }
  137. //0227 10m nei xianzhi shache
  138. if(obsDistance<6 &&obsDistance>0){
  139. controlSpeed=0;
  140. controlBrake=max(controlBrake,0.8f);
  141. }
  142. // if(DecideGps00::minDecelerate<0){
  143. // controlBrake = max((0-DecideGps00::minDecelerate),controlBrake);
  144. // controlSpeed=0;
  145. // }
  146. if(minDecelerate<0){
  147. controlBrake = max((0-minDecelerate),controlBrake);
  148. controlSpeed=0;
  149. }
  150. controlBrake=limitBrake(realSpeed,controlBrake,dSpeed,obsDistance,ttc);
  151. controlSpeed = limitSpeed(realSpeed, controlBrake, dSpeed, controlSpeed);
  152. // (*decition)->brake = controlBrake*10;
  153. (*decition)->brake = controlBrake*6;
  154. (*decition)->torque=controlSpeed;
  155. lastBrake= (*decition)->brake;
  156. lastTorque=(*decition)->torque;
  157. (*decition)->grade=1;
  158. (*decition)->mode=1;
  159. (*decition)->speak=0;
  160. (*decition)->handBrake=1; // 0: laqi 1: shifang
  161. (*decition)->bright=false;
  162. (*decition)->engine=0;
  163. (*decition)->dangweiEnable=true;
  164. (*decition)->angleEnable=true;
  165. (*decition)->speedEnable=true;
  166. (*decition)-> brakeEnable=true;
  167. (*decition)->air_enable=false;
  168. (*decition)->driveMode=1;
  169. (*decition)->brakeType=0;
  170. (*decition)->angSpeed=60;
  171. (*decition)->topLight=0;
  172. if(ServiceCarStatus.bocheMode ||ServiceCarStatus.daocheMode){
  173. (*decition)->dangWei=2;
  174. (*decition)->backLight=1;
  175. }
  176. //1220
  177. else{
  178. (*decition)->dangWei=4;
  179. (*decition)->backLight=0;
  180. }
  181. if((*decition)->brake>0){
  182. (*decition)->brakeLight=1;
  183. }else{
  184. (*decition)->brakeLight=0;
  185. }
  186. if((*decition)->leftlamp){
  187. (*decition)->directLight=1;
  188. }else if((*decition)->rightlamp){
  189. (*decition)->directLight=2;
  190. }else{
  191. (*decition)->directLight=0;
  192. }
  193. (*decition)->handBrake=false;
  194. (*decition)->wheel_angle+=ServiceCarStatus.mfEPSOff;
  195. (*decition)->wheel_angle=max((float)-870.0,(*decition)->wheel_angle);
  196. (*decition)->wheel_angle=min((float)870.0,(*decition)->wheel_angle);
  197. //dangweiTrasfer
  198. // if((decition_gps->dangWei!=ServiceCarStatus.dangwei_st && ServiceCarStatus.dangwei_st!=0)){
  199. // decition_gps->dangWei=2;
  200. // decition_gps->torque=0;
  201. // }
  202. lastDangWei= (*decition)->dangWei;
  203. (*decition)->topLight=0; //1116
  204. (*decition)->nearLight=0;
  205. (*decition)->farLight=0;
  206. if(ServiceCarStatus.stationCmd.mode_manual_drive==true)
  207. {
  208. (*decition)->mode=0;
  209. }
  210. if(ServiceCarStatus.station_control_door==0)
  211. {
  212. (*decition)->door=false; //CLOSE
  213. doorOpenTime.start();
  214. givlog->debug("DOOR","STATUS is: %d",5);
  215. }else if((ServiceCarStatus.station_control_door==1)&&(ServiceCarStatus.station_control_door_option==false))
  216. {
  217. (*decition)->door=true; //OPEN
  218. (*decition)->brake =6;
  219. (*decition)->torque=0;
  220. if(doorOpenTime.elapsed()>6000)
  221. {
  222. ServiceCarStatus.station_control_door_option=true;
  223. givlog->debug("DOOR","STATUS is: %d",8);
  224. }
  225. }
  226. givlog->debug("DOOR","door is: %d",(*decition)->door);
  227. givlog->debug("DOOR","station_control_door is: %d",ServiceCarStatus.station_control_door);
  228. std::cout<<"==========================================="<<std::endl;
  229. std::cout<<"dSpeed:"<<dSpeed<<" realSpeed:"<<realSpeed<<" acc:"<<accAim<<" torque_st:"<<ServiceCarStatus.torque_st
  230. <<" decideTorque:"<<(*decition)->torque <<" decideBrake:"<<(*decition)->brake
  231. <<std::endl;
  232. std::cout<<"========================================="<<std::endl;
  233. (*decition)->accelerator= (*decition)->torque ;
  234. givlog->debug("obs_distance","dSpeed: %f, realSpeed: %f, brake: %f",
  235. dSpeed, realSpeed,(*decition)->brake);
  236. return *decition;
  237. }
  238. float iv::decition::HapoAdapter::limitBrake(float realSpeed, float controlBrake,float dSpeed,float obsDistance , float ttc){
  239. //刹车限制
  240. //刹车限制
  241. float vs =realSpeed*3.6;
  242. int BrakeIntMax = 10;
  243. if (vs < 10.0 / 3.6) BrakeIntMax = 4;
  244. else if (vs < 20.0 / 3.6) BrakeIntMax = 6;
  245. //`
  246. if(ttc>10){
  247. BrakeIntMax = 2;
  248. }else if(ttc>6){
  249. BrakeIntMax = 3;
  250. }else if(ttc>3){
  251. BrakeIntMax = 4;
  252. }else {
  253. BrakeIntMax = 5;
  254. }
  255. if(obsDistance>0 && obsDistance<10){
  256. BrakeIntMax=max(BrakeIntMax,3);
  257. }
  258. if (controlBrake > BrakeIntMax) controlBrake = BrakeIntMax;
  259. controlBrake=min(5.0f,controlBrake);
  260. controlBrake=max(0.0f,controlBrake);
  261. return controlBrake;
  262. }
  263. float iv::decition::HapoAdapter::limitSpeed(float realSpeed, float controlBrake,float dSpeed,float controlSpeed ){
  264. controlSpeed=min((float)100.0,controlSpeed);
  265. controlSpeed=max((float)0.0,controlSpeed);
  266. return controlSpeed;
  267. }