-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
84 lines (69 loc) · 3.08 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
#include "main.h"
using namespace std;
int main(int argc, char** argv)
{
QString ip;
QByteArray rosaddress;
QString jsstring;
std::string jsport;
QFile f("test.txt");
QFile j("joystick.txt");
QTextStream in(&f);
if(f.open(QIODevice::ReadWrite)){
ip = in.readAll();
rosaddress.append(ip);
}
QTextStream inj(&j);
if(j.open(QIODevice::ReadWrite)){
jsstring = inj.readLine();
jsport = jsstring.toStdString();
}
qDebug("Value is");
qDebug(rosaddress);
qDebug(jsstring.toLatin1());
qputenv("ROS_MASTER_URI", rosaddress);
// Init ROS
ros::init(argc, argv, "UI");
ros::NodeHandle node;
// Init Qt
QGuiApplication app(argc, argv);
qmlRegisterType<Graph>("graph",1,0,"Graph");
// Subscribers and Publishers
SpeedSubscriber speedSubscriber(&app);
EulerSubscriber eulerSubscriber(&app);
RpmSubscriber rpmSubscriber(&app);
BatterySubscriber batterySubscriber(&app);
PositionSubscriber positionSubscriber(&app);
// Start ROS in separate thread, and trigger Qt shutdown when it exits
// If Qt exits before ROS, be sure to shutdown ROS
QFutureWatcher<void> rosThread;
rosThread.setFuture(QtConcurrent::run(&ros::spin));
QObject::connect(&rosThread, &QFutureWatcher<void>::finished, &app, &QCoreApplication::quit);
QObject::connect(&app, &QCoreApplication::aboutToQuit, [](){ros::shutdown();});
QQmlApplicationEngine engine(&app);
engine.rootContext()->setContextProperty("x", &positionSubscriber);
engine.rootContext()->setContextProperty("y", &positionSubscriber);
engine.rootContext()->setContextProperty("speed", &speedSubscriber);
engine.rootContext()->setContextProperty("roll", &eulerSubscriber);
engine.rootContext()->setContextProperty("yaw", &eulerSubscriber);
engine.rootContext()->setContextProperty("pitch", &eulerSubscriber);
engine.rootContext()->setContextProperty("rpmdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("currentdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("voltagedata", &rpmSubscriber);
engine.rootContext()->setContextProperty("throttledata", &rpmSubscriber);
engine.rootContext()->setContextProperty("depthdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("zpathdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("pressuredata", &rpmSubscriber);
engine.rootContext()->setContextProperty("battery", &batterySubscriber);
engine.rootContext()->setContextProperty("inflowdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("outflowdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("inletpumpdata", &rpmSubscriber);
engine.rootContext()->setContextProperty("outletpumpdata", &rpmSubscriber);
engine.addImageProvider("rosimage", new RosImageProvider);
engine.addImageProvider("roscimage", new RosCImageProvider);
engine.addImportPath("qrc:/");
engine.load(QUrl("qrc:/main.qml"));
std::thread joy(jsqt, jsport);
// Start Qt app
return app.exec();
}