insmod_rtmouse.sh: 起動のたびにドライバとワークスペースを再ビルドするのをやめる - #24
Open
NOPLAB wants to merge 1 commit into
Open
Conversation
`raspicat.service` runs this script at every boot, and the first line never succeeds at loading the driver: - `rosstack` is a ROS 1 command and is not present on a ROS 2 system, so `$(rosstack find raspicat_ros)` expands to an empty string and the path passed to `insmod` becomes `/../RaspberryPiMouse/src/drivers/rtmouse.kuo`. - `rtmouse.kuo` is a typo for `rtmouse.ko`. `insmod` therefore always fails and the `||` branch always runs, so the kernel module is recompiled on every boot. The `colcon build --symlink-install` after the `;` is worse: it is not part of the `||` fallback, so it rebuilds the whole workspace on every boot regardless of whether the driver loaded. Use `modprobe` to load the installed module, and keep the build script as a fallback for when the module is not installed yet. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3ZzEzNKDxANptPX4QNnHn
There was a problem hiding this comment.
Pull request overview
This PR updates the RTMouse driver auto-load script used by raspicat.service to avoid rebuilding the kernel module and ROS 2 workspace on every boot, by switching from a broken insmod invocation + unconditional colcon build to a modprobe-based load with a build fallback.
Changes:
- Replace
insmodof a typo’d/nonexistent.kuopath withmodprobe rtmouse. - Keep
build_install.bashas a fallback only when loading the module fails. - Remove the unconditional
colcon build --symlink-installfrom the boot-time driver-loading path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| source ~/.bashrc | ||
|
|
||
| sudo /sbin/insmod $(rosstack find raspicat_ros)/../RaspberryPiMouse/src/drivers/rtmouse.kuo || sudo /bin/bash $(ros2 pkg prefix --share raspberry_pi_mouse)/utils/build_install.bash; cd $RASPICAT2_WS; colcon build --symlink-install; cd - | ||
| sudo /sbin/modprobe rtmouse || sudo /bin/bash $(ros2 pkg prefix --share raspberry_pi_mouse)/utils/build_install.bash |
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.
問題
raspicat.service(WantedBy=multi-user.target)は起動のたびにdevice_driver_auto_install/scripts/insmod_rtmouse.shを実行しますが、その 1 行目はドライバのロードに決して成功しません。
rosstackは ROS 1 のコマンドで、ROS 2 の環境には入っていません。そのため$(rosstack find raspicat_ros)は空文字に展開され、insmodに渡るパスは/../RaspberryPiMouse/src/drivers/rtmouse.kuoになります。rtmouse.kuoはrtmouse.koの打ち間違いです。したがって
insmodは必ず失敗し、||の側が必ず実行されます。つまり起動のたびにカーネルモジュールが再コンパイルされます。
さらに
colcon build --symlink-installは||ではなく;で繋がっているため、フォールバックの一部ではありません。ドライバがロードできたかどうかに関係なく、
起動のたびにワークスペース全体を再ビルドします。
実機で観測した挙動
Raspberry Pi 4 / Ubuntu 22.04 / カーネル
5.15.0-1098-raspi。このサービスが約 25 分ループし続け、ロードアベレージは 14 を超えていました。
systemctl show raspicat.service -p NRestartsは 387 を返しました。変更内容
modprobeでインストール済みのモジュールをロードし、まだインストールされていない環境のためにビルドスクリプトをフォールバックとして残します。初回セットアップ時の
挙動は変わりません。
無条件の
colcon buildは削除しました。systemd ユニットから呼ばれるドライバロード用スクリプトが、ワークスペースを再ビルドする必要はないためです。
なお
modprobeが再ビルドを回避できるのは、モジュールが実際に/lib/modulesの下に置かれてからです。その半分は CIT-Autonomous-Robot-Lab/RaspberryPiMouse#3 で
対応しています。ただし本 PR は単独でも正しく、安全に適用できます。
動作確認
上記の実機で確認しました。モジュールを
/lib/modules/$(uname -r)/extra/に配置してdepmodを実行した状態であれば、modprobe rtmouseでロードされ、コンパイルは一切走りません。
🤖 Generated with Claude Code
https://claude.ai/code/session_01V3ZzEzNKDxANptPX4QNnHn