mainwindow.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QFile>
  4. MainWindow::MainWindow(QWidget *parent)
  5. : QMainWindow(parent)
  6. , ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. ui->horizontalSlider_vel->setRange(0,1000);
  10. ui->horizontalSlider_acc->setRange(0,1000);
  11. ui->horizontalSlider_acc->setValue(500);
  12. ui->horizontalSlider_vel->setValue(0);
  13. std::vector<std::tuple<double, double, double>> xvectortable_torque,xvectortable_brake;
  14. QFile xFile;
  15. xFile.setFileName("velacctable.txt");
  16. if(xFile.open(QIODevice::ReadOnly))
  17. {
  18. QByteArray ba = xFile.readAll();
  19. QString strba;
  20. strba.append(ba);
  21. QStringList strlinelist =strba.split("\n");// strba.split(QRegExp("[\t ;]+"));
  22. int nline = strlinelist.size();
  23. int i;
  24. for(i=0;i<nline;i++)
  25. {
  26. QString str = strlinelist.at(i);
  27. QStringList strvaluelist = str.split(QRegExp("[\t ;]+"));
  28. if(strvaluelist.size()>=4)
  29. {
  30. double vel,acc,torque,brake;
  31. vel = QString(strvaluelist.at(0)).toDouble();
  32. acc = QString(strvaluelist.at(1)).toDouble();
  33. torque = QString(strvaluelist.at(2)).toDouble();
  34. brake = QString(strvaluelist.at(3)).toDouble();
  35. xvectortable_torque.push_back(std::make_tuple(vel,acc,torque));
  36. xvectortable_brake.push_back(std::make_tuple(vel,acc,brake));
  37. }
  38. }
  39. }
  40. xFile.close();
  41. if(xvectortable_torque.size()>0)
  42. {
  43. mInterpolation2D_torque.Init(xvectortable_torque);
  44. mInterpolation2D_brake.Init(xvectortable_brake);
  45. mbInterpolation2DOK = true;
  46. }
  47. }
  48. MainWindow::~MainWindow()
  49. {
  50. delete ui;
  51. }
  52. void MainWindow::on_horizontalSlider_vel_valueChanged(int value)
  53. {
  54. double fvalue = value;
  55. fvalue = fvalue * 0.1;
  56. ui->lineEdit_vel->setText(QString::number(fvalue));
  57. updateinterp();
  58. }
  59. void MainWindow::on_horizontalSlider_acc_valueChanged(int value)
  60. {
  61. double fvalue = value;
  62. fvalue = (fvalue - 500)/50.0;
  63. ui->lineEdit_acc->setText(QString::number(fvalue));
  64. updateinterp();
  65. }
  66. void MainWindow::updateinterp()
  67. {
  68. double fvel = ui->horizontalSlider_vel->value();
  69. fvel = fvel*0.1;
  70. double facc = ui->horizontalSlider_acc->value();
  71. facc = (facc -500)/50.0;
  72. double ftorque,fbrake;
  73. if(mbInterpolation2DOK)
  74. {
  75. ftorque = mInterpolation2D_torque.Interpolate(std::make_pair(fvel,facc));
  76. fbrake = mInterpolation2D_brake.Interpolate(std::make_pair(fvel,facc));
  77. ui->lineEdit_torque->setText(QString::number(ftorque,'f',3));
  78. ui->lineEdit_brake->setText(QString::number(fbrake,'f',3));
  79. }
  80. }