Skip to content

Fix smalrubot S1 motor labels: Change from A4/A5 to M1/M2 to distinguish from sensors #405

@takaokouji

Description

@takaokouji

問題の概要 (Problem Overview)

現在、smalrubot S1 拡張機能において、センサーとモーター/LEDが同じラベルシステム (POSITIONS_MENU) を使用しているため、センサーの位置が分かりにくくなっています。保守性を高めるため、すべてのセンサーラベルを統一した名前空間に移行します。

Currently, the smalrubot S1 extension uses the same label system (POSITIONS_MENU) for both sensors and motors/LEDs, making sensor positions unclear. To improve maintainability, we will migrate all sensor labels to a unified namespace.

現在の実装 (Current Implementation)

場所 (Location): gui/scratch-vm/src/extensions/scratch3_smalrubot_s1/index.js

  • 共通ラベル (Shared Labels): Line 869-888 (POSITIONS_MENU) - モーター、LED、センサーで共用
  • センサー専用ラベル (Sensor-specific Labels): Line 893+ (SENSOR_POSITIONS_MENU) - 既に実装済み
  • モーター操作 (Motor Operations): Line 212+ (getMotorSpeed, setMotorSpeed など)
  • センサー操作 (Sensor Operations): Line 164+ (getSensorValue)

現在、ほとんどの操作が POSITIONS_MENU を使用していますが、センサー操作は SENSOR_POSITIONS_MENU を使用するように一部修正されています。

Currently, most operations use POSITIONS_MENU, but sensor operations have been partially updated to use SENSOR_POSITIONS_MENU.

提案する解決策 (Proposed Solution)

センサーとモーター/LEDのラベルを明確に分離し、すべてのセンサーラベルを統一した名前空間に移行します:

Clearly separate sensor and motor/LED labels, and migrate all sensor labels to a unified namespace:

センサーラベル (Sensor Labels)

  • SENSOR_POSITIONS_MENU を使用し、すべてのセンサーに統一した名前空間を適用
  • すべてのセンサー項目:
    • 左センサー: 左(A4)smalrubotS1.sensorPositionsMenu.left
    • 右センサー: 右(A5)smalrubotS1.sensorPositionsMenu.right
    • タッチセンサー: タッチ(A2)smalrubotS1.sensorPositionsMenu.touch
    • 光センサー: 光(A6)smalrubotS1.sensorPositionsMenu.light
    • 音センサー: 音(A7)smalrubotS1.sensorPositionsMenu.sound

モーター/LEDラベル (Motor/LED Labels)

  • POSITIONS_MENU を使用し、シンプルな位置表示(センサー項目を削除)
  • 左モーター/LED: smalrubotS1.positionsMenu.left
  • 右モーター/LED: smalrubotS1.positionsMenu.right

必要な変更 (Required Changes)

1. scratch-vm の変更 (scratch-vm Changes)

  • 完了: SENSOR_POSITIONS_MENU の実装 (line 893+)
  • 完了: getSensorValue ブロックでのセンサー専用ラベル使用 (line 174)

残りの作業:

  • SENSOR_POSITIONS_MENU のすべてのセンサーラベルを smalrubotS1.sensorPositionsMenu.* 名前空間に統一:
    • smalrubotS1.sensorPositionsMenu.left (A4ポート番号表示)
    • smalrubotS1.sensorPositionsMenu.right (A5ポート番号表示)
    • smalrubotS1.sensorPositionsMenu.touch (A2ポート番号表示)
    • smalrubotS1.sensorPositionsMenu.light (A6ポート番号表示)
    • smalrubotS1.sensorPositionsMenu.sound (A7ポート番号表示)
  • POSITIONS_MENU からセンサー関連項目 (touch, light, sound) を削除し、left/right のみに

2. smalruby3-gui の変更 (smalruby3-gui Changes)

  • 日本語ローカライゼーションファイル (src/locales/ja.js) に新しいセンサーラベルの翻訳を追加:
    • 'smalrubotS1.sensorPositionsMenu.left': '左(A4)'
    • 'smalrubotS1.sensorPositionsMenu.right': '右(A5)'
    • 'smalrubotS1.sensorPositionsMenu.touch': 'タッチ(A2)'
    • 'smalrubotS1.sensorPositionsMenu.light': '光(A6)'
    • 'smalrubotS1.sensorPositionsMenu.sound': '音(A7)'

技術的詳細 (Technical Details)

Target code structure:

// センサー専用メニュー (すべて smalrubotS1.sensorPositionsMenu 名前空間)
get SENSOR_POSITIONS_MENU () {
    return [
        {
            text: formatMessage({
                id: 'smalrubotS1.sensorPositionsMenu.left',
                default: 'left(A4)',
                description: 'label for "left" sensor in position picker for Smalrubot S1 extension'
            }),
            value: 'left'
        },
        {
            text: formatMessage({
                id: 'smalrubotS1.sensorPositionsMenu.right',
                default: 'right(A5)',
                description: 'label for "right" sensor in position picker for Smalrubot S1 extension'
            }),
            value: 'right'
        },
        {
            text: formatMessage({
                id: 'smalrubotS1.sensorPositionsMenu.touch',
                default: 'touch(A2)',
                description: 'label for "touch" sensor in position picker for Smalrubot S1 extension'
            }),
            value: 'touch'
        },
        {
            text: formatMessage({
                id: 'smalrubotS1.sensorPositionsMenu.light',
                default: 'light(A6)',
                description: 'label for "light" sensor in position picker for Smalrubot S1 extension'
            }),
            value: 'light'
        },
        {
            text: formatMessage({
                id: 'smalrubotS1.sensorPositionsMenu.sound',
                default: 'sound(A7)',
                description: 'label for "sound" sensor in position picker for Smalrubot S1 extension'
            }),
            value: 'sound'
        }
    ];
}

// モーター/LED専用メニュー (left/right のみ)
get POSITIONS_MENU () {
    return [
        {
            text: formatMessage({
                id: 'smalrubotS1.positionsMenu.left',
                default: 'left',
                description: 'label for "left" element in position picker for Smalrubot S1 extension'
            }),
            value: 'left'
        },
        {
            text: formatMessage({
                id: 'smalrubotS1.positionsMenu.right',
                default: 'right',
                description: 'label for "right" element in position picker for Smalrubot S1 extension'
            }),
            value: 'right'
        }
    ];
}

互換性とメンテナンス性 (Compatibility and Maintainability)

この変更により:

  • 互換性維持: モーターとLEDの操作は引き続き同じラベルシステムを共有
  • 明確な分離: センサーは独自の詳細なラベルシステムを使用
  • 統一した名前空間: すべてのセンサーラベルが smalrubotS1.sensorPositionsMenu.* に統一
  • 保守性向上: 将来のセンサー追加時も統一したパターンで対応可能
  • ハードウェア理解: ユーザーがポート番号を理解しやすくなる

実装ブランチ (Implementation Branch)

ブランチ名: fix/smalrubot-s1-sensor-labels

  • smalruby/scratch-vm
  • smalruby/smalruby3-gui

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions