From 19837b37363aafc16fde7e7bbac1bdaa60a05482 Mon Sep 17 00:00:00 2001 From: Georgi Tushev Date: Mon, 31 Dec 2018 14:43:22 +0100 Subject: [PATCH] fix motors sync mode --- BrainATUMtome/mainwindow.cpp | 136 +++++++++++++++-------------------- BrainATUMtome/mainwindow.h | 13 ++-- 2 files changed, 65 insertions(+), 84 deletions(-) diff --git a/BrainATUMtome/mainwindow.cpp b/BrainATUMtome/mainwindow.cpp index a73d8fd..fcc7007 100644 --- a/BrainATUMtome/mainwindow.cpp +++ b/BrainATUMtome/mainwindow.cpp @@ -7,8 +7,7 @@ MainWindow::MainWindow(QWidget *parent) : m_driverEpos(nullptr), m_driverMicrotome(nullptr), m_driverSyringe(nullptr), - m_epos_direction_lower(0), - m_epos_direction_upper(0), + m_epos_direction(0), m_microtome_iscutting(false), m_microtome_sections(0), m_microtome_advanceRemaining(0) @@ -33,6 +32,10 @@ void MainWindow::configure_epos() connect(this, &MainWindow::uirequest_epos_velocity, m_driverEpos, &Epos::on_uirequest_velocity); connect(this, &MainWindow::uirequest_epos_tension, m_driverEpos, &Epos::on_uirequest_tension); + connect(ui->radioButton_epos_sync_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); + connect(ui->radioButton_epos_sync_ccw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); + connect(ui->radioButton_epos_sync_cw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); + connect(ui->radioButton_epos_lower_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); connect(ui->radioButton_epos_lower_ccw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); connect(ui->radioButton_epos_lower_cw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); @@ -44,8 +47,7 @@ void MainWindow::configure_epos() connect(ui->radioButton_epos_tension_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposTensionToggled); connect(ui->radioButton_epos_tension_on, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposTensionToggled); - connect(ui->radioButton_epos_sync_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); - //connect(ui->radioButton_epos_sync_on, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); + } @@ -69,6 +71,30 @@ void MainWindow::configure_syringe() } +void MainWindow::on_radioButtonsEposSyncToggled(bool checked) +{ + if (!checked) + return; + + if (ui->radioButton_epos_sync_off->isChecked()) { + ui->radioButton_epos_lower_off->setChecked(checked); + ui->radioButton_epos_upper_off->setChecked(checked); + ui->radioButton_epos_tension_off->setChecked(checked); + } + else if (ui->radioButton_epos_sync_ccw->isChecked()) { + ui->radioButton_epos_lower_ccw->setChecked(checked); + ui->radioButton_epos_upper_ccw->setChecked(checked); + ui->radioButton_epos_tension_on->setChecked(checked); + } + else if (ui->radioButton_epos_sync_cw->isChecked()) { + ui->radioButton_epos_lower_cw->setChecked(checked); + ui->radioButton_epos_upper_cw->setChecked(checked); + ui->radioButton_epos_tension_on->setChecked(checked); + } +} + + + void MainWindow::on_radioButtonsEposLowerToggled(bool checked) { if (!checked) @@ -76,22 +102,21 @@ void MainWindow::on_radioButtonsEposLowerToggled(bool checked) if (ui->radioButton_epos_lower_off->isChecked()) { - m_epos_direction_lower = 0; + m_epos_direction = 0; } else if (ui->radioButton_epos_lower_ccw->isChecked()) { - m_epos_direction_lower = 1; + m_epos_direction = 1; } else if (ui->radioButton_epos_lower_cw->isChecked()) { - m_epos_direction_lower = -1; + m_epos_direction = -1; } - //emit ui->spinBox_epos_lower_velocity->editingFinished(); - emit ui->spinBox_epos_lower_velocity->valueChanged(ui->spinBox_epos_lower_velocity->value()); + drive_epos_motor(EPOS_LOWER_MOTTOR, ui->spinBox_epos_lower_velocity->value()); } @@ -103,34 +128,20 @@ void MainWindow::on_radioButtonsEposUpperToggled(bool checked) if (ui->radioButton_epos_upper_off->isChecked()) { - m_epos_direction_upper = 0; + m_epos_direction = 0; } else if (ui->radioButton_epos_upper_ccw->isChecked()) { - m_epos_direction_upper = 1; + m_epos_direction = 1; } else if (ui->radioButton_epos_upper_cw->isChecked()) { - m_epos_direction_upper = -1; - + m_epos_direction = -1; } - emit ui->spinBox_epos_upper_velocity->editingFinished(); -} - - - -void MainWindow::on_spinBox_epos_upper_velocity_editingFinished() -{ - int velocity_value = ui->spinBox_epos_upper_velocity->value() * m_epos_direction_upper; - emit uirequest_epos_velocity(1, velocity_value); - - //if (ui->radioButton_epos_sync_on->isChecked()) { - // ui->spinBox_epos_lower_velocity->setValue(ui->spinBox_epos_upper_velocity->value()); - // emit uirequest_epos_velocity(0, velocity_value); - //} + drive_epos_motor(EPOS_UPPER_MOTTOR, ui->spinBox_epos_upper_velocity->value()); } @@ -148,56 +159,36 @@ void MainWindow::on_radioButtonsEposTensionToggled(bool checked) } -void MainWindow::on_radioButtonsEposSyncToggled(bool checked) +void MainWindow::on_spinBox_epos_sync_velocity_editingFinished() { - if (!checked) - return; - - if (ui->radioButton_epos_sync_off->isChecked()) { - - ui->widget_board->on_log(EventLogType::Notify, "EPOS :: sync mode is off"); + int velocity_value = ui->spinBox_epos_sync_velocity->value(); + ui->spinBox_epos_lower_velocity->setValue(velocity_value); + ui->spinBox_epos_upper_velocity->setValue(velocity_value); +} - // switch off motors - ui->radioButton_epos_lower_off->setChecked(true); - ui->radioButton_epos_upper_off->setChecked(true); - ui->radioButton_epos_tension_off->setChecked(true); - // enable async mode - enable_epos_radioButtons(true); - } - /* - else if (ui->radioButton_epos_sync_on->isChecked()) { +void MainWindow::on_spinBox_epos_lower_velocity_editingFinished() +{ + if (ui->radioButton_epos_lower_off->isChecked()) + return; - ui->widget_board->on_log(EventLogType::Notify, "EPOS :: sync mode is on"); + drive_epos_motor(EPOS_LOWER_MOTTOR, ui->spinBox_epos_lower_velocity->value()); +} - int velocity_min = qMin(ui->spinBox_epos_lower_velocity->value(), ui->spinBox_epos_upper_velocity->value()); - ui->spinBox_epos_lower_velocity->setValue(velocity_min); - ui->spinBox_epos_upper_velocity->setValue(velocity_min); - // switch on motors - ui->radioButton_epos_lower_cw->setChecked(true); - ui->radioButton_epos_upper_cw->setChecked(true); - ui->radioButton_epos_tension_on->setChecked(true); +void MainWindow::on_spinBox_epos_upper_velocity_editingFinished() +{ + if (ui->radioButton_epos_upper_off->isChecked()) + return; - // enable sync mode - enable_epos_radioButtons(false); - } - */ + drive_epos_motor(EPOS_UPPER_MOTTOR, ui->spinBox_epos_upper_velocity->value()); } -void MainWindow::enable_epos_radioButtons(bool state) +void MainWindow::drive_epos_motor(int motorid, int velocity) { - ui->radioButton_epos_lower_off->setEnabled(state); - ui->radioButton_epos_lower_ccw->setEnabled(state); - ui->radioButton_epos_lower_cw->setEnabled(state); - - ui->radioButton_epos_upper_off->setEnabled(state); - ui->radioButton_epos_upper_ccw->setEnabled(state); - ui->radioButton_epos_upper_cw->setEnabled(state); - - ui->radioButton_epos_tension_off->setEnabled(state); - ui->radioButton_epos_tension_on->setEnabled(state); + int velocity_value = velocity * m_epos_direction; + emit uirequest_epos_velocity(motorid, velocity_value); } @@ -254,16 +245,3 @@ void MainWindow::on_checkBox_syringe_auto_toggled(bool checked) emit uirequest_syringe_auto(checked); } -void MainWindow::on_spinBox_epos_lower_velocity_valueChanged(int arg1) -{ - qDebug() << "SPINBOX LOWER " << arg1; - int velocity_value = ui->spinBox_epos_lower_velocity->value() * m_epos_direction_lower; - emit uirequest_epos_velocity(0, velocity_value); - - /* - if (ui->radioButton_epos_sync_on->isChecked()) { - ui->spinBox_epos_upper_velocity->setValue(ui->spinBox_epos_lower_velocity->value()); - emit uirequest_epos_velocity(1, velocity_value); - } - */ -} diff --git a/BrainATUMtome/mainwindow.h b/BrainATUMtome/mainwindow.h index 8e8a07c..60a6506 100644 --- a/BrainATUMtome/mainwindow.h +++ b/BrainATUMtome/mainwindow.h @@ -28,24 +28,27 @@ class MainWindow : public QMainWindow Microtome *m_driverMicrotome; Syringe *m_driverSyringe; - int m_epos_direction_lower; - int m_epos_direction_upper; + int m_epos_direction; bool m_microtome_iscutting; int m_microtome_sections; int m_microtome_advanceRemaining; - void enable_epos_radioButtons(bool state); + void drive_epos_motor(int motorid, int velocity); void configure_epos(); void configure_microtome(); void configure_syringe(); + static const int EPOS_LOWER_MOTTOR = 0; + static const int EPOS_UPPER_MOTTOR = 1; + private slots: + void on_radioButtonsEposSyncToggled(bool checked); void on_radioButtonsEposLowerToggled(bool checked); void on_radioButtonsEposUpperToggled(bool checked); void on_radioButtonsEposTensionToggled(bool checked); - void on_radioButtonsEposSyncToggled(bool checked); + void on_spinBox_epos_sync_velocity_editingFinished(); + void on_spinBox_epos_lower_velocity_editingFinished(); void on_spinBox_epos_upper_velocity_editingFinished(); - void on_spinBox_epos_lower_velocity_valueChanged(int arg1); void on_spinBox_microtome_cuttingSpeed_editingFinished(); void on_comboBox_microtome_returnSpeed_activated(int index);