Permalink
Browse files

amplitude and ratio detection.

  • Loading branch information...
1 parent 8c2ebf3 commit 32085caa221ad2ccf64ca53a132b29b48a5bb5d3 @bkubicek committed Nov 12, 2011
Showing with 48 additions and 7 deletions.
  1. +4 −3 mainwindow.cpp
  2. +43 −3 tab_pid.cpp
  3. +1 −1 tab_pid.h
View
@@ -212,7 +212,7 @@ void MainWindow::clickedRefresh()
//
// }
// cout<<ss.str()<<endl;
-#define OSX_WORKAROUND
+//#define OSX_WORKAROUND
#ifndef OSX_WORKAROUND
this->m_sde = SerialDeviceEnumerator::instance();
//connect(this->m_sde, SIGNAL(hasChanged(QStringList)), this, SLOT(slotPrintAllDevices(QStringList)));
@@ -246,10 +246,10 @@ void MainWindow::clickedRefresh()
}
#else
QDir mydir("/dev/");
- QStringList list = mydir.entryList();
+ QStringList list = mydir.entryList(QDir::System);
foreach (QString s, list) {
if(s.startsWith("tty."))
- portSelector->addItem(s);
+ portSelector->addItem(QString("/dev/%1").arg(s));
}
#endif
@@ -264,6 +264,7 @@ void MainWindow::slotRead()
tabRaw->edit->insertPlainText(ba);
serialBuffer=serialBuffer+QString(ba);
int n=serialBuffer.lastIndexOf("\n");
+ if(n==-1) return; //not even a full line
QStringList lines = serialBuffer.mid(0,n).split("\n");
serialBuffer=serialBuffer.mid(n,sizeof(serialBuffer)-n);
foreach(QString s, lines)
View
@@ -119,6 +119,15 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
h2layout->addWidget(new QLabel("Period:"));
h2layout->addWidget(lPeriod=new QLabel("0"));
h2layout->addWidget(new QLabel(" sec"));
+
+ h2layout->addWidget(new QLabel("Amplitude:"));
+ h2layout->addWidget(lAmp=new QLabel("0"));
+ h2layout->addWidget(new QLabel("last Amplitude:"));
+ h2layout->addWidget(lAmpPrevious=new QLabel("0"));
+
+ h2layout->addWidget(new QLabel("ratio:"));
+ h2layout->addWidget(lAmpRatio=new QLabel("0"));
+
layout->addLayout(h2layout);
setLayout(layout);
@@ -137,7 +146,11 @@ void TabPID::addData(float t1, float b, float t2, float h)
QTime now=QTime::currentTime();
float dt=starttime.msecsTo(now);
time.push_back(dt);
- value_hotend1.push_back(t1);
+ if((fabs(t1-value_hotend1.last())<50)||(value_hotend1.size()<10))
+ value_hotend1.push_back(t1);
+ else
+ value_hotend1.push_back(value_hotend1.last()); //emergency measure, not sure why this is needed.
+
value_bed.push_back(b);
value_hotend2.push_back(t2);
value_heater.push_back(h/255.);
@@ -180,6 +193,7 @@ void TabPID::calculatePeriodicity()
if(value_hotend1.size()<5)
return;
float t=value_hotend1.last();
+ int period=0;
int previouslast=value_hotend1.size()-1;
bool firsteventfound=false;
for(int i=value_hotend1.size()-2;i>0;i--)
@@ -190,8 +204,10 @@ void TabPID::calculatePeriodicity()
{
if(firsteventfound)
{
- lPeriod->setText(QString("%1").arg(value_hotend1.size()-i));
- return;
+
+ period=value_hotend1.size()-i;
+ lPeriod->setText(QString("%1").arg(period));
+ break;
}
else
{
@@ -207,6 +223,30 @@ void TabPID::calculatePeriodicity()
}
}
}
+
+ float minnow=100000,maxnow=0;
+ float minlast=100000,maxlast=0;
+ for(int i=value_hotend1.size()-2;i>value_hotend1.size()-period;i--)
+ {
+ double &f=value_hotend1[i];
+ if(f<minnow) minnow=f;
+ if(f>maxnow) maxnow=f;
+ }
+ lAmp->setText(QString("%1").arg(maxnow-minnow));
+
+ if(value_hotend1.size()-2*period)
+ {
+ //float minnow=100000,maxnow=0;
+ //float minlast=100000,maxlast=0;
+ for(int i=value_hotend1.size()-period;i>value_hotend1.size()-2*period;i--)
+ {
+ double &f=value_hotend1[i];
+ if(f<minlast) minlast=f;
+ if(f>maxlast) maxlast=f;
+ }
+ lAmpPrevious->setText(QString("%1").arg(maxlast-minlast));
+ }
+ lAmpRatio->setText(QString("%1").arg(lAmp->text().toFloat()/lAmpPrevious->text().toFloat()));
}
void TabPID::startTime()
View
@@ -44,7 +44,7 @@ Q_OBJECT
QTime starttime;
QCheckBox *differential;
QPushButton *btClear, *btPeriod, *btSet,*btLoad;
- QLabel *lPeriod;
+ QLabel *lPeriod,*lAmp,*lAmpPrevious,*lAmpRatio;
QLineEdit *ePeriod,*eCriticalGain;
QCheckBox *cbZieglerDif;

0 comments on commit 32085ca

Please sign in to comment.