also looking at this
feat: add bounded VTOL wind braking
#88
13 files
+447
-25
| @@ -0,0 +1,49 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { createVtolTransitionProfile } from '../../resources/functions/drone/vehicles/vtol/transition-profile' | |
| 3 | import { runVehicleSimulation } from '../../resources/functions/drone/vehicles/runtime' | |
| 4 | import { airAerodynamics } from '../../resources/functions/drone/vehicles/air/plant' | |
| 5 | import { vtolAerodynamics } from '../../resources/functions/drone/vehicles/vtol/plant' | |
| 6 | import { quaternionFromTilt } from '../../resources/functions/drone/estimation/frames' | |
| 7 | import { rotateNedToBody } from '../../resources/functions/drone/controls/physics' | |
| 8 | ||
| 9 | // Agreed actual shared-runtime function seam: force-driven wind, raw IMU/GNSS, estimator, | |
| 10 | // mission, controller and independent board leases. It does not qualify measured airframes. | |
| 11 | test('the owned VTOL completes its finite route in a declared sustained 2 m/s tailwind', () => { | |
| 12 | const profile = createVtolTransitionProfile({ electrical: true }) | |
| 13 | profile.faults = (_scenario, atMs) => ({ windMps: atMs >= 1000 ? [2, 0, 0] : [0, 0, 0] }) | |
| 14 | const result = runVehicleSimulation(profile, { seconds: 160 }) | |
| 15 | expect(result.status, JSON.stringify({ status: result.status, fault: result.fault, task: result.mission.taskId, reason: result.mission.reason })).toBe('completed') | |
| 16 | expect(result.mission.reason).toBe('landed') | |
| 17 | expect(result.path.at(-1)?.measurement?.values.onSurface).toBe(true) | |
| 18 | expect(result.board.actuators).toEqual([0, 0, 0, 0, 0, 0, 0, 0]) | |
| 19 | expect(result.board.expiresAtMs).toBeNull() | |
| 20 | expect(result.board.physicalActuationEnabled).toBe(false) | |
| 21 | }) | |
| 22 | ||
| 23 | test('the fictional VTOL wing opposes small vertical motion in either chordwise flow direction', () => { | |
| 24 | for (const u of [-2, 2]) { | |
| 25 | const up = vtolAerodynamics([u, 0, -0.01], [0, 0, 0], [0, 0, 0, 0, 0]) | |
| 26 | const down = vtolAerodynamics([u, 0, 0.01], [0, 0, 0], [0, 0, 0, 0, 0]) | |
| 27 | expect(down.forceN[2] - up.forceN[2], `body U ${u}`).toBeLessThan(0) | |
| 28 | const pitched = rotateNedToBody(quaternionFromTilt(0, 0.01), [u, 0, 0]) | |
| 29 | expect(vtolAerodynamics(pitched, [0, 0, 0], [0, 0, 0, 0, 0]).torqueNm[1], `body U ${u}`).toBeLessThan(0) | |
| 30 | } | |
| 31 | }) | |
| 32 | ||
| 33 | test('the VTOL extension preserves the declared forward pre-stall trainer curve exactly', () => { | |
| 34 | for (const alpha of [-0.28, -0.1, 0, 0.1, 0.28]) { | |
| 35 | const relative: [number, number, number] = [13 * Math.cos(alpha), 0, 13 * Math.sin(alpha)] | |
| 36 | expect(vtolAerodynamics(relative, [0.01, -0.02, 0.03], [0.2, 0.1, -0.1, 0.2, 0])).toEqual(airAerodynamics(relative, [0.01, -0.02, 0.03], [0.2, 0.1, -0.1, 0.2, 0])) | |
| 37 | } | |
| 38 | }) | |
| 39 | ||
| 40 | test('the VTOL folded-incidence curve has continuous force and pitch moment across reverse-flow angle wrapping', () => { | |
| 41 | for (const speed of [2, 8]) { | |
| 42 | const above = airAerodynamics([-speed, 0, 1e-8], [0, 0, 0], [0, 0, 0, 0, 0], true) | |
| 43 | const below = airAerodynamics([-speed, 0, -1e-8], [0, 0, 0], [0, 0, 0, 0, 0], true) | |
| 44 | expect(Math.hypot(...above.forceN.map((n, i) => n - below.forceN[i]!))).toBeLessThan(1e-5) | |
| 45 | expect(Math.hypot(...above.torqueNm.map((n, i) => n - below.torqueNm[i]!))).toBeLessThan(1e-5) | |
| 46 | expect(above.alphaRad).toBeGreaterThan(3) | |
| 47 | expect(below.alphaRad).toBeLessThan(-3) | |
| 48 | } | |
| 49 | }) | |