Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
add epos timer
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Jan 2, 2019
1 parent 9f9e63a commit b3f44bf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions BrainATUMtome/BrainATUMtome.pro
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ DEPENDPATH += $$PWD/../libs/epos/include

macx: INCLUDEPATH += $$PWD/../libs/epos/macx
macx: LIBS += -L$$PWD/../libs/epos/macx -lepos

16 changes: 15 additions & 1 deletion BrainATUMtome/epos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Epos::setVelocityMode(HANDLE m_keyHandle)
}
}

void Epos::move(HANDLE m_keyHandle, qint16 velocityMust)
void Epos::move(HANDLE m_keyHandle, int velocityMust)
{
enable(m_keyHandle);

Expand Down Expand Up @@ -230,11 +230,25 @@ void Epos::on_uirequest_velocity(int motorid, int velocity)
}

emit log(EventLogType::Notify, "EPOS :: " + textMotor + " motor " + textState);

// activate/deactivate runing state
BOOL runningState = (velocity == 0) ? FALSE : TRUE;
HANDLE keyHandle = (motorid == MOTORID_LOWER) ? m_keyHandle_lower : m_keyHandle_upper;

if (runningState) {
move(keyHandle, velocity);
}
else {
stop(keyHandle);
}

setLedGreen(runningState);
}


void Epos::on_uirequest_tension(bool state)
{
QString textState = (state) ? "on" : "off";
emit log(EventLogType::Notify, "EPOS :: tension motor is " + textState);
setTension(state);
}
2 changes: 1 addition & 1 deletion BrainATUMtome/epos.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Epos : public QObject
void enable(HANDLE m_keyHandle);
void disable(HANDLE m_keyHandle);
void setVelocityMode(HANDLE m_keyHandle);
void move(HANDLE m_keyHandle, qint16 velocityMust);
void move(HANDLE m_keyHandle, int velocityMust);
void stop(HANDLE m_keyHandle);
void setDOPin(HANDLE m_keyHandle, WORD digitalOutputNb, WORD configuration, BOOL state);

Expand Down
34 changes: 30 additions & 4 deletions BrainATUMtome/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ MainWindow::MainWindow(QWidget *parent) :
m_driverEpos(nullptr),
m_driverMicrotome(nullptr),
m_driverSyringe(nullptr),
m_timerEpos(new QTimer(this)),
m_epos_ticks(0),
m_epos_direction(0),
m_epos_velocity(1000),
m_microtome_iscutting(false),
m_microtome_sections(0),
m_microtome_advanceRemaining(0)
Expand All @@ -20,7 +23,10 @@ MainWindow::MainWindow(QWidget *parent) :
}

MainWindow::~MainWindow()
{
{
if (m_timerEpos->isActive())
m_timerEpos->stop();

delete ui;
}

Expand Down Expand Up @@ -50,6 +56,16 @@ void MainWindow::configure_epos()
ui->spinBox_epos_sync_velocity->setKeyboardTracking(false);
ui->spinBox_epos_lower_velocity->setKeyboardTracking(false);
ui->spinBox_epos_upper_velocity->setKeyboardTracking(false);

m_timerEpos = new QTimer(this);
m_timerEpos->setInterval(1000);
connect(m_timerEpos, &QTimer::timeout,
[this]() {
QString textTime = QDateTime::fromSecsSinceEpoch(++m_epos_ticks).toUTC().toString("hh:mm:ss");
QString textRpm = QString::number(abs(m_epos_velocity) * m_epos_ticks / 60.0, 'f', 2);
ui->lineEdit_epos_status->setText(textTime + " / " + textRpm);
}
);
}


Expand Down Expand Up @@ -184,14 +200,24 @@ void MainWindow::on_spinBox_epos_upper_velocity_valueChanged(int value)
if (ui->radioButton_epos_upper_off->isChecked())
return;

drive_epos_motor(EPOS_UPPER_MOTTOR, value);
drive_epos_motor(EPOS_UPPER_MOTTOR, value);
}


void MainWindow::drive_epos_motor(int motorid, int velocity)
{
int velocity_value = velocity * m_epos_direction;
emit uirequest_epos_velocity(motorid, velocity_value);
m_epos_velocity = velocity * m_epos_direction;
emit uirequest_epos_velocity(motorid, m_epos_velocity);

if ((m_epos_velocity == 0) && m_timerEpos->isActive()) {
m_timerEpos->stop();
m_epos_ticks = 0;
}

if ((m_epos_velocity != 0) && !m_timerEpos->isActive()) {
m_timerEpos->start();
}

}


Expand Down
4 changes: 4 additions & 0 deletions BrainATUMtome/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QDebug>

#include "eventlog.h"
Expand All @@ -27,8 +28,11 @@ class MainWindow : public QMainWindow
Epos *m_driverEpos;
Microtome *m_driverMicrotome;
Syringe *m_driverSyringe;
QTimer *m_timerEpos;

int m_epos_ticks;
int m_epos_direction;
int m_epos_velocity;
bool m_microtome_iscutting;
int m_microtome_sections;
int m_microtome_advanceRemaining;
Expand Down

0 comments on commit b3f44bf

Please sign in to comment.