drone-path-core 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -10
- package/dist/cammeta-decode.d.ts +0 -2
- package/dist/cammeta-decode.js +5 -6
- package/dist/shot-segmentation.js +54 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
# drone-path-core
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Read DJI flight telemetry in your own Node.js scripts. Convert coordinates from
|
|
4
|
+
embedded CAM-meta (DVTM) streams or SRT sidecars into tracks, export them as GPX,
|
|
5
|
+
GeoJSON, KML, KMZ, or JSON, or use the spatial and camera-footprint utilities to
|
|
6
|
+
analyze a flight. No map renderer or archive database is required.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Requires Node.js 24 or later.
|
|
7
11
|
|
|
8
12
|
```sh
|
|
9
13
|
npm install drone-path-core
|
|
10
14
|
```
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
## Read GPS positions from an SRT sidecar
|
|
17
|
+
|
|
18
|
+
Use the `srt` subpath to read a DJI sidecar and print the first GPS fix:
|
|
13
19
|
|
|
14
20
|
```js
|
|
15
21
|
import { parseSrt } from 'drone-path-core/srt';
|
|
16
22
|
|
|
17
|
-
const
|
|
23
|
+
const { cues } = await parseSrt('flight.SRT');
|
|
24
|
+
console.log(cues.find((cue) => cue.fix !== null)?.fix ?? 'No GPS fix');
|
|
18
25
|
```
|
|
19
26
|
|
|
27
|
+
## TypeScript
|
|
28
|
+
|
|
20
29
|
Each module ships TypeScript declarations.
|
|
21
30
|
|
|
22
31
|
Install `@types/node` for your Node.js major version. In TypeScript 6, list
|
|
@@ -31,7 +40,9 @@ Install `@types/node` for your Node.js major version. In TypeScript 6, list
|
|
|
31
40
|
}
|
|
32
41
|
```
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
## Learn more
|
|
44
|
+
|
|
45
|
+
Use the [`drone-path` CLI](https://www.npmjs.com/package/drone-path) if you want to
|
|
46
|
+
export a track without writing code. See the
|
|
47
|
+
[project manual](https://github.com/MrManny/drone-path/tree/main/docs/user)
|
|
48
|
+
for DJI input formats and track export details.
|
package/dist/cammeta-decode.d.ts
CHANGED
|
@@ -37,8 +37,6 @@ export interface CamMetaResult {
|
|
|
37
37
|
protoFile: string | null;
|
|
38
38
|
gimbalDevice: GimbalDeviceConstants | null;
|
|
39
39
|
}
|
|
40
|
-
export declare function decodeProductMeta(buf: Buffer, start?: number, end?: number): ProductMeta;
|
|
41
|
-
export declare function decodeProvenance(buf: Buffer, start?: number, end?: number): ClipProvenance;
|
|
42
40
|
export declare function scanGpsPair(buf: Buffer, offset?: number, end?: number): {
|
|
43
41
|
fix: LatLon;
|
|
44
42
|
at: number;
|
package/dist/cammeta-decode.js
CHANGED
|
@@ -51,8 +51,7 @@ function emptyProductMeta() {
|
|
|
51
51
|
whiteBalanceCctK: null,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
const top = parseProtoFields(buf, start, end);
|
|
54
|
+
function decodeProductMetaFields(buf, top) {
|
|
56
55
|
const frameMeta = firstSubMessage(buf, top, FRAME_META);
|
|
57
56
|
const camera = frameMeta ? firstSubMessage(buf, frameMeta, CAMERA) : null;
|
|
58
57
|
const drone = frameMeta ? firstSubMessage(buf, frameMeta, DRONE) : null;
|
|
@@ -136,8 +135,7 @@ function decodeEulerAngles(buf, fields, fieldNumber) {
|
|
|
136
135
|
yawDeg: (firstVarintField(euler, YAW) ?? 0) / 10,
|
|
137
136
|
};
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
const top = parseProtoFields(buf, start, end);
|
|
138
|
+
function decodeProvenanceFields(buf, top) {
|
|
141
139
|
return {
|
|
142
140
|
protoFile: decodeProtoFile(buf, top),
|
|
143
141
|
gimbalDevice: decodeGimbalDevice(buf, top),
|
|
@@ -193,12 +191,13 @@ export function decodePacketSamples(buf, packets, keepAll) {
|
|
|
193
191
|
let gimbalDevice = null;
|
|
194
192
|
for (const packet of packets) {
|
|
195
193
|
const end = offset + packet.size;
|
|
194
|
+
const top = parseProtoFields(buf, offset, end);
|
|
196
195
|
if (protoFile === null || gimbalDevice === null) {
|
|
197
|
-
const declared =
|
|
196
|
+
const declared = decodeProvenanceFields(buf, top);
|
|
198
197
|
protoFile ??= declared.protoFile;
|
|
199
198
|
gimbalDevice ??= declared.gimbalDevice;
|
|
200
199
|
}
|
|
201
|
-
let meta =
|
|
200
|
+
let meta = decodeProductMetaFields(buf, top);
|
|
202
201
|
if (meta.fix === null) {
|
|
203
202
|
const hit = scanGpsPair(buf, offset, end);
|
|
204
203
|
if (hit)
|
|
@@ -50,32 +50,51 @@ function lowerBoundTime(records, targetT) {
|
|
|
50
50
|
}
|
|
51
51
|
return lo;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
for (let i =
|
|
57
|
-
if (records[i].tSec > targetT)
|
|
58
|
-
continue;
|
|
53
|
+
function indexChannel(records, read) {
|
|
54
|
+
const indexes = [];
|
|
55
|
+
const values = [];
|
|
56
|
+
for (let i = 0; i < records.length; i++) {
|
|
59
57
|
const value = read(records[i]);
|
|
60
58
|
if (value !== null) {
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
indexes.push(i);
|
|
60
|
+
values.push(value);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
return { indexes, values };
|
|
64
|
+
}
|
|
65
|
+
function indexChannels(records) {
|
|
66
|
+
return {
|
|
67
|
+
fix: indexChannel(records, fixOf),
|
|
68
|
+
altitude: indexChannel(records, altitudeOf),
|
|
69
|
+
yaw: indexChannel(records, (r) => finiteOrNull(r.yawDeg)),
|
|
70
|
+
gimbalPitch: indexChannel(records, (r) => finiteOrNull(r.gimbalPitchDeg)),
|
|
71
|
+
gimbalYaw: indexChannel(records, (r) => finiteOrNull(r.gimbalYawDeg)),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function lowerBoundIndex(indexes, target) {
|
|
75
|
+
let lo = 0;
|
|
76
|
+
let hi = indexes.length;
|
|
77
|
+
while (lo < hi) {
|
|
78
|
+
const mid = (lo + hi) >> 1;
|
|
79
|
+
if (indexes[mid] < target)
|
|
80
|
+
lo = mid + 1;
|
|
81
|
+
else
|
|
82
|
+
hi = mid;
|
|
74
83
|
}
|
|
84
|
+
return lo;
|
|
85
|
+
}
|
|
86
|
+
// `before` may only sit on the first record at targetT (the lower-bound record); later records sharing that tSec are deliberately not considered.
|
|
87
|
+
function bracketValue(records, channel, targetT) {
|
|
88
|
+
const { indexes, values } = channel;
|
|
89
|
+
const idx = lowerBoundTime(records, targetT);
|
|
90
|
+
const pos = lowerBoundIndex(indexes, idx);
|
|
91
|
+
const after = pos < indexes.length ? { tSec: records[indexes[pos]].tSec, value: values[pos] } : null;
|
|
92
|
+
const beforePos = pos < indexes.length && indexes[pos] === idx && records[idx].tSec <= targetT ? pos : pos - 1;
|
|
93
|
+
const before = beforePos >= 0 ? { tSec: records[indexes[beforePos]].tSec, value: values[beforePos] } : null;
|
|
75
94
|
return { before, after };
|
|
76
95
|
}
|
|
77
|
-
function sampleFixAt(records, targetT) {
|
|
78
|
-
const { before, after } = bracketValue(records,
|
|
96
|
+
function sampleFixAt(records, channel, targetT) {
|
|
97
|
+
const { before, after } = bracketValue(records, channel, targetT);
|
|
79
98
|
if (before && after) {
|
|
80
99
|
if (before.tSec === targetT)
|
|
81
100
|
return before.value;
|
|
@@ -96,8 +115,8 @@ function sampleFixAt(records, targetT) {
|
|
|
96
115
|
return after.value;
|
|
97
116
|
return null;
|
|
98
117
|
}
|
|
99
|
-
function sampleScalarAt(records,
|
|
100
|
-
const { before, after } = bracketValue(records,
|
|
118
|
+
function sampleScalarAt(records, channel, targetT) {
|
|
119
|
+
const { before, after } = bracketValue(records, channel, targetT);
|
|
101
120
|
if (before && after) {
|
|
102
121
|
if (before.tSec === targetT)
|
|
103
122
|
return before.value;
|
|
@@ -115,8 +134,8 @@ function sampleScalarAt(records, targetT, read) {
|
|
|
115
134
|
return after.value;
|
|
116
135
|
return null;
|
|
117
136
|
}
|
|
118
|
-
function sampleAngleAt(records,
|
|
119
|
-
const { before, after } = bracketValue(records,
|
|
137
|
+
function sampleAngleAt(records, channel, targetT) {
|
|
138
|
+
const { before, after } = bracketValue(records, channel, targetT);
|
|
120
139
|
if (before && after) {
|
|
121
140
|
if (before.tSec === targetT)
|
|
122
141
|
return normalizeDeg(before.value);
|
|
@@ -219,11 +238,12 @@ function classifyWindow(window, minT, maxT) {
|
|
|
219
238
|
}
|
|
220
239
|
function buildWindows(records, minT, maxT) {
|
|
221
240
|
const bounds = buildWindowBounds(minT, maxT);
|
|
241
|
+
const channels = indexChannels(records);
|
|
222
242
|
const raw = bounds.map(({ startSec, endSec }) => {
|
|
223
243
|
const dt = endSec - startSec;
|
|
224
|
-
const fixStart = sampleFixAt(records, startSec);
|
|
225
|
-
const fixMid = sampleFixAt(records, (startSec + endSec) / 2);
|
|
226
|
-
const fixEnd = sampleFixAt(records, endSec);
|
|
244
|
+
const fixStart = sampleFixAt(records, channels.fix, startSec);
|
|
245
|
+
const fixMid = sampleFixAt(records, channels.fix, (startSec + endSec) / 2);
|
|
246
|
+
const fixEnd = sampleFixAt(records, channels.fix, endSec);
|
|
227
247
|
let speedMps = 0;
|
|
228
248
|
const hasFix = Boolean(fixStart && fixEnd);
|
|
229
249
|
if (fixStart && fixEnd) {
|
|
@@ -232,22 +252,22 @@ function buildWindows(records, minT, maxT) {
|
|
|
232
252
|
: haversineM(fixStart, fixEnd);
|
|
233
253
|
speedMps = distM / dt;
|
|
234
254
|
}
|
|
235
|
-
const altStart = sampleScalarAt(records,
|
|
236
|
-
const altEnd = sampleScalarAt(records,
|
|
255
|
+
const altStart = sampleScalarAt(records, channels.altitude, startSec);
|
|
256
|
+
const altEnd = sampleScalarAt(records, channels.altitude, endSec);
|
|
237
257
|
const altRateMps = altStart !== null && altEnd !== null ? (altEnd - altStart) / dt : null;
|
|
238
|
-
const yawStart = sampleAngleAt(records,
|
|
239
|
-
const yawEnd = sampleAngleAt(records,
|
|
258
|
+
const yawStart = sampleAngleAt(records, channels.yaw, startSec);
|
|
259
|
+
const yawEnd = sampleAngleAt(records, channels.yaw, endSec);
|
|
240
260
|
const directYawRate = yawStart !== null && yawEnd !== null
|
|
241
261
|
? shortestAngleDiffDeg(yawStart, yawEnd) / dt
|
|
242
262
|
: null;
|
|
243
263
|
const cogHeading = fixStart && fixEnd && speedMps >= 0.5 ? bearingDeg(fixStart, fixEnd) : null;
|
|
244
|
-
const gimbalPitchStart = sampleScalarAt(records,
|
|
245
|
-
const gimbalPitchEnd = sampleScalarAt(records,
|
|
264
|
+
const gimbalPitchStart = sampleScalarAt(records, channels.gimbalPitch, startSec);
|
|
265
|
+
const gimbalPitchEnd = sampleScalarAt(records, channels.gimbalPitch, endSec);
|
|
246
266
|
const signedGimbalPitchRate = gimbalPitchStart !== null && gimbalPitchEnd !== null
|
|
247
267
|
? (gimbalPitchEnd - gimbalPitchStart) / dt
|
|
248
268
|
: null;
|
|
249
|
-
const gimbalYawStart = sampleAngleAt(records,
|
|
250
|
-
const gimbalYawEnd = sampleAngleAt(records,
|
|
269
|
+
const gimbalYawStart = sampleAngleAt(records, channels.gimbalYaw, startSec);
|
|
270
|
+
const gimbalYawEnd = sampleAngleAt(records, channels.gimbalYaw, endSec);
|
|
251
271
|
const signedGimbalYawRate = gimbalYawStart !== null && gimbalYawEnd !== null
|
|
252
272
|
? shortestAngleDiffDeg(gimbalYawStart, gimbalYawEnd) / dt
|
|
253
273
|
: null;
|