| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "lookuptable.h"
- LookupTable::LookupTable()
- {
- std::vector<std::tuple<double, double, double>> xvectortable_torque,xvectortable_brake;
- QFile xFile;
- xFile.setFileName("velacctable.txt");
- if(xFile.open(QIODevice::ReadOnly))
- {
- QByteArray ba = xFile.readAll();
- QString strba;
- strba.append(ba);
- QStringList strlinelist =strba.split("\n");// strba.split(QRegExp("[\t ;]+"));
- int nline = strlinelist.size();
- int i;
- for(i=0;i<nline;i++)
- {
- QString str = strlinelist.at(i);
- str = str.trimmed();
- QStringList strvaluelist = str.split(QRegExp("[\t ;]+"));
- if(strvaluelist.size()>=4)
- {
- double vel,acc,torque,brake;
- vel = QString(strvaluelist.at(0)).toDouble();
- acc = QString(strvaluelist.at(1)).toDouble();
- torque = QString(strvaluelist.at(2)).toDouble();
- brake = QString(strvaluelist.at(3)).toDouble();
- xvectortable_torque.push_back(std::make_tuple(vel,acc,torque));
- xvectortable_brake.push_back(std::make_tuple(vel,acc,brake));
- }
- }
- }
- xFile.close();
- if(xvectortable_torque.size()>=4)
- {
- mInterpolation2D_torque.Init(xvectortable_torque);
- mInterpolation2D_brake.Init(xvectortable_brake);
- mbInterpolation2DOK = true;
- }
- }
- int LookupTable::GetTorqueBrake(double fVeh,double fAcc,double & fTorque, double & fBrake)
- {
- if(mbInterpolation2DOK == false)return -1;
- fTorque = mInterpolation2D_torque.Interpolate(std::make_pair(fVeh,fAcc));
- fBrake = mInterpolation2D_brake.Interpolate(std::make_pair(fVeh,fAcc));
- return 0;
- }
- bool LookupTable::IsINterpolationOK()
- {
- return mbInterpolation2DOK;
- }
|