Skip to content

Commit

Permalink
movement test first light. but still far to go.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkubicek committed Nov 13, 2011
1 parent 28954f6 commit e516c46
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 24 deletions.
4 changes: 2 additions & 2 deletions QTMarlin.pro
Expand Up @@ -21,8 +21,8 @@ QMAKE_LIBDOR += $$QEXTSERIAL_DIR/src/build/
QMAKE_LIBDIR += $$QSERIALDEVICE_DIR/src/build/release QMAKE_LIBDIR += $$QSERIALDEVICE_DIR/src/build/release


# Input # Input
HEADERS += mainwindow.h tab_pid.h tab_raw.h tab_eeprom.h HEADERS += mainwindow.h tab_pid.h tab_raw.h tab_eeprom.h tab_veltest.h
SOURCES += main.cpp mainwindow.cpp tab_pid.cpp tab_raw.cpp tab_eeprom.cpp SOURCES += main.cpp mainwindow.cpp tab_pid.cpp tab_raw.cpp tab_eeprom.cpp tab_veltest.cpp
#LIBS += -lqextserialport -lqserialdevice -lqwt #LIBS += -lqextserialport -lqserialdevice -lqwt
LIBS += -lqwt LIBS += -lqwt
LIBS += libqextserialport.a LIBS += libqextserialport.a
Expand Down
101 changes: 86 additions & 15 deletions mainwindow.cpp
Expand Up @@ -42,6 +42,7 @@ using namespace std;
#include "tab_pid.h" #include "tab_pid.h"
#include "tab_raw.h" #include "tab_raw.h"
#include "tab_eeprom.h" #include "tab_eeprom.h"
#include "tab_veltest.h"


#ifdef USE_QSERIALDEVICE #ifdef USE_QSERIALDEVICE
#include <serialdeviceenumerator.h> #include <serialdeviceenumerator.h>
Expand All @@ -52,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)
initSerial(); initSerial();


//port = new AbstractSerial(); //port = new AbstractSerial();
readSinceLastSend="";
wait_reply=false;
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;


QHBoxLayout *comLayout= new QHBoxLayout; QHBoxLayout *comLayout= new QHBoxLayout;
Expand All @@ -77,10 +80,12 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)
tabPID=new TabPID(tab); tabPID=new TabPID(tab);
tabRaw=new TabRaw(tab); tabRaw=new TabRaw(tab);
tabEEPROM=new TabEEPROM(tab); tabEEPROM=new TabEEPROM(tab);
tabVeltest=new TabVeltest(this,0);


tab->addTab(tabRaw,"Raw"); tab->addTab(tabRaw,"Raw");
tab->addTab(tabPID,"PID"); tab->addTab(tabPID,"PID");
tab->addTab(tabEEPROM,"EEPROM"); tab->addTab(tabEEPROM,"EEPROM");
tab->addTab(tabVeltest,"VelTest");


status=new QStatusBar(this); status=new QStatusBar(this);


Expand All @@ -107,7 +112,9 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)


connect(tabPID->temp[hotend1],SIGNAL(returnPressed()),this, SLOT(setHotend1Temp())); connect(tabPID->temp[hotend1],SIGNAL(returnPressed()),this, SLOT(setHotend1Temp()));


connect(this,SIGNAL(newSerialData()),this,SLOT(processReply()));
timer = new QTimer(this); timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),tabVeltest,SLOT(checkDone()));
} }


MainWindow::~MainWindow() MainWindow::~MainWindow()
Expand Down Expand Up @@ -289,7 +296,7 @@ void getdata(const QString &line,const QString &after, const QString &key,float
f=end.toFloat(); f=end.toFloat();
target=f; target=f;


qDebug()<<end<<endl; //qDebug()<<end<<endl;
} }
void MainWindow::slotRead() void MainWindow::slotRead()
{ {
Expand All @@ -298,12 +305,15 @@ void MainWindow::slotRead()
//qDebug()<<QString( ba); //qDebug()<<QString( ba);
tabRaw->edit->insertPlainText(ba); tabRaw->edit->insertPlainText(ba);
serialBuffer=serialBuffer+QString(ba); serialBuffer=serialBuffer+QString(ba);
readSinceLastSend.append(QString(ba));
int n=serialBuffer.lastIndexOf("\n"); int n=serialBuffer.lastIndexOf("\n");
if(n==-1) return; //not even a full line if(n==-1) return; //not even a full line
QStringList lines = serialBuffer.mid(0,n).split("\n"); QStringList lines = serialBuffer.mid(0,n).split("\n",QString::SkipEmptyParts);
serialBuffer=serialBuffer.mid(n,sizeof(serialBuffer)-n); serialBuffer=serialBuffer.mid(n,sizeof(serialBuffer)-n);
foreach(QString s, lines) foreach(QString s, lines)
{ {
if(s.contains("endstop"))
endstopfound=true;
if(s.startsWith("ok")) if(s.startsWith("ok"))
{ {
QStringList junks(s.remove(0,3).split(" ",QString::SkipEmptyParts)); QStringList junks(s.remove(0,3).split(" ",QString::SkipEmptyParts));
Expand All @@ -313,7 +323,10 @@ void MainWindow::slotRead()
QStringList ll=j.split(":",QString::SkipEmptyParts); QStringList ll=j.split(":",QString::SkipEmptyParts);
if(ll.size()==2) if(ll.size()==2)
{ {
variables[ll[0]]= ll[1].toDouble(); bool ok=false;
float f=ll[1].toDouble(&ok);
if(ok)
variables[ll[0]]=f ;
// qDebug()<<"Variable read:"<<QString(ll[0])<<"="<<variables[ll[0]]<<endl; // qDebug()<<"Variable read:"<<QString(ll[0])<<"="<<variables[ll[0]]<<endl;
if(ll[0]=="p") if(ll[0]=="p")
{ {
Expand All @@ -340,7 +353,7 @@ void MainWindow::slotRead()
else if(s.startsWith("echo:")) else if(s.startsWith("echo:"))
{ {


float f;
getdata(s,"M92","X",tabEEPROM->stepsperunit[0]); getdata(s,"M92","X",tabEEPROM->stepsperunit[0]);
getdata(s,"M92","Y",tabEEPROM->stepsperunit[1]); getdata(s,"M92","Y",tabEEPROM->stepsperunit[1]);
getdata(s,"M92","Z",tabEEPROM->stepsperunit[2]); getdata(s,"M92","Z",tabEEPROM->stepsperunit[2]);
Expand All @@ -365,7 +378,7 @@ void MainWindow::slotRead()
getdata(s,"M205","X",tabEEPROM->vxyjerk); getdata(s,"M205","X",tabEEPROM->vxyjerk);
getdata(s,"M205","Z",tabEEPROM->vzjerk); getdata(s,"M205","Z",tabEEPROM->vzjerk);


qDebug()<<f<<endl; //qDebug()<<f<<endl;
/* /*
* float stepsperunit[4]; * float stepsperunit[4];
float vmax[4]; float vmax[4];
Expand All @@ -377,6 +390,7 @@ void MainWindow::slotRead()
} }


} }
emit newSerialData();
} }


void MainWindow::manualSend() void MainWindow::manualSend()
Expand All @@ -385,37 +399,94 @@ void MainWindow::manualSend()
} }




void MainWindow::send(const QString &text) void MainWindow::send(QString text)
{ {
if(!comport->isOpen()) if(!comport->isOpen())
return; return;
QByteArray ba=text.toAscii(); //data to send QString text2=text.append("\n");
QByteArray ba=text2.toAscii(); //data to send
qint64 bw = 0; //bytes really writed qint64 bw = 0; //bytes really writed


/* 5. Fifth - you can now read / write device, or further modify its settings, etc.
*/

bw = comport->write(ba); bw = comport->write(ba);
//qDebug() << "Writen : " << bw << " bytes:"<<QString(ba);


} }


void MainWindow::sendGcode(const QString &text)
{
sendcodes<<text;
if(wait_reply)
return;

send(sendcodes[0]);
readSinceLastSend="";
wait_reply=true;
}

void MainWindow::processReply()
{
if(sendcodes.size()==0)
return;

QStringList lines = readSinceLastSend.split("\n",QString::SkipEmptyParts);
qDebug()<<"got reply for command "<<sendcodes[0];

QString overhang="";
foreach(QString s,lines)
{
if(overhang.size())
{
overhang.append(s);
//qDebug()<<"Appeneded Overhang:"<<overhang<<endl;
}
else
overhang=s;

if(overhang.startsWith("ok"))
{
qDebug()<<"ack ok:"<<overhang<<endl;
if(sendcodes.size())
{
sendcodes.removeFirst();
if(sendcodes.size())
{
readSinceLastSend="";
send(sendcodes[0]);
}
else
wait_reply=false;
}

}
else
{
// qDebug()<<"ack not ok:"<<overhang<<endl;
}
if(s.size()<2)
overhang=s;
else
overhang="";
//qDebug()<<"Overhang:"<<overhang<<endl;
}

}

void MainWindow::measure() void MainWindow::measure()
{ {
send("M105\n"); if(tabPID->monitor->isChecked())
sendGcode("M105");
} }


void MainWindow::setHotend1Temp() void MainWindow::setHotend1Temp()
{ {
send(QString("M104 S%1\n").arg(tabPID->temp[hotend1]->text())); sendGcode(QString("M104 S%1").arg(tabPID->temp[hotend1]->text()));
} }


void MainWindow::sendPID() void MainWindow::sendPID()
{ {
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())); sendGcode(QString("M301 P%1 I%2 D%3 C%4").arg(tabPID->pids[0]->text()).arg(tabPID->pids[1]->text()).arg(tabPID->pids[2]->text()).arg(tabPID->pids[3]->text()));
} }


void MainWindow::getPID() void MainWindow::getPID()
{ {
send(QString("M301\n")); sendGcode(QString("M301"));
} }
18 changes: 16 additions & 2 deletions mainwindow.h
@@ -1,3 +1,5 @@
#ifndef __MAINWINDOWH
#define __MAINWINDOWH
#include <QWidget> #include <QWidget>
#include <fstream> #include <fstream>


Expand All @@ -23,6 +25,7 @@ class QPushButton;
class TabPID; class TabPID;
class TabRaw; class TabRaw;
class TabEEPROM; class TabEEPROM;
class TabVeltest;
//class QextSerialPort; //class QextSerialPort;
class SerialDeviceEnumerator; class SerialDeviceEnumerator;
class AbstractSerial; class AbstractSerial;
Expand Down Expand Up @@ -59,11 +62,15 @@ Q_OBJECT
~MainWindow(); ~MainWindow();




void send(const QString &text); void send(QString text);
void sendGcode(const QString &text); //wait for "ok"



QStringList sendcodes;
QMap<QString, float> variables; QMap<QString, float> variables;


bool wait_reply;
bool endstopfound;

public slots: public slots:
void clickedConnect(); void clickedConnect();
void clickedDisconnect(); void clickedDisconnect();
Expand All @@ -77,13 +84,17 @@ public slots:
void getPID(); void getPID();
//void quit(); //void quit();


void processReply();
signals:
void newSerialData();


private: private:
QStatusBar *status; QStatusBar *status;
QTabWidget *tab; QTabWidget *tab;
TabPID *tabPID; TabPID *tabPID;
TabRaw *tabRaw; TabRaw *tabRaw;
TabEEPROM *tabEEPROM; TabEEPROM *tabEEPROM;
TabVeltest *tabVeltest;


QComboBox *portSelector; QComboBox *portSelector;
QComboBox *baudSelector; QComboBox *baudSelector;
Expand All @@ -105,5 +116,8 @@ public slots:
void initSerial(); void initSerial();
void openSerial(); void openSerial();
void closeSerial(); void closeSerial();

QString readSinceLastSend;
}; };


#endif
15 changes: 11 additions & 4 deletions tab_pid.cpp
Expand Up @@ -112,6 +112,8 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
layout->addLayout(h1layout); layout->addLayout(h1layout);


QHBoxLayout *h2layout = new QHBoxLayout; QHBoxLayout *h2layout = new QHBoxLayout;
monitor=new QCheckBox("monitor temp",this);
h2layout->addWidget(monitor);
differential=new QCheckBox("differential",this); differential=new QCheckBox("differential",this);
h2layout->addWidget(differential); h2layout->addWidget(differential);
btClear=new QPushButton("Clear"); btClear=new QPushButton("Clear");
Expand Down Expand Up @@ -145,12 +147,17 @@ void TabPID::addData(float t1, float b, float t2, float h)
{ {
QTime now=QTime::currentTime(); QTime now=QTime::currentTime();
float dt=starttime.msecsTo(now); float dt=starttime.msecsTo(now);
time.push_back(dt);
if((fabs(t1-value_hotend1.last())<50)||(value_hotend1.size()<10)) if((fabs(t1-value_hotend1.last())<50)||(value_hotend1.size()<5))
value_hotend1.push_back(t1); value_hotend1.push_back(t1);
else else
value_hotend1.push_back(value_hotend1.last()); //emergency measure, not sure why this is needed. {

if(value_hotend1.size()<5)
return;
else
value_hotend1.push_back(value_hotend1.last()); //emergency measure, not sure why this is needed.
}
time.push_back(dt);
value_bed.push_back(b); value_bed.push_back(b);
value_hotend2.push_back(t2); value_hotend2.push_back(t2);
value_heater.push_back(h/255.); value_heater.push_back(h/255.);
Expand Down
2 changes: 1 addition & 1 deletion tab_pid.h
Expand Up @@ -42,7 +42,7 @@ Q_OBJECT
QVector<double> value_hotend1,value_hotend2,value_bed,value_heater; QVector<double> value_hotend1,value_hotend2,value_bed,value_heater;
QVector<double> target_hotend1,target_hotend2,target_bed; QVector<double> target_hotend1,target_hotend2,target_bed;
QTime starttime; QTime starttime;
QCheckBox *differential; QCheckBox *differential,*monitor;
QPushButton *btClear, *btPeriod, *btSet,*btLoad; QPushButton *btClear, *btPeriod, *btSet,*btLoad;
QLabel *lPeriod,*lAmp,*lAmpPrevious,*lAmpRatio; QLabel *lPeriod,*lAmp,*lAmpPrevious,*lAmpRatio;
QLineEdit *ePeriod,*eCriticalGain; QLineEdit *ePeriod,*eCriticalGain;
Expand Down

0 comments on commit e516c46

Please sign in to comment.