-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
196 lines (180 loc) · 4.45 KB
/
app.js
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
const express = require("express");
const { execFile } = require("child_process");
const http = require("http");
const socketIO = require("socket.io");
const app = express();
const server = http.createServer(app);
const io = socketIO(server);
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.get("/", function (req, res) {
res.render("index");
});
app.get("/about", function (req, res) {
res.render("about");
});
app.get("/contact", function (req, res) {
res.render("contact");
});
var websocket;
app.post("/webSocket:id", function (req, res) {
console.log(req.params);
var id = req.params.id;
if (id == "Start") {
websocket = execFile(
"ros2",
["launch", "rosbridge_server", "rosbridge_websocket_launch.py"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Websocket started");
res.send("Connected");
} else if (id == "End") {
websocket.kill();
websocket.on("exit", function (code) {
console.log(`Websocket exited with ${code}.`);
res.send("Disconnected");
});
}
});
var roscore;
app.post("/roscore:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
roscore = execFile("ros2", ["daemon", "start"], function (err, stdout, stderr) {
if (err) {
console.log(err);
}
});
console.log("Roscore Started");
res.send("Connected");
} else if (id == "End") {
roscore.kill();
roscore.on("exit", function (code) {
console.log(`Roscore exit with ${code}`);
res.send("Disconnected");
});
}
});
var gazebo;
app.post("/gazebo:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
gazebo = execFile(
"ros2",
["launch", "bot", "simple_gazebo_launch.py"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Gazebo Started");
res.send("Connected");
} else if (id == "End") {
gazebo.kill();
gazebo.on("exit", function (code) {
console.log(`Gazebo exit with ${code}`);
res.send("Disconnected");
});
}
});
var mapviz;
app.post("/mapviz:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
mapviz = execFile(
"ros2",
["launch", "mapviz", "mapviz_launch.py"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Mapviz Started");
res.send("Connected");
} else if (id == "End") {
mapviz.kill();
mapviz.on("exit", function (code) {
console.log(`Mapviz exit with ${code}`);
res.send("Disconnected");
});
}
});
var cam;
app.post("/cam:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
cam = execFile(
"ros2",
["run", "mjpeg_server", "mjpeg_server"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Camera Started");
res.send("Connected");
} else if (id == "End") {
cam.kill();
cam.on("exit", function (code) {
console.log(`Camera exit with ${code}`);
res.send("Disconnected");
});
}
});
var autonomous;
app.post("/autonomous:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
autonomous = execFile(
"ros2",
["launch", "bot", "autonomous_launch.py"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Autonomous Task Started");
res.send("Connected");
} else if (id == "End") {
autonomous.kill();
autonomous.on("exit", function (code) {
console.log(`Autonomous Task exit with ${code}`);
res.send("Disconnected");
});
}
});
var Panorama;
app.post("/Panorama:id", function (req, res) {
var id = req.params.id;
if (id == "Start") {
Panorama = execFile(
"ros2",
["launch", "ydlidar_ros_driver", "lidar_view_launch.py"],
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
}
);
console.log("Panorama started");
res.send("Connected");
} else if (id == "End") {
Panorama.kill();
Panorama.on("exit", function (code) {
console.log(`Panorama exited with ${code}.`);
res.send("Disconnected");
});
}
});
app.listen(1008, function () {
console.log("Server running on 1008");
});