-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
executable file
·205 lines (152 loc) · 6.3 KB
/
main.cpp
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "mainwindow.h"
#include <QApplication>
#include "sevensegment.h"
#include "inversekinematicscore.h"
#include "receiverVision.h"
#include "receiver.h"
#include <QtGlobal>
#include <stdio.h>
#include <stdlib.h>
#include "interpretercore.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString txt;
switch (type) {
case QtDebugMsg:
txt= QString("Debug: %1 (%2:%3, %4)\n").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
break;
case QtInfoMsg:
txt= QString("Info: %1 (%2:%3, %4)\n").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
break;
case QtWarningMsg:
txt= QString("Warning: %1 (%2:%3, %4)\n").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
break;
case QtCriticalMsg:
txt= QString("Critical: %1 (%2:%3, %4)\n").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
break;
case QtFatalMsg:
txt= QString("Fatal: %1 (%2:%3, %4)\n").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
abort();
}
QFile outFile("debug-log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char *argv[])
{
//TODO : find out actual x,y,z for home(or what the drives percieve as home) the x,y,z needs to be stored and given as initial positon to inverse kinematics
//TODO : limit the input in positon(GUI)
//TODO : implement clear alarm
//TODO : go home for drives on startup
//qInstallMessageHandler(myMessageOutput); // Install the handler
QApplication a(argc, argv);
//remove all queue
//we should remove queue whit id 1234 1235
key_t msg_queue_key = msgget(1234 , IPC_CREAT | 0666);
//the queu exists
if (!(msgctl(msg_queue_key, IPC_RMID, nullptr)))
{
qDebug("The OLD 1234:receiver queue was successfully removed.");
}else{
qDebug("The OLD 1234:receiver queue was unsuccessful removed.");
}
//remove all queue
//we should remove queue whit id 1234 1235
msg_queue_key = msgget(1235 , IPC_CREAT | 0666);
//the queu exists
if (!(msgctl(msg_queue_key, IPC_RMID, nullptr)))
{
qDebug("The OLD 1235:command queue was successfully removed.");
}else{
qDebug("The OLD 1235:receiver queue was unsuccessful removed.");
}
msg_queue_key = msgget(1239 , IPC_CREAT | 0666);
//the queu exists
if (!(msgctl(msg_queue_key, IPC_RMID, nullptr)))
{
qDebug("The OLD 1239:command queue was successfully removed.");
}else{
qDebug("The OLD 1239:receiver queue was unsuccessful removed.");
}
// while (1) {
// InterpreterCore* core=new InterpreterCore();
// core->base();
// while (1) {
// KinematicsState* test = new KinematicsState();
// KinematicsState* initial = new KinematicsState();
// KinematicsState* final = new KinematicsState();
// initial->x = 0;
// initial->y = 0;
// initial->z = -0.8;
// final->x = 0;
// final->y = 0;
// final->z = -0.85;
// test->Interpolation(*initial, *final);
// delete initial;
// delete final;
// delete test;
// }
// InverseKinematicsCore core;
// core.base();
//TrajectorySender *ts = new TrajectorySender(0,0,-0.8,0,0,-0.85);
//start ethercat
QProcess *ethercatProcess=new QProcess() ;
QProcess process1;
process1.startDetached("/bin/sh", QStringList()<< "/home/fumdelta/start_ethercat.sh");
ethercatProcess->waitForFinished(-1); // will wait forever until finished
qDebug("finished waiting for ethercat startup");
QString output1=ethercatProcess->readAllStandardOutput();
QString stderr1 = ethercatProcess->readAllStandardError();
qDebug()<< output1 << stderr;
//start drives
//start ethercat and drives
Receiver receiver;
ReceiverVision receiverVision;
MainWindow w(&receiver);
receiver.start();
receiverVision.start();
QProcess *startDrivesProcess=new QProcess() ;
QProcess process2;
process2.startDetached("/bin/sh", QStringList()<< "/home/fumdelta/start_drivers_via_main.sh");
startDrivesProcess->waitForFinished(-1); // will wait forever until finished
qDebug("finished waiting for drives startup");
QString output2=startDrivesProcess->readAllStandardOutput();
QString stderr2 = startDrivesProcess->readAllStandardError();
qDebug()<< output2 << stderr;
// InterpreterCore* core=new InterpreterCore();
// core->base();
qDebug("is running...");
/*------------------------------------TESTING CIRC & LINEAR-------------------------------------*/
// InverseKinematicsCore core;
//// core.circ(-200,100,-700, 0, 0, 0, 0, 200,0,-800, 0, 0, 3.141592653589793, 0, 25, 10, 100, 50,100,-820,0);
// core.linear(0, 0, -755,0,0, 3.141592653589793,0, 200,200 , -800, 0,0, 3.141592653589793 / 2,0,25,10,100);
// QVector<double> m1;
// QVector<double> m2;
// QVector<double> m3;
// QVector<QVector<double>>points;
// points.push_back(m1);
// points.push_back(m2);
// points.push_back(m3);
// for (int var = 0; var < core.size_of_trajectory_points; var++) {
// qDebug("M1[%d]=%lf",var,core.M1[var]);
// qDebug("M2[%d]=%lf",var,core.M2[var]);
// qDebug("M3[%d]=%lf\n",var,core.M3[var]);
// m1.push_back(core.M1[var]);
// m2.push_back(core.M2[var]);
// m3.push_back(core.M3[var]);
// }
// for (int var = 0; var < core.size_of_trajectory_points; var++) {
// SendCommand::getInstance()->SendPointTo3Drives(core.M1[var],core.M2[var],core.M3[var]);
// }
/*------------------------------------TESTING CIRC & LINEAR-------------------------------------*/
//-----------------------------------------------------------------------------------------------------------
/*---------------------------TESTING INVERSE--------------------------*/
/* Receiver receiver;
//InverseKinematicsCore(0.0)
MainWindow w(&receiver);*/
/*---------------------------TESTING INVERSE--------------------------*/
w.show();
return a.exec();
}