Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pid calculation and obtaining, also setting of pid parameters

  • Loading branch information...
commit 4a6b7402164b86dca7b2606c3e6b61d700de1210 1 parent b2f1fe9
Bernhard Kubicek authored

Showing 4 changed files with 88 additions and 4 deletions. Show diff stats Hide diff stats

  1. +18 0 mainwindow.cpp
  2. +3 0  mainwindow.h
  3. +59 1 tab_pid.cpp
  4. +8 3 tab_pid.h
18 mainwindow.cpp
@@ -171,6 +171,14 @@ void MainWindow::clickedConnect()
171 171 QTimer *timer = new QTimer(this);
172 172 connect(timer, SIGNAL(timeout()), this, SLOT(measure()));
173 173 timer->start(1000);
  174 + send("M301\n");
  175 +
  176 + connect(tabPID,SIGNAL(pidChanged()),this, SLOT(sendPID()));
  177 + connect(tabPID->pids[0],SIGNAL(returnPressed()),this, SLOT(sendPID()));
  178 + connect(tabPID->pids[1],SIGNAL(returnPressed()),this, SLOT(sendPID()));
  179 + connect(tabPID->pids[2],SIGNAL(returnPressed()),this, SLOT(sendPID()));
  180 + connect(tabPID->pids[3],SIGNAL(returnPressed()),this, SLOT(sendPID()));
  181 + connect(tabPID->btLoad,SIGNAL(clicked()),this, SLOT(getPID()));
174 182
175 183 }
176 184
@@ -309,3 +317,13 @@ void MainWindow::setHotend1Temp()
309 317 {
310 318 send(QString("M104 S%1\n").arg(tabPID->temp[hotend1]->text()));
311 319 }
  320 +
  321 +void MainWindow::sendPID()
  322 +{
  323 + send(QString("M301 P%1 I%2 D%3 C%4\n").arg(tabPID->pids[0]->text()).arg(tabPID->pids[1]->text()).arg(tabPID->pids[2]->text()).arg(tabPID->pids[3]->text()));
  324 +}
  325 +
  326 +void MainWindow::getPID()
  327 +{
  328 + send(QString("M301\n"));
  329 +}
3  mainwindow.h
@@ -47,6 +47,9 @@ public slots:
47 47 void manualSend();
48 48 void measure();
49 49 void setHotend1Temp();
  50 +
  51 + void sendPID();
  52 + void getPID();
50 53 //void quit();
51 54
52 55
60 tab_pid.cpp
@@ -87,12 +87,24 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
87 87 gb2g->addWidget(pids[2]=new QLineEdit("0"),2,1);
88 88 gb2g->addWidget(new QLabel("Extruder speed prop:"),3,0);
89 89 gb2g->addWidget(pids[3]=new QLineEdit("0"),3,1);
  90 + gb2g->addWidget(btLoad=new QPushButton("Load"),4,0);
90 91 gb2->setLayout(gb2g);
91 92 // pids[0]->setMaxLength(3);
92 93 // pids[1]->setMaxLength(3);
93 94 // pids[2]->setMaxLength(3);
94 95 // pids[3]->setMaxLength(3);
95 96
  97 + QGridLayout *gb3g=new QGridLayout;
  98 +
  99 + gb3g->addWidget(new QLabel("Critical prop. Gain:"),0,0);
  100 + gb3g->addWidget(eCriticalGain=new QLineEdit("0"),0,1);
  101 + gb3g->addWidget(btPeriod=new QPushButton("Period [sec]@critical:"),1,0);
  102 + gb3g->addWidget(ePeriod=new QLineEdit("0"),1,1);
  103 + gb3g->addWidget(cbZieglerDif=new QCheckBox("PI+D?"),2,0);
  104 + //gb3g->addWidget(pids[2]=new QLineEdit("0"),2,1);
  105 + gb3g->addWidget(btSet=new QPushButton("Set",this),3,0);
  106 + //gb3g->addWidget(pids[3]=new QLineEdit("0"),3,1);
  107 + gb3->setLayout(gb3g);
96 108
97 109 h1layout->addWidget(gb1);
98 110 h1layout->addWidget(gb2);
@@ -111,7 +123,11 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
111 123 setLayout(layout);
112 124
113 125
114   -
  126 + connect(btClear,SIGNAL(clicked(bool)),this,SLOT(clearClicked()));
  127 + connect(btPeriod,SIGNAL(clicked(bool)),this,SLOT(periodClicked()));
  128 + connect(btSet,SIGNAL(clicked(bool)),this,SLOT(setClicked()));
  129 + connect(btLoad,SIGNAL(clicked(bool)),this,SLOT(loadClicked()));
  130 +
115 131
116 132 }
117 133
@@ -198,3 +214,45 @@ void TabPID::startTime()
198 214 starttime= QTime::currentTime();
199 215 }
200 216
  217 +
  218 +void TabPID::clearClicked()
  219 +{
  220 + time.resize(0);
  221 + value_hotend1.resize(0);
  222 + value_bed.resize(0);
  223 + value_hotend2.resize(0);
  224 + value_heater.resize(0);
  225 +
  226 + target_hotend1.resize(0);
  227 + target_hotend2.resize(0);
  228 + target_bed.resize(0);
  229 +
  230 +}
  231 +
  232 +void TabPID::periodClicked()
  233 +{
  234 + ePeriod->setText(lPeriod->text());
  235 +}
  236 +
  237 +void TabPID::setClicked()
  238 +{
  239 + float ku=eCriticalGain->text().toFloat();
  240 + float t=ePeriod->text().toFloat();
  241 + float kp=0,ki=0,kd=0;
  242 + if(cbZieglerDif->isChecked())
  243 + { //PID
  244 + kp=0.6*ku;
  245 + ki=2.*kp/t;
  246 + kd=kp*t/8.;
  247 + }
  248 + else //PI only
  249 + {
  250 + kp=ku/2.2;
  251 + ki=1.2*kp/t;
  252 + kd=0;
  253 + }
  254 + pids[0]->setText(QString("%1").arg(kp));
  255 + pids[1]->setText(QString("%1").arg(ki));
  256 + pids[2]->setText(QString("%1").arg(kd));
  257 + emit pidChanged();
  258 +}
11 tab_pid.h
@@ -43,14 +43,19 @@ Q_OBJECT
43 43 QVector<double> target_hotend1,target_hotend2,target_bed;
44 44 QTime starttime;
45 45 QCheckBox *differential;
46   - QPushButton *btClear;
  46 + QPushButton *btClear, *btPeriod, *btSet,*btLoad;
47 47 QLabel *lPeriod;
  48 + QLineEdit *ePeriod,*eCriticalGain;
  49 + QCheckBox *cbZieglerDif;
48 50
49 51 public slots:
50 52 //void setWasRead();
51 53 //void quit();
52   -
53   -
  54 + void clearClicked();
  55 + void periodClicked();
  56 + void setClicked();
  57 +signals:
  58 + void pidChanged();
54 59 private:
55 60 QPushButton *test;
56 61 };

0 comments on commit 4a6b740

Please sign in to comment.
Something went wrong with that request. Please try again.