also looking at this
feat: model VTOL electrical consumption and battery authority
#81
15 files
+605
-28
| @@ -1,11 +1,15 @@ | ||
| 1 | 1 | import type { VehicleProfile } from '../types' |
| 2 | 2 | import { createVtolPlant, vtolModel } from './plant' |
| 3 | 3 | import { createVtolVehicleHoverController } from './controller' |
| 4 | import { renderVtolElectricalMeasurement, vtolElectricalMaximumW } from './power' | |
| 4 | 5 | export const vtolHoverScenarios = Object.freeze(['hover', 'imu-loss', 'position-loss', 'vehicle-sensor-loss', 'host-loss', 'rc-override', 'kill'] as const) |
| 5 | 6 | |
| 6 | 7 | /** Development hover mission only. Front/cruise/back transitions remain unimplemented. */ |
| 7 | export function createVtolHoverProfile(scenario = 'hover'): VehicleProfile { | |
| 8 | export function createVtolHoverProfile(scenario = 'hover', options: { electrical?: boolean } = {}): VehicleProfile { | |
| 8 | 9 | if (!(vtolHoverScenarios as readonly string[]).includes(scenario)) throw new RangeError('Unknown VTOL hover scenario') |
| 10 | const electrical = options.electrical | |
| 11 | if (electrical !== undefined && typeof electrical !== 'boolean') throw new TypeError('Invalid VTOL electrical model selection') | |
| 12 | const batteryModel = electrical ? Object.freeze({ evidence: 'modeled-vehicle-battery-v1' as const, capacityWh: 50, maximumSourceW: vtolElectricalMaximumW(vtolModel.maxRotorThrustN, vtolModel.maxPusherThrustN) }) : undefined | |
| 9 | 13 | return { |
| 10 | 14 | scenario, vehicle: 'vtol', name: 'Owned VTOL hover development', evidence: 'modeled-vehicle-profile', physicalFlightEnabled: false, |
| 11 | 15 | actuators: [ |
| @@ -27,11 +31,12 @@ export function createVtolHoverProfile(scenario = 'hover'): VehicleProfile { | ||
| 27 | 31 | ], |
| 28 | 32 | }, |
| 29 | 33 | scenarios: vtolHoverScenarios, |
| 34 | ...(batteryModel ? { batteryModel } : {}), | |
| 30 | 35 | createSession() { |
| 31 | return { createPlant: createVtolPlant, createController: createVtolVehicleHoverController, | |
| 36 | return { createPlant: batteryModel ? () => createVtolPlant({ electricalCapacityWh: batteryModel.capacityWh }) : createVtolPlant, createController: createVtolVehicleHoverController, | |
| 32 | 37 | renderMeasurement(state, atMs, reference) { |
| 33 | 38 | return { version: 1, evidence: 'modeled-vehicle-sensors', vehicle: 'vtol', sequence: Math.floor(atMs / 20) + 1, reference, capturedAtMs: atMs, receivedAtMs: atMs + 60, |
| 34 | values: { onSurface: state.onSurface, stopped: Math.hypot(...state.velocityMps) <= 0.2, airspeedMps: Math.round((state.details.airspeedMps as number) * 1000) / 1000 } } | |
| 39 | values: { onSurface: state.onSurface, stopped: Math.hypot(...state.velocityMps) <= 0.2, airspeedMps: Math.round((state.details.airspeedMps as number) * 1000) / 1000, ...renderVtolElectricalMeasurement(state) } } | |
| 35 | 40 | }, |
| 36 | 41 | } |
| 37 | 42 | }, |