fix(crane_geometry): ボール接近計算のゼロ長normalized()によるNaNをガード#1378
Open
HansRobo wants to merge 1 commit into
Open
Conversation
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.
概要
crane_geometryのボール回り込みアプローチ計算において、退化入力(ボールとロボット・目標が同位置等)でゼロ長ベクトルを正規化し NaN が発生する不具合を修正します。問題
utility/crane_geometry/include/crane_geometry/geometry_operations.hppの以下の箇所で、ゼロ長ベクトルに対してEigen::Vector2d::normalized()を呼び出すと NaN が生成され、progress計算やアプローチ目標位置の算出が破綻します。computeAroundBallApproachTarget(239行付近):(ball - desired_opposite).normalized()がボールと目標の同位置で 0/0 = NaN。computeAroundBallApproachTargetDynamic(275, 276行付近):(desired_opposite - ball).normalized()および(from - ball).normalized()が同位置入力で NaN となり、progressが破綻。原因
Eigen::Vector2d::normalized()はノルム 0 に対する保護を行わず、0/0 = NaN を返します。これらの呼び出し前にゼロ長判定が存在しませんでした。修正内容
対象の各
normalized()呼び出しの前にノルムのゼロ判定(しきい値1e-9)を追加し、退化入力時に安全なフォールバックを返すようにしました。computeAroundBallApproachTarget:(ball - desired_opposite)がゼロ長の場合、from方向へオフセットした点を返す。from方向もゼロ長であれば既定方向(offset, 0)を返す。(result.closest_point - ball).normalized()はresult.distance > epsilonの分岐内でのみ実行されるため、ノルムがepsilon(既定 1e-4)を超えることが保証されており追加ガードは不要です。computeAroundBallApproachTargetDynamic:(desired_opposite - ball)と(from - ball)のいずれかがゼロ長の場合、progress = 0(初期状態 =max_offset側)にフォールバックし、dot計算を回避。なお
getIntersections(135, 142行)とgetSeparatedPoints(212行)は別PRで対応するため本PRでは変更していません。検証
colcon build(--no-rdeps)を実行し、crane_geometryがコンパイル成功することを確認(Build complete.、エラーなし)。colcon test --packages-select crane_geometry:100% tests passed, 0 tests failed out of 4(gtest 2件・copyright・xmllint)。colcon test-result --verbose:23 tests, 0 errors, 0 failures, 0 skipped。レビュー観点
computeAroundBallApproachTarget: 目標方向が定義できないときfrom方向、さらに不定なら既定方向(offset, 0)を使う妥当性。computeAroundBallApproachTargetDynamic: 退化入力時にprogress = 0(初期=大回り側)とみなす妥当性。本PRはソースコード監査ワークフローで検出・敵対的検証されたバグに対する単一修正です。