๐ A minimal, zero-dependency 2nd-order damped harmonic oscillator solver for haptic actuator physics & motor 5 key parameters.
ไธไธบ็กฌไปถๅทฅ็จๅธๅ็ฎๆณๅผๅ่ ๆ้ ็่ฝป้็บง่งฆ่ง้ฉฌ่พพ๏ผLRA / VCM๏ผไบ้ถ็ฉ็ๆฑ่งฃๅจไธๅจๆไฝ็งปไปฟ็ๅผๆใ
English | ็ฎไฝไธญๆ | ๐ ๐ Online Live Studio Demo
- ๐ Interactive Web Studio: Open
docs/index.htmlor visit Online Live Studio Demo to tweak parameters in real-time with synchronized 2D haptic motor physics animation!
Below is the dynamic simulation generated by ansv-haptics-sim showing a full haptic actuator lifecycle (Transient Rise
ansv-haptics-sim is a lightweight, open-source 2nd-order harmonic oscillator solver for educational demonstration and haptic actuator physics modeling.
๐ ๏ธ Developer Note:
My primary engineering stack for industrial simulation and data acquisition has historically been LabVIEW. As an individual developer with limited bandwidth, I am currently learning and exploring JavaScript for Web-based physics visualization in my spare time. I will refine and update this open-source repository as time permits. Community contributions and feedback are warmly welcome!๐ Feel free to check out my open lab page at ansv.net/simulations/ for more simulation demos.
The system dynamics are governed by the 2nd-order linear differential equation:
| Parameter | Symbol | Description | Default Value | Unit |
|---|---|---|---|---|
mass |
Moving Mass |
0.0015 (1.5g) |
||
stiffness |
Spring Stiffness | 800 |
||
damping |
Damping Coefficient | 0.10 |
||
bl |
Force Factor / BL Product | 1.2 |
|
|
current |
Drive Current Peak | 0.4 |
|
Derived Key Metrics:
-
Resonant Frequency (
$f_0$ ):$$f_0 = \frac{1}{2\pi}\sqrt{\frac{k}{m}} \quad (\text{Hz})$$ -
Acceleration Response (
$a$ ):$$a(t) = \frac{d^2x/dt^2}{9.81} \quad (\text{G})$$
๐ ๏ธ Roadmap Note:
The following advanced Motor Control algorithms and simulation features are currently [Under Active Development / Planned], and will be rolled out in upcoming releases:
-
๐ [Planned] Overdrive Control (Fast Transient Rise): Applies a higher-than-rated drive voltage/current during the initial phase (first 10โ20ms) to accelerate kinetic energy accumulation, significantly shortening the transient rise time.
-
๐ [Planned] Active Braking (Active Deceleration): Applies a 180ยฐ phase-inverted braking pulse at the end of the haptic effect to actively counteract kinetic energy, reducing ring-down decay time by >60% for a crisp "button-click" feel.
-
๐ [Planned] Closed-Loop Resonance Tracking (Auto-Resonance): Monitors Back-EMF or current phase angle to dynamically adjust drive frequency, keeping the actuator locked exactly at its measured resonant frequency (
$f_0$ ).
To illustrate the underlying data flow and Euler numerical integration loop of the physics engine, below is the core execution flowchart of ansv-haptics-sim:
flowchart TD
A[1. Initialize Actuator Params m, k, c, BL] --> B[2. Import Drive Waveform I t]
B --> C[3. Init Physical State x=0, v=0]
C --> D[4. Enter Time-step Loop dt]
D --> E["5. Compute Lorentz Force: F = BL * I(t)"]
E --> F["6. Compute Acceleration: a = (F - c*v - k*x) / m"]
F --> G["7. Integrate Velocity: v = v + a*dt"]
G --> H["8. Integrate Displacement: x = x + v*dt"]
H --> I{9. Reached Stop Time?}
I -- No --> D
I -- Yes --> J["10. Export Time-Domain Data (x, v, a)"]
Figure 2:
ansv-haptics-simNumerical Integration Solver Flowchart.
# Run unit tests
npm test
# Generate SVG simulation graph (Supports English & Chinese CLI output)
npm run build:svg
# Run with custom parameters & English terminal CLI output
node generate_svg.js --lang=en --mass=0.002 --stiffness=950 --bl=1.5 --current=0.5
# Run with Chinese terminal CLI output
node generate_svg.js --lang=zh --mass=0.002 --stiffness=950const { solveBasicDampedOscillator } = require('./index');
// Define custom motor parameters:
const myMotorParams = {
mass: 0.0015, // Mass m = 1.5g (0.0015 kg)
stiffness: 800, // Stiffness k = 800 N/m
damping: 0.10, // Damping c = 0.10 Ns/m
bl: 1.2, // BL = 1.2 N/A
current: 0.4, // Current I = 0.4 A
driveType: 'ac', // 'ac' for sine wave drive, 'dc' for step drive
driveDuration: 0.20 // 200ms power-on duration
};
// Solve 260ms simulation (0.1ms step size)
const res = solveBasicDampedOscillator(myMotorParams, 0.260, 0.0001);
console.log(`๐ Resonant Frequency (f0): ${res.f0Hz} Hz`);
console.log(`๐ Steady-State Amplitude: ยฑ${Math.max(...res.displacement.slice(600, 1800))} mm`);- ๐ Personal Tech Website: https://ansv.net
- ๐ฑ WeChat Official Account: ใANSVๅพฎๅๆง่กๅจใ
- ๐ก Zhihu Column: Zhihu@ansv-net
-
v1.2.1(2026-08-20)- ๐จ Web Live Studio UI & High-DPI Polish: Sleek dark mode visual overhaul, custom glow sliders, responsive mobile layout, and sharp High-DPI canvas rendering.
- โฏ๏ธ Playback Controls: Added Play/Pause and Re-trigger controls for waveforms and spring-mass dynamics.
- ๐ฑ Mobile Responsiveness: Optimized touch targets and adaptive stats grid for smartphone displays.
-
v1.2.0(2026-07-31)- ๐ Launched Zero-Dependency Web Live Studio (
docs/index.html). - ๐๏ธ Real-Time Parameter Tuning & i18n: Interactive Web UI with Chinese/English language toggle, sliders to dynamically tweak
$m, k, c, BL, I$ and instantly recompute waveforms. - ๐งฒ 2D Haptic Motor Motion Simulation: Added synchronized 2D spring and moving mass physics animation in Canvas.
- ๐ฏ Presets: One-click switching between Standard LRA, Heavy VCM, High Damping Fast Cutoff, and Soft Spring Ring-down.
- ๐ Launched Zero-Dependency Web Live Studio (
-
v1.1.0(2026-07-31)- ๐ Added Mermaid flowchart for core numerical integration solver architecture.
- โก Implemented AC sine resonance drive & full haptic lifecycle (Rise
$\rightarrow$ 200ms Steady-State$\rightarrow$ Ring-down). - ๐จ Added
--lang=zh/enCLI flag and clip-path sequential SVG vector wave renderer. - ๐ ๏ธ Updated MIT License and personal developer background notes.
-
v1.0.0(2026-07-30)- ๐ Initial open-source release: Minimal 2nd-order forced damped harmonic oscillator solver (
$m, k, c, BL, I$ motor 5 key parameters).
- ๐ Initial open-source release: Minimal 2nd-order forced damped harmonic oscillator solver (
MIT License ยฉ 2026 ansv.net