@jjlmoya/utils-drones 1.36.0 → 1.37.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.
Files changed (35) hide show
  1. package/package.json +1 -1
  2. package/src/category/index.ts +4 -0
  3. package/src/entries.ts +4 -0
  4. package/src/tests/locale_completeness.test.ts +2 -2
  5. package/src/tests/tool_validation.test.ts +2 -2
  6. package/src/tool/drone-mission-battery-reserve-planner/bibliography.astro +6 -0
  7. package/src/tool/drone-mission-battery-reserve-planner/bibliography.ts +7 -0
  8. package/src/tool/drone-mission-battery-reserve-planner/component.astro +229 -0
  9. package/src/tool/drone-mission-battery-reserve-planner/controller.ts +124 -0
  10. package/src/tool/drone-mission-battery-reserve-planner/dom-views.ts +114 -0
  11. package/src/tool/drone-mission-battery-reserve-planner/drone-mission-battery-reserve-planner.css +392 -0
  12. package/src/tool/drone-mission-battery-reserve-planner/entry.ts +27 -0
  13. package/src/tool/drone-mission-battery-reserve-planner/evaluator.ts +23 -0
  14. package/src/tool/drone-mission-battery-reserve-planner/i18n/de.ts +223 -0
  15. package/src/tool/drone-mission-battery-reserve-planner/i18n/en.ts +223 -0
  16. package/src/tool/drone-mission-battery-reserve-planner/i18n/es.ts +223 -0
  17. package/src/tool/drone-mission-battery-reserve-planner/i18n/fr.ts +223 -0
  18. package/src/tool/drone-mission-battery-reserve-planner/i18n/id.ts +223 -0
  19. package/src/tool/drone-mission-battery-reserve-planner/i18n/it.ts +223 -0
  20. package/src/tool/drone-mission-battery-reserve-planner/i18n/ja.ts +223 -0
  21. package/src/tool/drone-mission-battery-reserve-planner/i18n/ko.ts +223 -0
  22. package/src/tool/drone-mission-battery-reserve-planner/i18n/nl.ts +223 -0
  23. package/src/tool/drone-mission-battery-reserve-planner/i18n/pl.ts +223 -0
  24. package/src/tool/drone-mission-battery-reserve-planner/i18n/pt.ts +223 -0
  25. package/src/tool/drone-mission-battery-reserve-planner/i18n/ru.ts +223 -0
  26. package/src/tool/drone-mission-battery-reserve-planner/i18n/sv.ts +223 -0
  27. package/src/tool/drone-mission-battery-reserve-planner/i18n/tr.ts +223 -0
  28. package/src/tool/drone-mission-battery-reserve-planner/i18n/zh.ts +223 -0
  29. package/src/tool/drone-mission-battery-reserve-planner/index.ts +11 -0
  30. package/src/tool/drone-mission-battery-reserve-planner/logic.test.ts +94 -0
  31. package/src/tool/drone-mission-battery-reserve-planner/logic.ts +203 -0
  32. package/src/tool/drone-mission-battery-reserve-planner/seo.astro +15 -0
  33. package/src/tool/drone-mission-battery-reserve-planner/storage.ts +59 -0
  34. package/src/tool/drone-mission-battery-reserve-planner/ui.ts +78 -0
  35. package/src/tools.ts +4 -0
@@ -0,0 +1,203 @@
1
+ export type UnitSystem = 'metric' | 'imperial';
2
+ export type WindDirection = 'headwind' | 'tailwind' | 'crosswind';
3
+ export type MissionStatusKey = 'optimal' | 'tight' | 'critical' | 'exceeded';
4
+
5
+ export interface MissionInputs {
6
+ unitSystem: UnitSystem;
7
+ batteryCapacityMah: number;
8
+ voltageNominal: number;
9
+ averageCurrentAmps: number;
10
+ cruiseSpeedKmh: number;
11
+ oneWayDistanceKm: number;
12
+ targetHoverTimeMin: number;
13
+ windSpeedKmh: number;
14
+ windDirection: WindDirection;
15
+ reservePolicyPercent: number;
16
+ }
17
+
18
+ export interface MissionResults {
19
+ totalEnergyWh: number;
20
+ usableEnergyWh: number;
21
+ reserveEnergyWh: number;
22
+ basePowerDrawWatts: number;
23
+ outboundPowerWatts: number;
24
+ returnPowerWatts: number;
25
+ totalAutonomyMinutes: number;
26
+ outboundSpeedKmh: number;
27
+ returnSpeedKmh: number;
28
+ outboundTimeMinutes: number;
29
+ targetHoverTimeMinutes: number;
30
+ returnTimeMinutes: number;
31
+ totalMissionTimeMinutes: number;
32
+ outboundEnergyWh: number;
33
+ targetHoverEnergyWh: number;
34
+ returnEnergyWh: number;
35
+ missionEnergyUsedWh: number;
36
+ remainingEnergyLandingWh: number;
37
+ remainingEnergyLandingPercent: number;
38
+ maxSafeRadiusKm: number;
39
+ voltageSagWhLoss: number;
40
+ statusKey: MissionStatusKey;
41
+ }
42
+
43
+ const KMH_TO_MPH = 0.621371;
44
+ const KM_TO_MILES = 0.621371;
45
+
46
+ export function clampValue(val: number, min: number, max: number): number {
47
+ return Math.min(Math.max(val, min), max);
48
+ }
49
+
50
+ export function computeEffectiveSpeeds(
51
+ cruiseKmh: number,
52
+ windKmh: number,
53
+ dir: WindDirection
54
+ ): { outbound: number; returnLeg: number } {
55
+ if (dir === 'headwind') {
56
+ return { outbound: Math.max(1, cruiseKmh - windKmh), returnLeg: cruiseKmh + windKmh * 0.85 };
57
+ }
58
+ if (dir === 'tailwind') {
59
+ return { outbound: cruiseKmh + windKmh * 0.85, returnLeg: Math.max(1, cruiseKmh - windKmh) };
60
+ }
61
+ const effective = Math.max(1, Math.sqrt(Math.max(0, cruiseKmh * cruiseKmh - windKmh * windKmh * 0.5)));
62
+ return { outbound: effective, returnLeg: effective };
63
+ }
64
+
65
+ export function calculateWindPowerPenalty(
66
+ basePowerWatts: number,
67
+ cruiseKmh: number,
68
+ windKmh: number,
69
+ dir: WindDirection
70
+ ): { outboundPower: number; returnPower: number } {
71
+ const windRatio = windKmh / Math.max(10, cruiseKmh);
72
+
73
+ if (dir === 'headwind') {
74
+ return {
75
+ outboundPower: basePowerWatts * Math.pow(1 + 0.65 * windRatio, 1.3),
76
+ returnPower: basePowerWatts * Math.max(0.75, 1 - 0.35 * windRatio),
77
+ };
78
+ }
79
+ if (dir === 'tailwind') {
80
+ return {
81
+ outboundPower: basePowerWatts * Math.max(0.75, 1 - 0.35 * windRatio),
82
+ returnPower: basePowerWatts * Math.pow(1 + 0.65 * windRatio, 1.3),
83
+ };
84
+ }
85
+ const crossPower = basePowerWatts * (1 + 0.25 * windRatio);
86
+ return { outboundPower: crossPower, returnPower: crossPower };
87
+ }
88
+
89
+ export function calculateEnergyMetrics(inputs: MissionInputs): {
90
+ totalEnergyWh: number;
91
+ usableEnergyWh: number;
92
+ reserveEnergyWh: number;
93
+ basePowerDrawWatts: number;
94
+ totalAutonomyMinutes: number;
95
+ voltageSagWhLoss: number;
96
+ } {
97
+ const cap = Math.max(1, inputs.batteryCapacityMah);
98
+ const volt = Math.max(0.1, inputs.voltageNominal);
99
+ const current = Math.max(0.1, inputs.averageCurrentAmps);
100
+ const reservePct = clampValue(inputs.reservePolicyPercent, 5, 50) / 100;
101
+
102
+ const grossWh = (cap * volt) / 1000;
103
+ const sagLoss = grossWh * Math.min(0.12, 0.02 + 0.015 * (current / (cap / 1000)));
104
+ const totalWh = Math.max(0.1, grossWh - sagLoss);
105
+ const reserveWh = totalWh * reservePct;
106
+ const usableWh = totalWh - reserveWh;
107
+ const baseWatts = volt * current;
108
+
109
+ return {
110
+ totalEnergyWh: totalWh,
111
+ usableEnergyWh: usableWh,
112
+ reserveEnergyWh: reserveWh,
113
+ basePowerDrawWatts: baseWatts,
114
+ totalAutonomyMinutes: (usableWh / baseWatts) * 60,
115
+ voltageSagWhLoss: sagLoss,
116
+ };
117
+ }
118
+
119
+ export function determineMissionStatus(
120
+ remainingWh: number,
121
+ reserveWh: number,
122
+ _totalEnergyWh: number
123
+ ): MissionStatusKey {
124
+ if (remainingWh < 0) return 'exceeded';
125
+ if (remainingWh < reserveWh * 0.5) return 'critical';
126
+ if (remainingWh < reserveWh) return 'tight';
127
+ return 'optimal';
128
+ }
129
+
130
+ interface LegParams {
131
+ distKm: number;
132
+ hoverMin: number;
133
+ baseWatts: number;
134
+ outboundSpeed: number;
135
+ returnSpeed: number;
136
+ outboundPower: number;
137
+ returnPower: number;
138
+ }
139
+
140
+ function calculateTransitLegs(p: LegParams) {
141
+ const outboundTimeMin = (p.distKm / p.outboundSpeed) * 60;
142
+ const returnTimeMin = (p.distKm / p.returnSpeed) * 60;
143
+ const outboundEnergyWh = (outboundTimeMin / 60) * p.outboundPower;
144
+ const hoverEnergyWh = (p.hoverMin / 60) * p.baseWatts;
145
+ const returnEnergyWh = (returnTimeMin / 60) * p.returnPower;
146
+
147
+ return {
148
+ outboundTimeMin, returnTimeMin, hoverTimeMin: p.hoverMin,
149
+ totalMissionTimeMin: outboundTimeMin + p.hoverMin + returnTimeMin,
150
+ outboundEnergyWh, hoverEnergyWh, returnEnergyWh,
151
+ totalUsedWh: outboundEnergyWh + hoverEnergyWh + returnEnergyWh,
152
+ };
153
+ }
154
+
155
+ interface SafeRadiusParams {
156
+ usableWh: number;
157
+ hoverWh: number;
158
+ outboundPower: number;
159
+ returnPower: number;
160
+ outboundSpeed: number;
161
+ returnSpeed: number;
162
+ }
163
+
164
+ function calculateSafeRadius(p: SafeRadiusParams): number {
165
+ const transitWh = Math.max(0, p.usableWh - p.hoverWh);
166
+ const perKm = (p.outboundPower / p.outboundSpeed) + (p.returnPower / p.returnSpeed);
167
+ return perKm > 0 ? Math.max(0, transitWh / perKm) : 0;
168
+ }
169
+
170
+ export function calculateMissionReserve(inputs: MissionInputs): MissionResults {
171
+ const e = calculateEnergyMetrics(inputs);
172
+ const s = computeEffectiveSpeeds(Math.max(1, inputs.cruiseSpeedKmh), Math.max(0, inputs.windSpeedKmh), inputs.windDirection);
173
+ const p = calculateWindPowerPenalty(e.basePowerDrawWatts, Math.max(1, inputs.cruiseSpeedKmh), Math.max(0, inputs.windSpeedKmh), inputs.windDirection);
174
+ const legs = calculateTransitLegs({
175
+ distKm: Math.max(0, inputs.oneWayDistanceKm), hoverMin: Math.max(0, inputs.targetHoverTimeMin),
176
+ baseWatts: e.basePowerDrawWatts, outboundSpeed: s.outbound, returnSpeed: s.returnLeg,
177
+ outboundPower: p.outboundPower, returnPower: p.returnPower,
178
+ });
179
+ const maxSafeRadiusKm = calculateSafeRadius({
180
+ usableWh: e.usableEnergyWh, hoverWh: legs.hoverEnergyWh, outboundPower: p.outboundPower,
181
+ returnPower: p.returnPower, outboundSpeed: s.outbound, returnSpeed: s.returnLeg,
182
+ });
183
+
184
+ const remWh = e.totalEnergyWh - legs.totalUsedWh;
185
+ return {
186
+ totalEnergyWh: e.totalEnergyWh, usableEnergyWh: e.usableEnergyWh, reserveEnergyWh: e.reserveEnergyWh,
187
+ basePowerDrawWatts: e.basePowerDrawWatts, outboundPowerWatts: p.outboundPower, returnPowerWatts: p.returnPower,
188
+ totalAutonomyMinutes: e.totalAutonomyMinutes, outboundSpeedKmh: s.outbound, returnSpeedKmh: s.returnLeg,
189
+ outboundTimeMinutes: legs.outboundTimeMin, targetHoverTimeMinutes: legs.hoverTimeMin, returnTimeMinutes: legs.returnTimeMin,
190
+ totalMissionTimeMinutes: legs.totalMissionTimeMin, outboundEnergyWh: legs.outboundEnergyWh, targetHoverEnergyWh: legs.hoverEnergyWh,
191
+ returnEnergyWh: legs.returnEnergyWh, missionEnergyUsedWh: legs.totalUsedWh, remainingEnergyLandingWh: remWh,
192
+ remainingEnergyLandingPercent: (remWh / e.totalEnergyWh) * 100, maxSafeRadiusKm, voltageSagWhLoss: e.voltageSagWhLoss,
193
+ statusKey: determineMissionStatus(remWh, e.reserveEnergyWh, e.totalEnergyWh),
194
+ };
195
+ }
196
+
197
+ export function convertDistance(km: number, unit: UnitSystem): number {
198
+ return unit === 'imperial' ? km * KM_TO_MILES : km;
199
+ }
200
+
201
+ export function convertSpeed(kmh: number, unit: UnitSystem): number {
202
+ return unit === 'imperial' ? kmh * KMH_TO_MPH : kmh;
203
+ }
@@ -0,0 +1,15 @@
1
+ ---
2
+ import { SEORenderer } from '@jjlmoya/utils-shared';
3
+ import { droneMissionBatteryReservePlanner } from './entry';
4
+ import type { KnownLocale } from '../../types';
5
+
6
+ interface Props {
7
+ locale?: KnownLocale;
8
+ }
9
+
10
+ const { locale = 'en' } = Astro.props;
11
+ const content = await droneMissionBatteryReservePlanner.i18n[locale]?.();
12
+ if (!content) return null;
13
+ ---
14
+
15
+ {content.seo?.length > 0 && <SEORenderer content={{ locale, sections: content.seo }} />}
@@ -0,0 +1,59 @@
1
+ import type { MissionInputs, UnitSystem, WindDirection } from './logic';
2
+
3
+ const STORAGE_KEY = 'jjlmoya_drone_mission_battery_reserve_planner_state';
4
+
5
+ export const DEFAULT_MISSION_INPUTS: MissionInputs = {
6
+ unitSystem: 'metric',
7
+ batteryCapacityMah: 10000,
8
+ voltageNominal: 22.2,
9
+ averageCurrentAmps: 18,
10
+ cruiseSpeedKmh: 45,
11
+ oneWayDistanceKm: 6,
12
+ targetHoverTimeMin: 5,
13
+ windSpeedKmh: 12,
14
+ windDirection: 'headwind',
15
+ reservePolicyPercent: 20,
16
+ };
17
+
18
+ function parseNumberField(val: unknown, fallback: number): number {
19
+ return typeof val === 'number' && !Number.isNaN(val) ? val : fallback;
20
+ }
21
+
22
+ function parseUnitSystem(val: unknown): UnitSystem {
23
+ return val === 'imperial' ? 'imperial' : 'metric';
24
+ }
25
+
26
+ function parseWindDirection(val: unknown): WindDirection {
27
+ if (val === 'tailwind' || val === 'crosswind') return val;
28
+ return 'headwind';
29
+ }
30
+
31
+ export function loadSavedInputs(): MissionInputs {
32
+ try {
33
+ const raw = localStorage.getItem(STORAGE_KEY);
34
+ if (!raw) return DEFAULT_MISSION_INPUTS;
35
+ const parsed = JSON.parse(raw);
36
+ if (!parsed || typeof parsed !== 'object') return DEFAULT_MISSION_INPUTS;
37
+
38
+ return {
39
+ unitSystem: parseUnitSystem(parsed.unitSystem),
40
+ batteryCapacityMah: parseNumberField(parsed.batteryCapacityMah, DEFAULT_MISSION_INPUTS.batteryCapacityMah),
41
+ voltageNominal: parseNumberField(parsed.voltageNominal, DEFAULT_MISSION_INPUTS.voltageNominal),
42
+ averageCurrentAmps: parseNumberField(parsed.averageCurrentAmps, DEFAULT_MISSION_INPUTS.averageCurrentAmps),
43
+ cruiseSpeedKmh: parseNumberField(parsed.cruiseSpeedKmh, DEFAULT_MISSION_INPUTS.cruiseSpeedKmh),
44
+ oneWayDistanceKm: parseNumberField(parsed.oneWayDistanceKm, DEFAULT_MISSION_INPUTS.oneWayDistanceKm),
45
+ targetHoverTimeMin: parseNumberField(parsed.targetHoverTimeMin, DEFAULT_MISSION_INPUTS.targetHoverTimeMin),
46
+ windSpeedKmh: parseNumberField(parsed.windSpeedKmh, DEFAULT_MISSION_INPUTS.windSpeedKmh),
47
+ windDirection: parseWindDirection(parsed.windDirection),
48
+ reservePolicyPercent: parseNumberField(parsed.reservePolicyPercent, DEFAULT_MISSION_INPUTS.reservePolicyPercent),
49
+ };
50
+ } catch {
51
+ return DEFAULT_MISSION_INPUTS;
52
+ }
53
+ }
54
+
55
+ export function saveInputs(inputs: MissionInputs): void {
56
+ try {
57
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(inputs));
58
+ } catch {}
59
+ }
@@ -0,0 +1,78 @@
1
+ export interface DroneMissionBatteryReservePlannerUI {
2
+ [key: string]: unknown;
3
+ title: string;
4
+ subtitle: string;
5
+ description: string;
6
+ sections: {
7
+ batteryPropulsion: string;
8
+ flightAtmosphere: string;
9
+ };
10
+ inputs: {
11
+ unitSystemLabel: string;
12
+ metricLabel: string;
13
+ imperialLabel: string;
14
+ presetLabel: string;
15
+ batteryCapacityLabel: string;
16
+ batteryVoltageLabel: string;
17
+ averageCurrentLabel: string;
18
+ cruiseSpeedLabel: string;
19
+ oneWayDistanceLabel: string;
20
+ targetHoverTimeLabel: string;
21
+ windSpeedLabel: string;
22
+ windDirectionLabel: string;
23
+ windHeadwindLabel: string;
24
+ windTailwindLabel: string;
25
+ windCrosswindLabel: string;
26
+ reservePolicyLabel: string;
27
+ };
28
+ presets: {
29
+ mappingSurvey: string;
30
+ fpvRecon: string;
31
+ cinematicInspection: string;
32
+ microRecon: string;
33
+ surveyMeta: string;
34
+ scoutMeta: string;
35
+ hoverMeta: string;
36
+ };
37
+ results: {
38
+ totalCapacityEnergy: string;
39
+ usableEnergy: string;
40
+ reserveEnergyBuffer: string;
41
+ totalAutonomyTime: string;
42
+ maxSafeMissionRadius: string;
43
+ outboundLegTime: string;
44
+ targetHoverTime: string;
45
+ returnLegTime: string;
46
+ totalMissionTime: string;
47
+ remainingEnergyLanding: string;
48
+ feasibilityStatus: string;
49
+ voltageSagSubLabel: string;
50
+ maxRadiusSubLabel: string;
51
+ powerSubLabel: string;
52
+ };
53
+ statusBadges: {
54
+ optimalTitle: string;
55
+ optimalSubtitle: string;
56
+ tightTitle: string;
57
+ tightSubtitle: string;
58
+ criticalTitle: string;
59
+ criticalSubtitle: string;
60
+ exceededTitle: string;
61
+ exceededSubtitle: string;
62
+ };
63
+ chart: {
64
+ batteryProfileTitle: string;
65
+ modelTitle: string;
66
+ windLabel: string;
67
+ homeNode: string;
68
+ targetNode: string;
69
+ landNode: string;
70
+ launchPadLabel: string;
71
+ surveyHoverLabel: string;
72
+ safeRadiusLabel: string;
73
+ outboundSegment: string;
74
+ targetSegment: string;
75
+ returnSegment: string;
76
+ reserveSegment: string;
77
+ };
78
+ }
package/src/tools.ts CHANGED
@@ -8,6 +8,7 @@ import { DRONE_BATTERY_C_RATING_CALCULATOR_TOOL } from './tool/drone-battery-c-r
8
8
  import { FPV_DRONE_THRUST_TO_WEIGHT_RATIO_TOOL } from './tool/fpv-drone-thrust-to-weight-ratio/index';
9
9
  import { DRONE_MOTOR_PROPELLER_CALCULATOR_TOOL } from './tool/drone-motor-propeller-calculator/index';
10
10
  import { FPV_DRONE_SPEED_CALCULATOR_TOOL } from './tool/fpv-drone-speed-calculator/index';
11
+ import { DRONE_MISSION_BATTERY_RESERVE_PLANNER_TOOL } from './tool/drone-mission-battery-reserve-planner/index';
11
12
  import type { ToolDefinition } from './types';
12
13
 
13
14
  export const ALL_TOOLS: ToolDefinition[] = [
@@ -20,6 +21,7 @@ export const ALL_TOOLS: ToolDefinition[] = [
20
21
  FPV_DRONE_THRUST_TO_WEIGHT_RATIO_TOOL,
21
22
  DRONE_MOTOR_PROPELLER_CALCULATOR_TOOL,
22
23
  FPV_DRONE_SPEED_CALCULATOR_TOOL,
24
+ DRONE_MISSION_BATTERY_RESERVE_PLANNER_TOOL,
23
25
  ];
24
26
 
25
27
  export {
@@ -32,4 +34,6 @@ export {
32
34
  FPV_DRONE_THRUST_TO_WEIGHT_RATIO_TOOL,
33
35
  DRONE_MOTOR_PROPELLER_CALCULATOR_TOOL,
34
36
  FPV_DRONE_SPEED_CALCULATOR_TOOL,
37
+ DRONE_MISSION_BATTERY_RESERVE_PLANNER_TOOL,
35
38
  };
39
+