跳轉到

02 第一次建置與測試

目標:取得各 domain 的程式碼,完成建置,並執行單元測試與整合測試。

時間:約 20 分鐘(首次執行需建置 image)

背景

DIT-X 由「shell repo」與「domain repo」組成:

  • shell repo:即 DIT-X,包含 ditx 工具、CI、Docker image,以及各小組共用的介面定義(base/)
  • domain repo:每個小組各有一個 repo(Eurobot-Main、Eurobot-Navigation、Eurobot-Localization、Eurobot-Vision),列於 ditx.repos,ditx sync 會將它們放到 domains/<組名>/

建置在 dev container 中進行,每個 domain 各自擁有一層 install(build/<distro>-<arch>/<domain>/install)。因此,某個小組的程式出錯時不會影響其他小組,重新建置時也只會編譯有變更的部分。

前置條件

步驟

1. 取得程式碼

ditx sync

sync

sync 會先將 shell repo 快轉(fast-forward)至最新版本,再複製(clone)或快轉每個 domain repo,並安裝 Git hook(用於檢查提交訊息格式)。含有未提交變更的 repo 不會被更動。

ditx.repos 中的網址是 https(CI 與機器人以唯讀 token 讀取);若 shell repo 是用 SSH clone 的,sync 也會用 SSH clone domain repo,因此同一把 SSH 金鑰就能 push 每個 repo,不需要另外設定。

只需要自己小組的程式碼

可以只取特定 domain,例如 ditx sync vision。之後 build、test、lint、deploy 預設只處理已同步的 domain,其他小組的程式碼不必下載。

唯一的例外是整合測試(ditx test --integration):它會同時啟動所有 domain,因此需要先執行完整的 ditx sync。

查看各 repo 目前的狀態,以及各 domain 包含哪些套件(package):

ditx status
ditx list

status

list

2. 準備 image

CI 會把 develop 的 image 發佈到 GHCR(ghcr.io/dit-robotics/eurobot-*:develop,amd64 與 arm64),所以不需要自己建置:第一次執行 ditx build 時會自動 pull dev image(約 1 GB),ditx up -r sim 也會自動 pull runtime image。

只有在你的分支修改了 Dockerfile 或新增相依套件(package.xml 的 <depend>)時,才需要在本機建置。ditx build 會先檢查 dev image 是否缺少你需要的相依套件,缺少時會直接提示這一步:

ditx image                      # 建 base、dev、cross 與 4 個 domain 的 runtime image(tag: local),約 5–10 分鐘
DIT_DEV_TAG=local ditx build    # 用自己建的 dev image 建置

要一直使用自己建置的 image,在 .env 設定 DIT_DEV_TAG=local,並把 config/robots.ini 中 sim 的 tag 改成 local。

▸ images  humble · linux/amd64 → ghcr.io/dit-robotics/eurobot-*:local
✓ images         base, dev, navigation, vision, localization, main  (loaded, 70 steps)  91s

image 的用途

  • dev:ditx build、test、lint 在裡面執行,VS Code 的 Dev Container 也用它。
  • cross:ditx build --arch arm64 用來交叉編譯。
  • runtime(每個 domain 一個):sim 機器人執行的 image。

3. 格式檢查、建置與測試

ditx lint
ditx build
ditx test --integration

lint

build

test-integration

每個步驟顯示為一行。執行期間,左側會顯示進度指示符號,右側顯示目前的動作;完成後會變為 ✓ 或 ✗。

  • -j auto(預設):依據你的 RAM 與 CPU,決定同時建置的套件數量及每個 make 的 job 數,並將容器記憶體上限設為 80%,避免大型建置因記憶體不足(OOM)導致桌面工作階段終止
  • --integration:同時啟動 4 個 domain,確認「啟動交握(handshake)」完成,且實際執行中的 topic 與 contract.yaml 一致(名稱、型別相符,且每個 topic 都有 publisher)

4. 查看詳細輸出

ditx 會將 colcon、Docker 等工具的完整輸出儲存在 build/logs/,畫面上只顯示一行摘要。執行失敗時,會列出相關錯誤與日誌檔路徑。若要查看完整輸出:

ditx build -v          # verbose:完整輸出
ditx -n build          # dry-run:只印出會執行的指令,不真的做

摘要

  • 使用 ditx sync 取得程式碼,使用 ditx status / ditx list 查看狀態
  • ditx build 為每個 domain 建立獨立的 install 層,並進行增量建置
  • ditx test --integration 是同時啟動所有 domain 的系統測試,CI 也會執行相同的測試

下一步

03 認識 TUI:不需記憶指令,只要輸入 ditx 即可開始操作。