12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QFile>
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- ui->horizontalSlider_vel->setRange(0,1000);
- ui->horizontalSlider_acc->setRange(0,1000);
- ui->horizontalSlider_acc->setValue(500);
- ui->horizontalSlider_vel->setValue(0);
- 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);
- 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()>0)
- {
- mInterpolation2D_torque.Init(xvectortable_torque);
- mInterpolation2D_brake.Init(xvectortable_brake);
- mbInterpolation2DOK = true;
- }
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_horizontalSlider_vel_valueChanged(int value)
- {
- double fvalue = value;
- fvalue = fvalue * 0.1;
- ui->lineEdit_vel->setText(QString::number(fvalue));
- updateinterp();
- }
- void MainWindow::on_horizontalSlider_acc_valueChanged(int value)
- {
- double fvalue = value;
- fvalue = (fvalue - 500)/50.0;
- ui->lineEdit_acc->setText(QString::number(fvalue));
- updateinterp();
- }
- void MainWindow::updateinterp()
- {
- double fvel = ui->horizontalSlider_vel->value();
- fvel = fvel*0.1;
- double facc = ui->horizontalSlider_acc->value();
- facc = (facc -500)/50.0;
- double ftorque,fbrake;
- if(mbInterpolation2DOK)
- {
- ftorque = mInterpolation2D_torque.Interpolate(std::make_pair(fvel,facc));
- fbrake = mInterpolation2D_brake.Interpolate(std::make_pair(fvel,facc));
- ui->lineEdit_torque->setText(QString::number(ftorque,'f',3));
- ui->lineEdit_brake->setText(QString::number(fbrake,'f',3));
- }
- }
|