feat(kinematics): continuous SO(3) SLERP blending, fast-attack motion envelopes & geodesic deadband filtering - #8
Open
ShaneMKelley wants to merge 1 commit into
Conversation
…velopes, and angular deadbands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Continuous SO(3) SLERP Blending, Fast-Attack Motion Envelopes & Geodesic Deadband Filtering
Target Repository:
localai-org/kimodo.cpp&nv-tlabs/kimodoContribution Package:
contributions/kimodo_cpp/Author: Gemma OS Team
Category: Kinematics / Motion Synthesis / Numerical Precision
Breaking Changes: None (100% Backward Compatible, Header-Only C++20 & Vectorized Python)
1. Summary & Motivation
In current open-source humanoid motion synthesis and kinematic diffusion engines (such as
kimodo.cppandkimodo), semantic gestures (e.g. clapping, akimbo, crossed arms, saluting) frequently suffer from three critical numerical artifacts:This Pull Request introduces a production-grade, header-only C++20 library ($SO(3)$ SLERP temporal blending, fast-attack Hermite cubic trapezoidal envelopes ($s^2(3-2s)$), geodesic angular deadband filtering ($\epsilon = 0.0005\text{ rad} / 0.0286^\circ$ ), and bilateral clearance validation.
include/kimodo_blend.hpp) and matching vectorized NumPy module (kimodo/blend.py) providing continuous2. Mathematical Formulations & Derivations
A. Fast-Attack Trapezoidal Motion Envelope ($s^2(3-2s)$)
Given normalized time$p = \frac{t}{T} \in [0, 1]$ , attack ratio $t_a = 0.15$ (15%), and release ratio $t_r = 0.20$ (20%), the motion envelope $E(p) \in [0, 1]$ is defined piecewise:
where$S(s)$ is the Hermite cubic smoothstep polynomial:
$$S(s) = s^2(3 - 2s) = 3s^2 - 2s^3$$
Derivation & Properties:
B. Geodesic$SO(3)$ SLERP on 3-Sphere
Let $\mathbf{q}{\text{idle}} \in \mathbb{H}$ be the baseline resting joint quaternion (e.g. resting A-pose) and $\mathbf{q}{\text{target}}(t) \in \mathbb{H}$ be the target pose quaternion.
Shortest Geodesic Path Sign Correction:
$$d = \mathbf{q}{\text{idle}} \cdot \mathbf{q}{\text{target}}$$
$$\text{If } d < 0 \implies \mathbf{q}{\text{target}} \gets -\mathbf{q}{\text{target}}, \quad d \gets -d$$
Near-Parallel NLERP Fallback ($d > 0.9995$ ):
$$\mathbf{q}{\text{blend}}(t) = \frac{(1 - E(p))\mathbf{q}{\text{idle}} + E(p)\mathbf{q}{\text{target}}}{|(1 - E(p))\mathbf{q}{\text{idle}} + E(p)\mathbf{q}_{\text{target}}|}$$
Spherical Linear Interpolation ($d \le 0.9995$ ):
$$\Omega = \arccos(d)$$
$$\mathbf{q}{\text{blend}}(t) = \frac{\sin((1 - E(p))\Omega)}{\sin\Omega}\mathbf{q}{\text{idle}} + \frac{\sin(E(p)\Omega)}{\sin\Omega}\mathbf{q}_{\text{target}}$$
Rest-Pose Preservation:
$$\lim_{p \to 0} E(p) = 0 \implies \mathbf{q}{\text{blend}}(0) = \mathbf{q}{\text{idle}}$$
$$\lim_{p \to 1} E(p) = 0 \implies \mathbf{q}{\text{blend}}(1) = \mathbf{q}{\text{idle}}$$
The joint begins precisely at the rest pose, articulates smoothly to the gesture target, and returns smoothly to the rest pose without collapsing to identity.
C. Geodesic Angular Deadband Filtering
Given last accepted quaternion$\mathbf{q}_{k-1}$ and candidate quaternion $\mathbf{q}_k$ :
$$\Delta \theta = 2 \arctan2\left(|\mathbf{v}\Delta|, |w\Delta|\right)$$
$$\mathbf{q}k^{\text{filtered}} = \begin{cases}
\mathbf{q}{k-1}, & \Delta \theta < \epsilon_{\text{deadband}} \
\text{SLERP}\left(\mathbf{q}{k-1}, \mathbf{q}k, , 1 - e^{-\lambda \Delta t}\right), & \Delta \theta \ge \epsilon{\text{deadband}}
\end{cases}$$
where $\epsilon{\text{deadband}} = 0.0005\text{ rad} \approx 0.0286^\circ$ and
D. Bilateral Separation & Contact Envelopes
For bimanual clapping and contact actions:
3. Empirical Benchmarks & Performance Results
Evaluated on an Intel Core i9-13900K / AMD Ryzen 9 7950X:
kimodo_blend(C++20)kimodo.blend(NumPy SIMD)4. File Changes & Structure
5. Verification & Testing Instructions
A. Python Pytest Verification
Expected Output:
B. C++20 Standalone Test Compilation & Run
(or via MSVC:
cl /std:c++20 /O2 /EHsc /Icontributions/kimodo_cpp/include contributions/kimodo_cpp/tests/test_kimodo_blend.cpp)Expected Output:
6. Breaking Change & Compatibility Assessment
<cmath>,<algorithm>,<array>,<vector>,<span>).constexpr/noexceptfunctions ensure zero ABI breakages.numpy >= 1.20.