-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVICAR-frame-reader.html
297 lines (253 loc) · 11.7 KB
/
VICAR-frame-reader.html
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>Coordinate System Parser</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1600px;
margin: 20px auto;
padding: 0 15px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 0.7em;
}
th, td {
border: 1px solid #ddd;
padding: 4px;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
}
input[type="file"] {
margin-bottom: 15px;
}
</style>
</head>
<body>
<h1>Lettura coordinate da etichetta VICAR di file .IMG</h1>
<a href="https://planetarydata.jpl.nasa.gov/img/data/mer/spirit/mer2no_0xxx/data/sol1869/edr/">Example folder</a><br><br>
<a href="https://wgc2.jpl.nasa.gov:8443/webgeocalc/#StateVector">Webgeocalc site for calculating rover traverse path</a><br>
<input type="file" id="fileInput" multiple accept=".img">
<table id="coordinateTable">
<thead>
<tr>
<th>Nome File</th>
<th>DAT_TIM 1</th>
<th>DAT_TIM 2</th>
<th>DAT_TIM 3</th>
<th>MAST X Offset</th>
<th>MAST Y Offset</th>
<th>MAST Z Offset</th>
<th>MAST Yaw</th>
<th>MAST Pitch</th>
<th>MAST Roll</th>
<th>ROVER X Offset</th>
<th>ROVER Y Offset</th>
<th>ROVER Z Offset</th>
<th>ROVER Yaw</th>
<th>ROVER Pitch</th>
<th>ROVER Roll</th>
<th>MAST Offset X Delta</th>
<th>MAST Offset Y Delta</th>
<th>MAST Offset Z Delta</th>
<th>MAST Yaw Delta</th>
<th>MAST Pitch Delta</th>
<th>MAST Roll Delta</th>
<th>ROVER Offset X Delta</th>
<th>ROVER Offset Y Delta</th>
<th>ROVER Offset Z Delta</th>
<th>ROVER Yaw Delta</th>
<th>ROVER Pitch Delta</th>
<th>ROVER Roll Delta</th>
<th>DAT_TIM 1 Delta</th>
<th>DAT_TIM 2 Delta</th>
<th>DAT_TIM 3 Delta</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
<script>
let previousMastFrame = null;
let previousRoverFrame = null;
let previousDatTim = [null, null, null];
document.getElementById('fileInput').addEventListener('change', handleFiles);
function quaternionToEuler(q) {
const [x, y, z, w] = q.split(',').map(parseFloat);
const sinr_cosp = 2 * (w * x + y * z);
const cosr_cosp = 1 - 2 * (x * x + y * y);
const roll = Math.atan2(sinr_cosp, cosr_cosp);
const sinp = 2 * (w * y - z * x);
const pitch = Math.abs(sinp) >= 1
? Math.sign(sinp) * Math.PI / 2
: Math.asin(sinp);
const siny_cosp = 2 * (w * z + x * y);
const cosy_cosp = 1 - 2 * (y * y + z * z);
const yaw = Math.atan2(siny_cosp, cosy_cosp);
return {
yaw: (yaw * 180 / Math.PI).toFixed(2),
pitch: (pitch * 180 / Math.PI).toFixed(2),
roll: (roll * 180 / Math.PI).toFixed(2)
};
}
function handleFiles(event) {
const files = event.target.files;
for (let file of files) {
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
parseCoordinateData(file.name, content);
};
reader.readAsText(file);
}
}
function parseCoordinateData(fileName, content) {
const frames = {
'MAST_FRAME': { quaternion: null, offset: null },
'ROVER_FRAME': { quaternion: null, offset: null }
};
// Estrazione DAT_TIM
const datTimMatches = content.match(/DAT_TIM='[^']+'/g) || [];
const datTims = datTimMatches.map(match => match.match(/'([^']+)'/)[1]);
const coordinateSystemMatches = content.match(/COORDINATE_SYSTEM_NAME='([^']+)'/g) || [];
const offsetVectorMatches = content.match(/ORIGIN_OFFSET_VECTOR=\(([^)]+)\)/g) || [];
const rotationQuaternionMatches = content.match(/ORIGIN_ROTATION_QUATERNION=\(([^)]+)\)/g) || [];
coordinateSystemMatches.forEach((match, index) => {
const systemName = match.match(/'([^']+)'/)[1];
if (systemName === 'MAST_FRAME' || systemName === 'ROVER_FRAME') {
frames[systemName].quaternion = rotationQuaternionMatches[index].match(/\(([^)]+)\)/)[1];
frames[systemName].offset = offsetVectorMatches[index].match(/\(([^)]+)\)/)[1];
}
});
const tableBody = document.getElementById('tableBody');
const row = tableBody.insertRow();
// Nome File
const fileNameCell = row.insertCell();
fileNameCell.textContent = fileName;
// DAT_TIM
const datTimCells = [
row.insertCell(),
row.insertCell(),
row.insertCell()
];
datTimCells.forEach((cell, index) => {
cell.textContent = datTims[index] || 'N/A';
});
// MAST Frame Offset
const mastOffsetParts = frames['MAST_FRAME'].offset
? frames['MAST_FRAME'].offset.split(',').map(x => parseFloat(x).toFixed(2))
: ['N/A', 'N/A', 'N/A'];
row.insertCell().textContent = mastOffsetParts[0];
row.insertCell().textContent = mastOffsetParts[1];
row.insertCell().textContent = mastOffsetParts[2];
// Calcolo angoli Eulero per MAST_FRAME
const mastEuler = frames['MAST_FRAME'].quaternion
? quaternionToEuler(frames['MAST_FRAME'].quaternion)
: { yaw: 'N/A', pitch: 'N/A', roll: 'N/A' };
row.insertCell().textContent = mastEuler.yaw;
row.insertCell().textContent = mastEuler.pitch;
row.insertCell().textContent = mastEuler.roll;
// ROVER Frame Offset
const roverOffsetParts = frames['ROVER_FRAME'].offset
? frames['ROVER_FRAME'].offset.split(',').map(x => parseFloat(x).toFixed(2))
: ['N/A', 'N/A', 'N/A'];
row.insertCell().textContent = roverOffsetParts[0];
row.insertCell().textContent = roverOffsetParts[1];
row.insertCell().textContent = roverOffsetParts[2];
// Calcolo angoli Eulero per ROVER_FRAME
const roverEuler = frames['ROVER_FRAME'].quaternion
? quaternionToEuler(frames['ROVER_FRAME'].quaternion)
: { yaw: 'N/A', pitch: 'N/A', roll: 'N/A' };
row.insertCell().textContent = roverEuler.yaw;
row.insertCell().textContent = roverEuler.pitch;
row.insertCell().textContent = roverEuler.roll;
// Delta Calculations
const deltaCells = [
row.insertCell(), row.insertCell(), row.insertCell(), // MAST Offset Deltas
row.insertCell(), row.insertCell(), row.insertCell(), // MAST Angle Deltas
row.insertCell(), row.insertCell(), row.insertCell(), // ROVER Offset Deltas
row.insertCell(), row.insertCell(), row.insertCell(), // ROVER Angle Deltas
row.insertCell(), row.insertCell(), row.insertCell() // DAT_TIM Deltas
];
// Calcolo delta MAST_FRAME
if (previousMastFrame) {
const mastOffsetDelta = calculateOffsetDelta(previousMastFrame.offset, mastOffsetParts);
const mastAngleDelta = calculateAngleDelta(previousMastFrame.euler, mastEuler);
deltaCells[0].textContent = mastOffsetDelta.x;
deltaCells[1].textContent = mastOffsetDelta.y;
deltaCells[2].textContent = mastOffsetDelta.z;
deltaCells[3].textContent = mastAngleDelta.yaw;
deltaCells[4].textContent = mastAngleDelta.pitch;
deltaCells[5].textContent = mastAngleDelta.roll;
}
// Calcolo delta ROVER_FRAME
if (previousRoverFrame) {
const roverOffsetDelta = calculateOffsetDelta(previousRoverFrame.offset, roverOffsetParts);
const roverAngleDelta = calculateAngleDelta(previousRoverFrame.euler, roverEuler);
deltaCells[6].textContent = roverOffsetDelta.x;
deltaCells[7].textContent = roverOffsetDelta.y;
deltaCells[8].textContent = roverOffsetDelta.z;
deltaCells[9].textContent = roverAngleDelta.yaw;
deltaCells[10].textContent = roverAngleDelta.pitch;
deltaCells[11].textContent = roverAngleDelta.roll;
}
// Calcolo delta DAT_TIM
const datTimDeltas = calculateDatTimDeltas(previousDatTim, datTims);
deltaCells[12].textContent = datTimDeltas[0];
deltaCells[13].textContent = datTimDeltas[1];
deltaCells[14].textContent = datTimDeltas[2];
// Aggiorna i frame e i tempi precedenti
previousMastFrame = {
offset: mastOffsetParts,
euler: mastEuler
};
previousRoverFrame = {
offset: roverOffsetParts,
euler: roverEuler
};
previousDatTim = datTims;
}
function calculateOffsetDelta(prev, curr) {
return {
x: prev[0] === 'N/A' || curr[0] === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr[0]) - parseFloat(prev[0])).toFixed(2),
y: prev[1] === 'N/A' || curr[1] === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr[1]) - parseFloat(prev[1])).toFixed(2),
z: prev[2] === 'N/A' || curr[2] === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr[2]) - parseFloat(prev[2])).toFixed(2)
};
}
function calculateAngleDelta(prev, curr) {
return {
yaw: prev.yaw === 'N/A' || curr.yaw === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr.yaw) - parseFloat(prev.yaw)).toFixed(2),
pitch: prev.pitch === 'N/A' || curr.pitch === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr.pitch) - parseFloat(prev.pitch)).toFixed(2),
roll: prev.roll === 'N/A' || curr.roll === 'N/A'
? 'N/A'
: Math.abs(parseFloat(curr.roll) - parseFloat(prev.roll)).toFixed(2)
};
}
function calculateDatTimDeltas(prev, curr) {
return curr.map((time, index) => {
if (!prev || prev[index] === null || time === 'N/A') return 'N/A';
const prevDate = new Date(prev[index]);
const currDate = new Date(time);
const diffMs = currDate - prevDate;
const diffSeconds = (diffMs / 1000).toFixed(2);
return diffSeconds;
});
}
</script>
</body>
</html>