lookuptable.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "lookuptable.h"
  2. LookupTable::LookupTable()
  3. {
  4. std::vector<std::tuple<double, double, double>> xvectortable_torque,xvectortable_brake;
  5. QFile xFile;
  6. xFile.setFileName("velacctable.txt");
  7. if(xFile.open(QIODevice::ReadOnly))
  8. {
  9. QByteArray ba = xFile.readAll();
  10. QString strba;
  11. strba.append(ba);
  12. QStringList strlinelist =strba.split("\n");// strba.split(QRegExp("[\t ;]+"));
  13. int nline = strlinelist.size();
  14. int i;
  15. for(i=0;i<nline;i++)
  16. {
  17. QString str = strlinelist.at(i);
  18. str = str.trimmed();
  19. QStringList strvaluelist = str.split(QRegExp("[\t ;]+"));
  20. if(strvaluelist.size()>=4)
  21. {
  22. double vel,acc,torque,brake;
  23. vel = QString(strvaluelist.at(0)).toDouble();
  24. acc = QString(strvaluelist.at(1)).toDouble();
  25. torque = QString(strvaluelist.at(2)).toDouble();
  26. brake = QString(strvaluelist.at(3)).toDouble();
  27. xvectortable_torque.push_back(std::make_tuple(vel,acc,torque));
  28. xvectortable_brake.push_back(std::make_tuple(vel,acc,brake));
  29. }
  30. }
  31. }
  32. xFile.close();
  33. if(xvectortable_torque.size()>=4)
  34. {
  35. mInterpolation2D_torque.Init(xvectortable_torque);
  36. mInterpolation2D_brake.Init(xvectortable_brake);
  37. mbInterpolation2DOK = true;
  38. }
  39. }
  40. int LookupTable::GetTorqueBrake(double fVeh,double fAcc,double & fTorque, double & fBrake)
  41. {
  42. if(mbInterpolation2DOK == false)return -1;
  43. fTorque = mInterpolation2D_torque.Interpolate(std::make_pair(fVeh,fAcc));
  44. fBrake = mInterpolation2D_brake.Interpolate(std::make_pair(fVeh,fAcc));
  45. return 0;
  46. }
  47. bool LookupTable::IsINterpolationOK()
  48. {
  49. return mbInterpolation2DOK;
  50. }