Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 89 additions & 14 deletions linkhub-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ outside the 3D viewport, and continue updating from live telemetry.
The scene's text overlay keeps only arming/mode, attitude, and motor/rotor RPM;
swash, servo, and yaw-control details remain in their dedicated panels.

The blue hub rotates with the rotor. The red checkerboard instrument bay carries
the flight controller, sensors and counter-rotation motor. The motor turns the
bay relative to the spinning hub to hold a steady world heading.

The 3D rotor retains RPM-driven spin. Each blade separately feathers about its
spanwise axis using live S1/S2/S3 collective and cyclic travel, sampled at its
current azimuth relative to the stationary swashplate. A two-line cross centered
at each blade tip rotates with its pitch to make feathering easier to see.
The hub and supports do
not tilt with the swash commands; vehicle attitude still follows its quaternion.
Blade travel uses the same normalized, servo-derived coordinates as the compact
instruments, with an illustrative 30-degree scale, not measured blade angles or
a calibrated linkage model. Without swash telemetry the blades are shown unpitched.
The hub and supports do not tilt with the swash commands; vehicle attitude still
follows its quaternion. Blade pitch uses calibrated servo decoding, distinct from
the compact widgets' normalized travel; see [Blade collective and cyclic](#blade-collective-and-cyclic).
The camera automatically centers and fits the full swept rotor, including tip crosses, to the viewport,
with 2% clearance at each edge. It refits on resize and attitude/position changes;
using the swept envelope avoids zoom pulsing as the blades spin.
Expand Down Expand Up @@ -164,17 +166,34 @@ offline reloads.

The default demo is a synthetic bench experiment, not automatic flight playback:

On each page load a non-modal tutorial highlights the next real control with a
red box. Follow the instructions, then click **Next**; **Skip tutorial** dismisses
the guide without running commands or changing experiment/motor state.
The final **Finish** returns keyboard focus to the command input. The walkthrough
is demo-only, is absent from recorded replay, and can be restarted by refreshing
(which also resets the synthetic experiment).
It first explains RAWES's wind-driven rotor kite and ground-generator pumping
cycle, the purpose of the bench interface, and how the synthetic bench differs
from flight. It identifies the real kit's ArduPilot traditional-helicopter
configuration, distinct from the demo's simplified controller.
A UI/panel overview follows, then the **Cameras** dialog and a sample
QR before experiment creation.
The QR encodes a demo message, not a pairing URL: it does not connect a phone,
request camera access, or record video. The guide explains the real same-network
phone setup separately.

1. Click **Start Experiment**, enter a name, and start. Allow the simulated
snapshot check to complete (about one second; the UI polls every two seconds).
2. Enter `run passive` in the terminal. The normal controller arms, waits for
simulated heli runup, enters GUIDED_NOGPS, and verifies three seconds of
quiet attitude before enabling passive controls.
3. Keep the terminal input focused for keyboard controls: arrow keys for
roll/pitch, `,`/`.` for yaw, `-`/`=` for thrust, and Space to recapture.
Open **Yaw** and **Wobble** for synthetic live diagnostics.
4. The simulated motor connects automatically, stopped. To spin the rotor,
3. The simulated motor connects automatically, stopped. To spin the rotor,
set its speed and click **Start**. The drive is independent of vehicle arming:
this is a fake external bench motor, not a rotor flight motor.
4. Return to the terminal input and keep it focused for keyboard controls: arrow keys for
roll/pitch, `,`/`.` for yaw, `-`/`=` for thrust, and Space to recapture.
The `=` key (the +/= key without Shift) increases thrust; `-` decreases it.
Open **Yaw** and **Wobble** for synthetic live diagnostics.
5. Add segment labels with `experiment mark LABEL`. Click **Stop** to ramp the
motor down, wait for rotor spin-down, apply safe-off, and finish.

Expand All @@ -186,13 +205,36 @@ lease and five-second full-scale ramp as the real panel. The simulated bench
restrains body roll/pitch: arrow keys change the production roll/pitch targets,
producing sustained cyclic swash and individual blade feathering rather than
tilting the whole vehicle to cancel the error. Yaw remains free to respond.
Rotor inertia, speed-dependent vibration, swash outputs, and a simple yaw PID produce
related telemetry instead of independent random curves. PID gain edits affect
the synthetic response. Unsupported commands, inputs, and endpoints fail
Rotor inertia, speed-dependent vibration, actuator outputs, and control feedback produce
related telemetry instead of independent random curves. A simplified
arduloop-style cascade runs at 400 Hz: quaternion attitude error produces
shaped, rate/acceleration-limited body-rate targets, followed by per-axis
filtered PID + rate feedforward, integrator limits, and actuator anti-windup.
The cyclic outputs drive the swash telemetry while the rigid bench mount reacts
roll/pitch torque. Only small rotor-driven vibration tilts the body; this is not
a free-flight roll/pitch plant. Live `ATC_ANG_*` and `ATC_RAT_*` gains affect the
actuator response even with the external drive stopped.

Yaw uses an independent finite-torque motor/governor state and rigid 10:1
gearing, following the structure of the
[simulation yaw plant](../design/simulation.md#yaw-motor-plant).
Body yaw rate is motor shaft speed divided by the gear ratio minus rotor
speed. Thus the external drive can spin the hub while disarmed or with
compensation disabled; arming alone does not hold heading. In passive mode,
the yaw rate PID and a simplified servo-output/gyro trim observer command the
compensator. `ENTER_PASSIVE` accepts a fixed nonnegative trim seed or a negative
seed for adaptation, following the
[flight-stack command contract](../design/flight_stack.md#52-yaw-actuator-boundary-and-trim-observer).
ESC RPM follows actual simulated motor speed, including acceleration and
coast-down, rather than instantaneously following throttle. Current is an
illustrative torque-based estimate, not a calibrated electrical model.

Unsupported commands, inputs, and endpoints fail
explicitly rather than pretending to perform calibration or reboot.

The implementation stays inside [src/demo/](src/demo/):
[simulator.ts](src/demo/simulator.ts) owns the fake plant,
[rate-controller.ts](src/demo/rate-controller.ts) owns its simplified rate PID,
[simulated-backend.ts](src/demo/simulated-backend.ts) owns HTTP-shaped state and
experiment/motor endpoints, and [journal.ts](src/demo/journal.ts) shares finite
cursor reads with recorded replay. Only
Expand All @@ -207,8 +249,11 @@ safe-off and short simulated runup overrides. Hardware journal samples informed
the message shapes and approximate bench RPM/rate ranges; this is **not**
measured telemetry, a calibrated digital twin, ArduPilot/Lua execution, or
flight-physics validation. Profiles cap local delivery at the model's 100 Hz
sample rate. Throughput is an estimate at 64 bytes per frame, not real link
bandwidth. Suspended-tab catch-up and journal memory are bounded. Cameras,
telemetry sample rate. The controller omits ArduPilot's full target shaping,
notches, pirouette compensation, spool logic, and EKF; roll/pitch omit detailed
rotor aerodynamics and tether mechanics. Throughput is an estimate at 64 bytes
per frame, not real link bandwidth. Suspended-tab catch-up and journal memory
are bounded. Cameras,
NTP, physical links, gauge CSVs, onboard logs, and experiment files are not
implemented; clock/snapshot checks are clearly simulated and no phones are
connected.
Expand Down Expand Up @@ -875,6 +920,36 @@ Position, attitude, target, and RPM are display-only smoothed. The smoothing
time constant is 80 ms. The rotor holds the last valid RPM through telemetry
gaps; disconnects and generation changes clear reconstructed state.

### Blade collective and cyclic

The shared live/demo rotor feathers each blade about its own span, rather than
tilting the whole disk to represent cyclic. The pose comes from received
`SERVO_OUTPUT_RAW` outputs 1–3 on port 0, not attitude targets or keyboard
commands, and remains visible during disarmed swash setup.

The H3-120 inverse in [swashplate.ts](src/swashplate.ts) first undoes each
servo's trim, reversal and optional `H_SW_LIN_SVO` correction, then recovers
roll/pitch cyclic and collective with `H_SW_COL_DIR` and `H_COL_MIN/MAX`.
Collective is mapped to `H_COL_ANG_MIN/MAX`; cyclic uses the estimated 0.3 rad
per normalized unit from the rotor definition. Each blade receives collective
plus the azimuth-dependent cyclic harmonic used by
[the simulation swash model](../simulation/swashplate.py).
The mesh, outline, blade-identification dots and tip crosses feather together;
housings and hub structure remain rigid.

Calibration is read from the vehicle on connection/reconnection and generation
changes, with subsequent `PARAM_VALUE` updates applied live. The synthetic demo
uses the same path against its editable local parameter map; the experiment
snapshot is separate. Servo-pose changes use the same 80 ms display smoothing.
Missing or unsupported calibration is reported in the terminal without guessed
defaults. Until calibration and valid outputs arrive, or after one second
without valid servo telemetry, the blades are drawn unfeathered. Disconnects
and generation changes clear the reconstruction.

This is an inferred visualization of reported actuator outputs, not measured
blade travel, flap deflection, aerodynamic flapping or mechanical clearance.
The estimated cyclic scale is not a calibrated model of the Kaman linkage.

## Yaw panel

The **Yaw** summary shows live yaw rate, heading-error RMS, and RPM. Expand it
Expand Down
7 changes: 7 additions & 0 deletions linkhub-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions linkhub-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test": "vitest run"
},
"dependencies": {
"qrcode-generator": "^2.0.4",
"three": "^0.180.0"
},
"devDependencies": {
Expand Down
29 changes: 12 additions & 17 deletions linkhub-ui/src/airframe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from "three";
import type { SwashControlPositions } from "./swashplate";
import { bladePitchAtAzimuth, type BladePitchState } from "./swashplate";

// Planform from simulation/rotor_definitions/beaupoil_2026.yaml. The remaining
// dimensions are visual assumptions shared with viz3d/visualize_rotor_model.py.
Expand Down Expand Up @@ -73,20 +73,14 @@ export interface Airframe {
textures: THREE.Texture[];
}

// Illustrative travel, shared with the normalized servo widgets, not calibrated blade degrees.
const BLADE_DISPLAY_TRAVEL_RAD = Math.PI / 6;

export function updateBladePitch(airframe: Airframe, controls: SwashControlPositions | null): boolean {
let changed = false;
export function updateRotorPose(airframe: Airframe, spin: number, pitch: BladePitchState | null): boolean {
let changed = airframe.rotor.rotation.y !== spin;
airframe.rotor.rotation.y = spin;
airframe.blades.forEach((blade, index) => {
const azimuth = airframe.rotor.rotation.y + index * 2 * Math.PI / airframe.blades.length;
// Model +X is forward; a positive rotor azimuth turns toward model -Z (left).
const travel = controls === null ? 0 : controls.collectiveUpDown
+ (controls.cyclicLeftRight * Math.cos(azimuth)
+ controls.cyclicUpDown * Math.sin(azimuth)) / 2;
const pitch = travel * BLADE_DISPLAY_TRAVEL_RAD;
if (blade.rotation.x !== pitch) {
blade.rotation.x = pitch;
const angle = pitch ? bladePitchAtAzimuth(pitch, spin + index * 2 * Math.PI / airframe.blades.length) : 0;
if (blade.rotation.x !== angle) {
// Local -Z is the advancing edge; positive feathering lifts it toward +Y.
blade.rotation.x = angle;
changed = true;
}
});
Expand Down Expand Up @@ -215,15 +209,16 @@ export function buildAirframe(): Airframe {
const angle = index * 2 * Math.PI / ROTOR.bladeCount;
const arm = new THREE.Group();
arm.rotation.y = angle;

const blade = new THREE.Group();
blade.name = `blade-feather-${index + 1}`;
arm.add(blade);
blades.push(blade);

blade.add(new THREE.Mesh(bladeGeometry, wood), new THREE.LineSegments(bladeEdges, woodEdge));
const tipCross = new THREE.LineSegments(tipCrossGeometry, tipCrossMaterial);
tipCross.name = "blade-tip-cross";
tipCross.position.x = ROTOR.radiusM;
blade.add(tipCross);
arm.add(blade);
blades.push(blade);

const housingMesh = new THREE.Mesh(housingGeometry, housing);
housingMesh.position.x = housingRadius;
Expand Down
3 changes: 3 additions & 0 deletions linkhub-ui/src/demo-runtime-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LinkHubApi } from "./api";
import { DemoBackend } from "./demo-backend";
import { SimulatedBackend } from "./demo/simulated-backend";
import { DemoTutorial } from "./demo/tutorial";
import "./demo/tutorial.css";
import recording from "./demo/pumping-cycle.json";
import type { VehicleSceneOptions } from "./scene";

Expand All @@ -19,6 +21,7 @@ export function createLinkHubApi(): LinkHubApi {
if (label) label.textContent = "RAWES / SYNTHETIC DEMO / NO HARDWARE / NOTHING SAVED";
const hint = document.querySelector(".control-hint");
if (hint) hint.textContent = 'Start an experiment, then enter "run passive". Motor connects off automatically; click Start to run it. Focus terminal for keys: arrows cyclic (bench holds body roll/pitch); ,/. yaw; -/= thrust.';
queueMicrotask(() => new DemoTutorial());
return new LinkHubApi("", new SimulatedBackend().fetch);
}
document.title = "RAWES LinkHub / Recorded SITL pumping cycle";
Expand Down
49 changes: 49 additions & 0 deletions linkhub-ui/src/demo/rate-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value));

/** Small AC_PID-style subset: target/error/D filters, PID + FF, and anti-windup. */
export class DemoRateController {
desired = 0;
p = 0;
i = 0;
d = 0;
ff = 0;
output = 0;
limited = false;
private error = 0;
private derivative = 0;
private excess = 0;

constructor(
private readonly axis: "RLL" | "PIT" | "YAW",
private readonly parameter: (name: string) => number,
) {}

reset(): void {
this.desired = this.p = this.i = this.d = this.ff = this.output = 0;
this.error = this.derivative = this.excess = 0;
this.limited = false;
}

update(target: number, actual: number, dt: number, min: number, max: number, bias = 0): void {
const param = (suffix: string) => this.parameter(`ATC_RAT_${this.axis}_${suffix}`);
const filter = (previous: number, value: number, hz: number) =>
hz > 0 ? previous + (value - previous) * -Math.expm1(-2 * Math.PI * hz * dt) : value;
this.desired = filter(this.desired, target, param("FLTT"));
const error = filter(this.error, this.desired - actual, param("FLTE"));
if (dt > 0) {
this.derivative = filter(this.derivative, (error - this.error) / dt, param("FLTD"));
// Saturated axes may unwind their I-term, but must not accumulate into the limit.
if ((!this.limited || error * this.i < 0) && error * this.excess <= 0) {
this.i = clamp(this.i + param("I") * error * dt, -param("IMAX"), param("IMAX"));
}
}
this.error = error;
this.p = param("P") * error;
this.d = param("D") * this.derivative;
this.ff = this.parameter("ATC_RATE_FF_ENAB") ? param("FF") * this.desired : 0;
const output = bias + this.p + this.i + this.d + this.ff;
this.output = clamp(output, min, max);
this.excess = output - this.output;
this.limited = false;
}
}
Loading
Loading