forked from selste/TwoStepperControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
147 lines (113 loc) · 4.55 KB
/
mainwindow.cpp
File metadata and controls
147 lines (113 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qstepperphidgets.h"
#include <qtimer.h>
#include <QtConcurrent/qtconcurrentrun.h>
#include <math.h>
#include <unistd.h>
//------------------------------------------------------------------
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWindow) {
int serNo,verNo, encoderNum;
double maa, mav;
ui->setupUi(this);
QTimer *timer = new QTimer(this);
timer->start(100);
EncoderDriveOne = new QEncoderPhidgets();
encoderNum = EncoderDriveOne->retrievePhidgetEncoderData(3);
StepperDriveOne = new QStepperPhidgets();
serNo = StepperDriveOne->retrievePhidgetStepperData(1);
verNo = StepperDriveOne->retrievePhidgetStepperData(2);
maa = StepperDriveOne->getKinetics(2);
ui->sbSteps->setValue(10000);
ui->sbMaxAccRA->setValue(maa);
ui->sbMaxAccRA->setMaximum(maa);
ui->sbMaxAccRA->setMinimum(maa*0.0001);
mav=StepperDriveOne->getKinetics(3);
ui->sbMaxVelRA->setMaximum(mav);
ui->sbMaxVelRA->setMinimum(StepperDriveOne->getKinetics(4));
ui->sbMaxVelRA->setValue(mav);
camera_client = new alccd5_client();
connect(timer, SIGNAL(timeout()), this, SLOT(updateReadings()));
connect(ui->pushButtonGo, SIGNAL(clicked()), this, SLOT(executeSteps()));
connect(ui->sbMaxAccRA, SIGNAL(valueChanged(int)), this, SLOT(setMaxStepperAcc()));
connect(ui->sbMaxVelRA, SIGNAL(valueChanged(int)), this, SLOT(setMaxStepperVel()));
connect(ui->pbExit,SIGNAL(clicked()), this, SLOT(shutDownProgram()));
connect(ui->pbConnectToServer,SIGNAL(clicked()),this, SLOT(setINDISAddrAndPort()));
connect(ui->pbExpose, SIGNAL(clicked()), this, SLOT(takeSingleCamShot()));
}
//------------------------------------------------------------------
MainWindow::~MainWindow() {
delete StepperDriveOne;
delete EncoderDriveOne;
delete timer;
delete ui;
exit(0);
}
//------------------------------------------------------------------
void MainWindow::updateReadings() {
float encoderReading;
encoderReading=round(EncoderDriveOne->getTopicalReadingFromEncoder()*EncoderDriveOne->getCalibrationFactor());
ui->lcdEncRA->display(encoderReading);
if (camera_client->newImageArrived() ==true) {
this->updateCameraImage();
camera_client->newImageUsedAsPixmap(); // set the "new image state to false
this->takeSingleCamShot();
}
}
//------------------------------------------------------------------
void MainWindow::executeSteps() {
int stepsSet;
float encoderReading;
ui->pushButtonGo->setEnabled(0);
EncoderDriveOne->resetEncoder();
encoderReading=round(EncoderDriveOne->getTopicalReadingFromEncoder()*EncoderDriveOne->getCalibrationFactor());
ui->lcdEncRA->display(encoderReading);
QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
stepsSet=ui->sbSteps->value();
futureStepperBehaviour = QtConcurrent::run(this->StepperDriveOne, &QStepperPhidgets::sendSteps,(round(stepsSet)));
while (!futureStepperBehaviour.isFinished()) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
ui->pushButtonGo->setEnabled(1);
}
//------------------------------------------------------------------
void MainWindow::shutDownProgram() {
this->StepperDriveOne->shutDownDrive();
delete StepperDriveOne;
delete EncoderDriveOne;
exit(0);
}
//------------------------------------------------------------------
void MainWindow::setMaxStepperAcc(void) {
double val;
val = (double)(ui->sbMaxAccRA->value());
StepperDriveOne->setKinetics(val, 1);
}
//------------------------------------------------------------------
void MainWindow::setMaxStepperVel(void) {
double val;
val = (double)(ui->sbMaxVelRA->value());
StepperDriveOne->setKinetics(val, 2);
}
//------------------------------------------------------------------
void MainWindow::setINDISAddrAndPort(void) {
QString saddr;
int sport;
bool isServerUp = 0;
saddr=ui->leINDIServer->text();
sport=ui->sbINDIPort->value();
isServerUp = camera_client->setINDIServer(saddr,sport);
qDebug() << isServerUp;
}
//------------------------------------------------------------------
void MainWindow::takeSingleCamShot(void) {
int exptime;
exptime = (ui->sbExposureTime->value());
camera_client->takeExposure(exptime);
}
//------------------------------------------------------------------
void MainWindow::updateCameraImage(void) {
camImg=camera_client->getScaledPixmapFromCamera();
ui->camLabel->setPixmap(*camImg);
ui->camLabel->show();
}