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

Commit

Permalink
fix motors sync mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Dec 31, 2018
1 parent e87d2c5 commit 19837b3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 84 deletions.
136 changes: 57 additions & 79 deletions BrainATUMtome/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);

}


Expand All @@ -69,29 +71,52 @@ 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)
return;

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());
}


Expand All @@ -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());
}


Expand All @@ -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);
}


Expand Down Expand Up @@ -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);
}
*/
}
13 changes: 8 additions & 5 deletions BrainATUMtome/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 19837b3

Please sign in to comment.