Skip to content

insmod_rtmouse.sh: 起動のたびにドライバとワークスペースを再ビルドするのをやめる - #24

Open
NOPLAB wants to merge 1 commit into
ros2from
fix/insmod-rtmouse-no-rebuild-on-boot
Open

insmod_rtmouse.sh: 起動のたびにドライバとワークスペースを再ビルドするのをやめる#24
NOPLAB wants to merge 1 commit into
ros2from
fix/insmod-rtmouse-no-rebuild-on-boot

Conversation

@NOPLAB

@NOPLAB NOPLAB commented Aug 3, 2026

Copy link
Copy Markdown

問題

raspicat.serviceWantedBy=multi-user.target)は起動のたびに
device_driver_auto_install/scripts/insmod_rtmouse.sh を実行しますが、その 1 行目は
ドライバのロードに決して成功しません。

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 -
  • rosstackROS 1 のコマンドで、ROS 2 の環境には入っていません。そのため
    $(rosstack find raspicat_ros) は空文字に展開され、insmod に渡るパスは
    /../RaspberryPiMouse/src/drivers/rtmouse.kuo になります。
  • rtmouse.kuortmouse.ko の打ち間違いです。

したがって insmod は必ず失敗し、|| の側が必ず実行されます。つまり
起動のたびにカーネルモジュールが再コンパイルされます

さらに colcon build --symlink-install|| ではなく ; で繋がっているため、
フォールバックの一部ではありません。ドライバがロードできたかどうかに関係なく、
起動のたびにワークスペース全体を再ビルドします

実機で観測した挙動

Raspberry Pi 4 / Ubuntu 22.04 / カーネル 5.15.0-1098-raspi
このサービスが約 25 分ループし続け、ロードアベレージは 14 を超えていました。

Aug 03 17:52:31 ubuntu bash[150843]: build_install_header_from_apt_raspi4.bash
Aug 03 17:53:32 ubuntu bash[151032]: make -C /usr/src/linux-headers-5.15.0-1098-raspi ... modules
Aug 03 17:54:23 ubuntu bash[151424]:   CC [M]  .../src/drivers/rtmouse.o

systemctl show raspicat.service -p NRestarts387 を返しました。

変更内容

sudo /sbin/modprobe rtmouse || sudo /bin/bash $(ros2 pkg prefix --share raspberry_pi_mouse)/utils/build_install.bash

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

`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
Copilot AI review requested due to automatic review settings August 3, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 insmod of a typo’d/nonexistent .kuo path with modprobe rtmouse.
  • Keep build_install.bash as a fallback only when loading the module fails.
  • Remove the unconditional colcon build --symlink-install from 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
@NOPLAB NOPLAB changed the title insmod_rtmouse.sh: stop rebuilding the driver and the workspace on every boot insmod_rtmouse.sh: 起動のたびにドライバとワークスペースを再ビルドするのをやめる Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants