IntensityProcessorの震度計算バグを修正 - #7
Open
njm2360 wants to merge 3 commits 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.
概要
include/IntensityProcessor.hの上位30値抽出処理のバグ修正3件。1コミット1修正。修正内容
NaN チェックが機能していない
v != NANは NaN がどの値とも比較不等になるため常に true で、ガードとして働いていない。isnan()に置き換える。グループ枯渇時の範囲外読み
INTENSITY_PROCESS_SAMPLE_GROUP_SIZEは各Board.hで 20 に上書きされており、1グループ20サンプルに対して上位30値を取り出すループが回る。ひとつのグループを20回選んで使い切った後、21回目の読み出しで添字が20 - (20 + 1) = -1になる。昇順ソート済みのためsortedGroups[g][-1]は隣グループの最大値を指し、同じ値を二重に数える。発生条件は2つ。
max < vが成立せず、グループ0が選ばれ続けて21回目で範囲外に出るバッファが未初期化
processor = new IntensityProcessor(...)とヒープに確保しているため、静的記憶域なら効く暗黙のゼロ初期化が働かない。sortedGroupsは 300 × 20 の float で、起動直後から未初期化ヒープを読んでいた。= {}を追加する。compositeSampleとsortedGroupIndiceは使用前に全要素の書き込みとmemsetがあるため変更なし。挙動の変化
2番目の修正により、起動から数秒は30番目の値が揃わず
lastMaxValueが0になり、震度出力がスキップされる(従来はゴミ値を出力していた)。stabilityCheckCountの加算も同じ分岐のため、安定判定の開始がそのぶん遅れる。動作確認
5環境すべてビルド成功。arm-none-eabi、riscv32、xtensa のいずれでも
isnanはコンパイルできている。RP2040 の3環境はクリーンな状態だと本件と無関係な理由でビルドが通らない。
lib_depsのFreeRTOSが名前衝突で feilipu の AVR ATmega 向け Arduino_FreeRTOS_Library に解決されること、および現在の framework-arduinopico が-D __FREERTOS=1を要求することによる。確認時はlib_depsからFreeRTOSを外し-D __FREERTOS=1を追加した。別件のためplatformio.iniは変更していない。