@hackbuild/motion-net 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +152 -2
- package/dist/engine.d.ts +95 -0
- package/dist/engine.js +374 -0
- package/dist/host.d.ts +189 -0
- package/dist/host.js +735 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/layout.d.ts +43 -0
- package/dist/layout.js +80 -0
- package/dist/load.d.ts +7 -0
- package/dist/load.js +42 -0
- package/dist/motion-net.iife.js +1724 -0
- package/dist/single.d.ts +1 -0
- package/dist/single.js +2 -0
- package/dist/wasm/inline.d.ts +2 -0
- package/dist/wasm/inline.js +8 -0
- package/dist/wasm/motion_net.d.ts +48 -0
- package/dist/wasm/motion_net.js +183 -0
- package/dist/wasm/motion_net_bg.wasm +0 -0
- package/dist/wasm/motion_net_bg.wasm.d.ts +17 -0
- package/dist/weights.d.ts +89 -0
- package/dist/weights.js +203 -0
- package/package.json +37 -4
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { type StyleLabel } from "./layout.js";
|
|
2
|
+
import type { RawPrediction } from "./engine.js";
|
|
3
|
+
export type MotorSource = "procedural" | "neural" | "motion-match" | "clip" | "other";
|
|
4
|
+
export interface MotorState {
|
|
5
|
+
source: MotorSource;
|
|
6
|
+
phase: number;
|
|
7
|
+
duty: number;
|
|
8
|
+
strideFrequency: number;
|
|
9
|
+
contacts: boolean[];
|
|
10
|
+
}
|
|
11
|
+
export interface Capabilities {
|
|
12
|
+
turnInPlace: boolean;
|
|
13
|
+
minStopDistance: number;
|
|
14
|
+
headPitchBias: number;
|
|
15
|
+
}
|
|
16
|
+
export interface RootMotion {
|
|
17
|
+
x: number;
|
|
18
|
+
z: number;
|
|
19
|
+
yaw: number;
|
|
20
|
+
speed: number;
|
|
21
|
+
turnRate: number;
|
|
22
|
+
}
|
|
23
|
+
export interface GaitCommand {
|
|
24
|
+
/** Forward speed, m/s. */
|
|
25
|
+
speed: number;
|
|
26
|
+
/** Turn rate, rad/s, positive to the left. */
|
|
27
|
+
turnRate: number;
|
|
28
|
+
posture?: {
|
|
29
|
+
sit?: number;
|
|
30
|
+
down?: number;
|
|
31
|
+
bow?: number;
|
|
32
|
+
reach?: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface LocomotionBackend {
|
|
36
|
+
readonly capabilities: Capabilities;
|
|
37
|
+
update(dt: number, cmd: GaitCommand): RootMotion;
|
|
38
|
+
motorState(): MotorState;
|
|
39
|
+
}
|
|
40
|
+
export interface HostCommand extends GaitCommand {
|
|
41
|
+
/** World planar velocity, m/s; overrides `speed` and lets the dog move sideways. */
|
|
42
|
+
velocity?: {
|
|
43
|
+
x: number;
|
|
44
|
+
z: number;
|
|
45
|
+
};
|
|
46
|
+
/** World facing to turn toward, radians; overrides `turnRate`. */
|
|
47
|
+
facing?: number;
|
|
48
|
+
/** A style label to hold, or "auto" (the default) to choose by speed. */
|
|
49
|
+
style?: StyleLabel | "auto";
|
|
50
|
+
}
|
|
51
|
+
export interface Predicts {
|
|
52
|
+
predict(input: Float32Array): Promise<RawPrediction>;
|
|
53
|
+
}
|
|
54
|
+
export interface HostTuning {
|
|
55
|
+
/** Seconds between prediction requests. */
|
|
56
|
+
interval: number;
|
|
57
|
+
/** Time of trajectory sample k is start + k step, seconds. */
|
|
58
|
+
trajStart: number;
|
|
59
|
+
trajStep: number;
|
|
60
|
+
/** Time constant over which the root's own velocity gives way to the command along the trajectory, s. */
|
|
61
|
+
trajBlend: number;
|
|
62
|
+
/** Half life of the command smoothing, s. */
|
|
63
|
+
commandHalflife: number;
|
|
64
|
+
/** Half life of the seam offset when a new prediction lands, s. */
|
|
65
|
+
seamHalflife: number;
|
|
66
|
+
/** Contact on and off thresholds. */
|
|
67
|
+
contactOn: number;
|
|
68
|
+
contactOff: number;
|
|
69
|
+
/** Largest distance a pinned paw may sit from the network's paw, m. */
|
|
70
|
+
maxPin: number;
|
|
71
|
+
/** Integral gain of the speed loop that leans the trajectory until the dog's speed meets the command, 1/s. */
|
|
72
|
+
speedGain: number;
|
|
73
|
+
/** Largest lean of the speed loop either way, m/s. */
|
|
74
|
+
leanRange: number;
|
|
75
|
+
/** Share of the network's planted paw drift the root takes over, 0 to 1. */
|
|
76
|
+
plantFollow: number;
|
|
77
|
+
/** Half life of the slow pull of the root toward its pinned paws, s; 0 turns it off. */
|
|
78
|
+
plantHalflife: number;
|
|
79
|
+
/** Half life of the low pass on the root's share of the paw drift, s. */
|
|
80
|
+
followHalflife: number;
|
|
81
|
+
/** Speeds (m/s) where auto style moves up from Idle, Walk, Trot. */
|
|
82
|
+
walkAt: number;
|
|
83
|
+
trotAt: number;
|
|
84
|
+
canterAt: number;
|
|
85
|
+
}
|
|
86
|
+
export declare const DEFAULT_TUNING: HostTuning;
|
|
87
|
+
type V3 = [number, number, number];
|
|
88
|
+
export interface PawState {
|
|
89
|
+
/** Raw contact value of the network, sampled now. */
|
|
90
|
+
contact: number;
|
|
91
|
+
stance: boolean;
|
|
92
|
+
/** Pinned world position in the host frame while in stance. */
|
|
93
|
+
pin: V3 | null;
|
|
94
|
+
/** Phase since touchdown over the last stride period, 0 to 1. */
|
|
95
|
+
phase: number;
|
|
96
|
+
}
|
|
97
|
+
/** Drives the quadruped network and fills the gait motor state. */
|
|
98
|
+
export declare class QuadrupedHost implements LocomotionBackend {
|
|
99
|
+
private readonly predictor;
|
|
100
|
+
private readonly styles;
|
|
101
|
+
readonly capabilities: Capabilities;
|
|
102
|
+
readonly tuning: HostTuning;
|
|
103
|
+
/** Root in the host frame: position on the ground and yaw (positive left). */
|
|
104
|
+
root: {
|
|
105
|
+
x: number;
|
|
106
|
+
z: number;
|
|
107
|
+
yaw: number;
|
|
108
|
+
};
|
|
109
|
+
/** Root velocity in the host frame, m/s, and turn rate, rad/s. */
|
|
110
|
+
rootVelocity: {
|
|
111
|
+
x: number;
|
|
112
|
+
z: number;
|
|
113
|
+
turnRate: number;
|
|
114
|
+
};
|
|
115
|
+
/** World bone positions, host frame, x y z per bone. */
|
|
116
|
+
readonly positions: Float32Array<ArrayBuffer>;
|
|
117
|
+
/** World bone rotations, host frame, x y z w per bone. */
|
|
118
|
+
readonly rotations: Float32Array<ArrayBuffer>;
|
|
119
|
+
readonly paws: PawState[];
|
|
120
|
+
style: StyleLabel;
|
|
121
|
+
/** Request to arrival of the last prediction, wall clock ms (measured). */
|
|
122
|
+
latencyMs: number;
|
|
123
|
+
/** Request to first use of the last prediction, ms on the host clock: what playback skips (measured). */
|
|
124
|
+
lagMs: number;
|
|
125
|
+
/** Evaluation time of the last prediction where it ran, ms (measured). */
|
|
126
|
+
evalMs: number;
|
|
127
|
+
/** Seconds since the playing prediction was requested; past 0.5 the dog holds. */
|
|
128
|
+
predictionAge: number;
|
|
129
|
+
/** Horizontal travel of each stance paw this frame, m, after pinning and before. */
|
|
130
|
+
footSlide: number[];
|
|
131
|
+
rawFootSlide: number[];
|
|
132
|
+
/** Distance from each pinned paw to where the network puts it, m; 0 when free. */
|
|
133
|
+
pinGap: number[];
|
|
134
|
+
/** Predictions received and requests sent. */
|
|
135
|
+
received: number;
|
|
136
|
+
requested: number;
|
|
137
|
+
private t;
|
|
138
|
+
private yaw;
|
|
139
|
+
private px;
|
|
140
|
+
private pz;
|
|
141
|
+
private cmdV;
|
|
142
|
+
private cmdW;
|
|
143
|
+
/** Speed added to the trajectory by the speed loop, m/s. */
|
|
144
|
+
private lean;
|
|
145
|
+
/** Ground speed of the root, smoothed over 0.1 s, m/s. */
|
|
146
|
+
private speedNow;
|
|
147
|
+
/** Turn rate of the root, smoothed over 0.1 s, rad/s (network sign). */
|
|
148
|
+
private turnNow;
|
|
149
|
+
private turnLean;
|
|
150
|
+
/** Pinned paw positions, network frame world. */
|
|
151
|
+
private readonly pins;
|
|
152
|
+
/** The network's paw ends last frame, network frame world x z. */
|
|
153
|
+
private readonly follow;
|
|
154
|
+
/** Last knee bend direction per leg, root frame. */
|
|
155
|
+
private readonly bend;
|
|
156
|
+
private readonly prevRaw;
|
|
157
|
+
private active;
|
|
158
|
+
private pending;
|
|
159
|
+
private lastRequest;
|
|
160
|
+
private readonly pose;
|
|
161
|
+
private readonly fresh;
|
|
162
|
+
private readonly seam;
|
|
163
|
+
private seamOn;
|
|
164
|
+
private readonly input;
|
|
165
|
+
private readonly lastSite;
|
|
166
|
+
private readonly lastRawSite;
|
|
167
|
+
private readonly release;
|
|
168
|
+
private readonly touch;
|
|
169
|
+
private lastCmd;
|
|
170
|
+
constructor(predictor: Predicts, styles: Record<StyleLabel, ArrayLike<number>>, tuning?: Partial<HostTuning>);
|
|
171
|
+
/** Places the dog, host frame, and forgets any motion. */
|
|
172
|
+
reset(x: number, z: number, yaw: number): void;
|
|
173
|
+
update(dtIn: number, cmd: HostCommand): RootMotion;
|
|
174
|
+
motorState(): MotorState;
|
|
175
|
+
/** Smooths the command into a network frame world velocity and yaw rate, and picks the style. */
|
|
176
|
+
private steer;
|
|
177
|
+
private toLocal;
|
|
178
|
+
private schedule;
|
|
179
|
+
private land;
|
|
180
|
+
/** Current pose and velocities, the trajectory and the style pose, in the current root frame. */
|
|
181
|
+
private buildInput;
|
|
182
|
+
/** World transforms, pins, phases and slide readouts from the current pose. */
|
|
183
|
+
private output;
|
|
184
|
+
/** Moves the paw end to `target` (root frame) and bends the knee to keep both limb lengths. */
|
|
185
|
+
private pinLeg;
|
|
186
|
+
/** The last command passed to update. */
|
|
187
|
+
get command(): HostCommand;
|
|
188
|
+
}
|
|
189
|
+
export {};
|