Commit 2f43a3c
fix(ik): _random_q() silently produces garbage for non-finite joint limits (#648)
* fix(ik): _random_q() silently produces garbage for non-finite joint limits
_random_q() (used by every numeric IK solver -- IK_NR/IK_GN/IK_LM/IK_QP --
to seed random restarts) sampled directly from a joint's qlim with no
check that the limits were actually finite. A joint with a bad
(non-finite, e.g. inf/-inf) limit baked into its model's own data --
this was the real root cause behind #485's KinovaGen3 report, whose
own qlim was fixed separately without ever patching this gap -- caused
either a silent NaN joint value or an opaque internal numpy error
(OverflowError: high - low range exceeds valid bounds, depending on
which RNG code path is hit), instead of a clear diagnostic pointing at
the actual bad joint.
Now raises a ValueError naming the offending joint index(es) and their
bad qlim before sampling, matching the existing convention elsewhere in
this code (e.g. ETS.qlim already raises for an unset prismatic limit)
of failing loudly rather than propagating a silent bad value.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(ik): apply the same non-finite-qlim guard to the C++ IK fast path
ik.py's _random_q() (fixed in the previous commit) and ik.cpp's own
_rand_q() are separate implementations reached by different public
entry points -- ikine_LM/ikine_NR/ikine_GN/ikine_QP go through the
pure-Python IK_LM/IK_NR/IK_GN/IK_QP classes, while ik_LM/ik_NR/ik_GN
(documented as "a fast solver implemented in C++") go through
ik.cpp via nanobind. The C++ side had the identical gap with no
guard at all: sampling a non-finite qlim via raw Eigen arithmetic
silently produced a NaN q, which the solve loop then burned through
every one of its random restarts on before returning a "failed"
solution containing NaN -- no exception, no diagnostic.
Since RTB's public API is "IK" regardless of which implementation
backs a given method name, both solvers now enforce the same
contract: _rand_q() throws nb::value_error (mapping to a Python
ValueError, matching the Python-side message) before sampling if
any joint's qlim is non-finite.
Verified by rebuilding the compiled extension locally and confirming
the fail-then-pass behavior directly: pre-fix, ets.ik_LM() silently
returned (q=[nan], success=0) after 101 wasted searches; post-fix,
it raises ValueError immediately.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 8caa363 commit 2f43a3c
3 files changed
Lines changed: 63 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
290 | 294 | | |
291 | 295 | | |
292 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
293 | 310 | | |
294 | 311 | | |
295 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
409 | 412 | | |
410 | 413 | | |
411 | 414 | | |
412 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
413 | 426 | | |
414 | 427 | | |
415 | 428 | | |
416 | 429 | | |
417 | | - | |
| 430 | + | |
418 | 431 | | |
419 | 432 | | |
420 | 433 | | |
421 | 434 | | |
422 | 435 | | |
423 | 436 | | |
424 | | - | |
425 | | - | |
426 | | - | |
| 437 | + | |
427 | 438 | | |
428 | 439 | | |
429 | 440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
849 | 880 | | |
850 | 881 | | |
851 | 882 | | |
0 commit comments