-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.js
169 lines (169 loc) · 5.25 KB
/
go.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
const mqtt = require("mqtt");
const axios = require("axios");
let client = mqtt.connect(
"wss://team07:vp2pv227if@mr1dns3dpz5mjj.messaging.solace.cloud:8443"
);
let mission = [];
let position = { x: 0.0, y: 0.0 };
let paths = [];
axios
.get(
"http://agent-controller.team07.xp65.renault-digital.com/api/user/situation/last"
)
.then(response => {
console.log("api/user/situation/last", response.data);
position = response.data.position;
});
axios
.get(
"http://context-controller.team07.xp65.renault-digital.com/api/context/weather/current"
)
.then(response => {
console.log("api/context/weather/current", response.data);
});
axios
.get(
"http://context-controller.team07.xp65.renault-digital.com/api/context/air/current"
)
.then(response => {
console.log("api/context/air/current", response.data);
});
axios
.get("http://graph.team07.xp65.renault-digital.com/road_graph/line_state")
.then(response => {
console.log("road_graph/line_state", response.data);
});
axios
.get("http://graph.team07.xp65.renault-digital.com/subway/stations")
.then(response => {
console.log("subway/stations", response.data);
});
axios
.get(
"http://graph.team07.xp65.renault-digital.com/road_graph/traffic_conditions"
)
.then(response => {
console.log("road_graph/traffic_conditions", response.data);
});
axios
.get("http://graph.team07.xp65.renault-digital.com/processed/subway.json")
.then(response => {
console.log(
"processed/subway",
response.data.elements.nodes.map(n => {
return { data: n.data, position: n.position };
}),
response.data.elements.edges.map(e => {
return { data: e.data };
})
);
});
client.on("connect", () => {
client.subscribe("team07/prod/user/mission");
client.subscribe("team07/prod/user/situation");
client.subscribe("team07/prod/user/objective-reached");
client.subscribe("team07/prod/user/status");
client.subscribe("team07/prod/context/change/weather");
client.subscribe("team07/prod/context/change/air");
client.subscribe("team07/prod/environment/change/roads_status");
client.subscribe("team07/prod/environment/change/lines_state");
client.subscribe("team07/prod/environment/change/traffic_conditions");
client.subscribe("team07/prod/environment/change/breakdown");
client.publish(
"team07/prod/user/mission",
JSON.stringify({
mission: "Yo !",
positions: [
{ x: 21.8, y: 5.6 },
{ x: 0.2, y: 2.0 },
{ x: 7.4, y: 3.8 },
{ x: 13.9, y: 3.8 },
]
})
);
});
// function solveMission() {
// if (mission.length > 0) {
// console.log("trying to go to the next mission by walk", {
// departure: { x: position.x, y: position.y },
// arrival: { x: mission[0].x, y: mission[0].y }
// });
// axios
// .post(
// "http://graph.team07.xp65.renault-digital.com/road_graph/shortest_path/walk",
// {
// departure: { x: position.x, y: position.y },
// arrival: { x: mission[0].x, y: mission[0].y }
// }
// )
// .then(response => {
// console.log("shortest_path/walk", response.data);
// // response.data.cars[0].paths.shift()
// // paths.push(... response.data.cars[0].paths)
// // nextMove()
// });
// //
// // axios.post('http://graph.team07.xp65.renault-digital.com/road_graph/shortest_path/bike', {
// // departure: { x: position.x, y: position.y },
// // arrival: { x: mission[0].x, y: mission[0].y }
// // })
// // .then(response => {
// // console.log('shortest_path/bike', response.data)
// // })
// // axios.post('http://graph.team07.xp65.renault-digital.com/road_graph/shortest_path/subway', {
// // departure: { x: position.x, y: position.y },
// // arrival: { x: mission[0].x, y: mission[0].y }
// // })
// // .then(response => {
// // console.log('shortest_path/subway', response.data.cars[0].paths)
// // })
// client.publish(
// "team07/prod/user/path",
// JSON.stringify({
// vehicle_type: "subway",
// target: {
// x: mission[0].x,
// y: mission[0].y
// }
// })
// );
// }
// }
// function nextMove() {
// if (paths.length > 0) {
// let path = paths.shift();
// client.publish(
// "team07/prod/user/path",
// JSON.stringify({
// vehicle_type: "walk",
// target: {
// x: path[0],
// y: path[1]
// }
// })
// );
// }
// }
client.on("message", (topic, message) => {
console.log(`${topic}: ${message.toString()}`);
// if (topic === "team07/prod/user/mission") {
// mission = JSON.parse(message).positions;
// console.log(mission);
// solveMission();
// }
// if (topic === "team07/prod/user/status") {
// // if (JSON.parse(message).status === 'stopped') {
// // nextMove();
// // }
// }
// if (topic === "team07/prod/user/objective-reached") {
// const r = JSON.parse(message);
// mission = mission.filter(p => p.x !== r.x && p.y !== r.y);
// console.log(mission);
// solveMission();
// }
// if (topic === "team07/prod/user/status") {
// position = JSON.parse(message).situation.position;
// console.log(position);
// }
});