From f579cea7a1f70db1ee7975a798145d2e8d451d46 Mon Sep 17 00:00:00 2001 From: Agus Darmawan Date: Wed, 28 Oct 2026 14:00:21 +0700 Subject: [PATCH 01/34] build: pin every dharma repository to its main of 2026-10-28, hub tooling --- .clang-format | 19 +++++++++++ .editorconfig | 21 ++++++++++++ .flake8 | 6 ---- .github/pull_request_template.md | 14 ++++---- .gitignore | 51 +++++++++------------------- .pre-commit-config.yaml | 34 ++++++++++++------- .prettierrc.yaml | 7 ++++ molly.repos | 33 ++++++++++-------- ruff.toml | 58 ++++++++++++++++++++++++++++++++ 9 files changed, 169 insertions(+), 74 deletions(-) create mode 100644 .clang-format create mode 100644 .editorconfig delete mode 100644 .flake8 create mode 100644 .prettierrc.yaml create mode 100644 ruff.toml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c0ac998 --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +--- +# ament_clang_format style (ROS 2) +Language: Cpp +BasedOnStyle: Google +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +BraceWrapping: + AfterClass: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true +BreakBeforeBraces: Custom +ColumnLimit: 100 +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 2 +DerivePointerAlignment: false +IncludeBlocks: Preserve +PointerAlignment: Middle +ReflowComments: false diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1147c07 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{py,cpp,hpp,h,c}] +indent_size = 4 + +[*.{cpp,hpp,h,c}] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 301fb71..0000000 --- a/.flake8 +++ /dev/null @@ -1,6 +0,0 @@ -# Same rules as ament_flake8 (colcon test), for editors and pre-commit. -[flake8] -max-line-length = 99 -import-order-style = google -extend-ignore = B902,C816,D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404,I202,W503 -exclude = .git,build,install,log,src/xtras diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a39ccc7..6feca54 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,12 +4,14 @@ ## How it was tested -- [ ] `colcon test` passes (CI green, simulator end-to-end test included) -- [ ] Tried in the simulator (`ros2 launch molly sim.launch.py`), on the robot or in the dev - container: +- [ ] CI green (lint, Humble build and tests of the whole stack from `molly.repos`) +- [ ] Tried in the simulator (`ros2 launch molly_bringup sim.launch.py`), in the dev container or + on the robot: ## Checklist -- [ ] Conventional commit titles (`fix(navigation): ...`, `feat(bridge): ...`) -- [ ] New parameters documented in the package README and its `config/*.yaml` -- [ ] Safety-relevant change (motion, e-stop, limits)? Described above and tested on the robot +- [ ] Conventional commit titles (`fix(guide): ...`, `feat(bridge): ...`) +- [ ] Parameters and launch arguments documented (package README, `config/*.yaml`) +- [ ] CHANGELOG entry for user-visible changes +- [ ] Safety-relevant change (motion, e-stop, limits, robot profile)? Described above and tested + on the robot diff --git a/.gitignore b/.gitignore index 6058e89..78e5a57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,25 @@ -# ---- env / secrets ---- -.env -*.pem -*.key +/build/ +/install/ +/log/ +__pycache__/ +*.py[cod] +*.egg-info/ +.pytest_cache/ +.ruff_cache/ -# ---- ROS2 / colcon build artifacts ---- -build/ -install/ -log/ -**/COLCON_IGNORE +# the Dharma stack (vcs import src < molly.repos, scripts/setup.sh install dharma) +/src/dharma/ -# ---- rosbag recordings ---- +# rosbag recordings *.bag *.db3 -*_bag/ rosbag2_*/ -# ---- python ---- -__pycache__/ -*.py[cod] -*.egg-info/ -.venv/ -venv/ - -# ---- editors ---- -.idea/ +# local settings and secrets +.env +*.pem +*.key *.swp -*.swo -# NOTE: .vscode/ is intentionally tracked (shared workspace settings) — do not ignore it - -# ---- OS junk ---- .DS_Store -Thumbs.db -desktop.ini - -# ---- misc ---- -*.log -.cache/ -__MACOSX/ - +.idea/ .vscode/settings.json - -# dharma packages (vcs import src < molly.repos) -src/dharma/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index acd9985..657b5da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,28 +1,36 @@ -# pip install pre-commit && pre-commit install (runs on every commit, CI runs the same checks) -exclude: ^src/xtras/ +# pip install pre-commit && pre-commit install (CI runs the same hooks) +# submodules (src/xtras) are not ours; the draw.io diagram is saved as draw.io writes it +exclude: ^(src/xtras/|docs/diagrams/) repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer + - id: mixed-line-ending + args: [--fix=lf] - id: check-yaml args: [--allow-multiple-documents] - id: check-xml - id: check-merge-conflict - id: check-added-large-files args: [--maxkb=1024] - exclude: ^docs/.*\.pdf$ # the guides, screenshots included - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.16.9 hooks: - - id: flake8 - additional_dependencies: - - flake8-builtins - - flake8-comprehensions - - flake8-docstrings - - flake8-import-order - - flake8-quotes + - id: ruff-check + args: [--fix] + - id: ruff-format + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.8 + hooks: + - id: clang-format + types_or: [c++, c] + - repo: https://github.com/rbubley/mirrors-prettier + rev: v3.3.3 + hooks: + - id: prettier + types_or: [yaml, markdown, json] - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.10.0.1 hooks: diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..5513325 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,7 @@ +printWidth: 99 +proseWrap: preserve +singleQuote: false +overrides: + - files: ["*.yaml", "*.yml"] + options: + bracketSpacing: false diff --git a/molly.repos b/molly.repos index c5f22ab..679de64 100644 --- a/molly.repos +++ b/molly.repos @@ -1,39 +1,44 @@ -# Dharma packages Molly runs on: vcs import src < molly.repos -# Pinned to released commits (the comment names the release). +# The Dharma stack Molly runs on: vcs import src < molly.repos (scripts/setup.sh install dharma) +# Every repository pinned to a commit of its main branch (the comment names the day). +# dharma_navigation holds dharma_navigation and dharma_control. repositories: + dharma/dharma_utils: + type: git + url: git@github.com:DarmawanRobotics/dharma_utils.git + version: a0a64691e3a47b35923a7cc03bc81c6db087498d # main 2026-10-28 dharma/dharma_interfaces: type: git url: git@github.com:DarmawanRobotics/dharma_interfaces.git - version: d45a00e20b6b11079261c9c403cfecd8985ab07a # v0.1.1 + version: 2ddbb00b0ba35f6486515bde22cfb59ffe86acee # main 2026-10-28 dharma/dharma_odometry: type: git url: git@github.com:DarmawanRobotics/dharma_odometry.git - version: 28ae0522d6bb6aa6409dedbedb3a91f3e83b9a2b # v0.1.1 + version: 3789552b70f7f76b2625662c76f4a083a2df5d5b # main 2026-10-28 dharma/dharma_localization: type: git url: git@github.com:DarmawanRobotics/dharma_localization.git - version: fc327c3f511c1d34e4d79c53bc6ccf9ca58d9372 # v0.1.1 - dharma/dharma_navigation: - type: git - url: git@github.com:DarmawanRobotics/dharma_navigation.git - version: 9da81dfc845565dc504f8547e18848339bdbe4c9 # v0.1.1 + version: f9e1a9564cc7b3e3cda3235af10e80bcd55d54df # main 2026-10-28 dharma/dharma_perception: type: git url: git@github.com:DarmawanRobotics/dharma_perception.git - version: 3e597d659ff64dea89aca62fe4d2900c820365c7 # v0.1.1 + version: 3e088d208aae317dbe56c7103a01569a0f8e1031 # main 2026-10-28 dharma/dharma_mapping: type: git url: git@github.com:DarmawanRobotics/dharma_mapping.git - version: 51df355e0d0a1d62f02f2b00d48bcc6524895651 # v0.1.1 + version: 8e322baf88739c8e5adf4aae79385e791aa783c4 # main 2026-10-28 + dharma/dharma_navigation: + type: git + url: git@github.com:DarmawanRobotics/dharma_navigation.git + version: 84ce22df7f61b6a12f19c13a14045610ab01b2f3 # main 2026-10-28 dharma/dharma_health: type: git url: git@github.com:DarmawanRobotics/dharma_health.git - version: ed6035277795027c391846ed7ebaef56ed5fb9c6 # v0.1.0 + version: dc48db6257d1dd1bf635c6338f06d4abf97558a9 # main 2026-10-28 dharma/dharma_rviz: type: git url: git@github.com:DarmawanRobotics/dharma_rviz.git - version: 3cf73fa2b6485837989d6f34392b9776faab1e6a # v0.1.0 + version: 6080357301a6b17c4aeef5b60705c136bf357f05 # main 2026-10-28 dharma/dharma_sim: type: git url: git@github.com:DarmawanRobotics/dharma_sim.git - version: f6b25248c1b5dd13701fbd43599352e4cf8d35b8 # v0.1.0 + version: cbfb592b0a5a42888005d1aa722d66010fa5e2f6 # main 2026-10-28 diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..830a155 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,58 @@ +line-length = 99 +target-version = "py38" # Foxy (Python 3.8); annotations stay modern via __future__ +extend-exclude = ["./build", "./install", "./log"] # anchored: a package may have a log/ module + +[format] +quote-style = "single" +docstring-code-format = true + +[lint] +select = [ + "B", # bugbear + "C4", # comprehensions + "C90", # complexity + "D", # docstrings + "E", # pycodestyle + "FA", # from __future__ import annotations (PEP 604 / 585 hints on 3.8) + "F", # pyflakes + "I", # imports + "N", # naming + "NPY", # numpy + "PIE", + "PL", # pylint + "PT", # pytest + "RUF", + "SIM", + "UP", # pyupgrade + "W", +] +ignore = [ + "D100", # module docstring + "D104", # package docstring + "D105", # magic method docstring + "D107", # __init__ docstring + "D203", + "D213", + "PLC0415", # imports inside functions (optional dependencies) + "PLR0913", # many arguments + "PLR0917", # many positional arguments + "PLR2004", # magic values + "RUF009", # nested() / param() return dataclass fields + "RUF012", +] + +[lint.mccabe] +max-complexity = 12 + +[lint.pydocstyle] +convention = "pep257" + +[lint.isort] +force-sort-within-sections = true +known-first-party = ["dharma_*"] +required-imports = ["from __future__ import annotations"] + +[lint.per-file-ignores] +"**/test/**" = ["D", "N802", "PLR0915", "PLR2004", "PT011", "PT012", "PT018"] +"**/launch/*.py" = ["D103"] +"**/setup.py" = ["D"] From 6e6428bdccad94fe8a271f60193be1710c0d8a69 Mon Sep 17 00:00:00 2001 From: Agus Darmawan Date: Wed, 28 Oct 2026 14:03:56 +0700 Subject: [PATCH 02/34] feat(interfaces)!: POIs, tours and visitors owned by molly_interfaces, typed status enums --- src/molly_interfaces/CMakeLists.txt | 18 +++++++++++++- src/molly_interfaces/README.md | 28 +++++++++++++--------- src/molly_interfaces/msg/Conversation.msg | 8 +++++++ src/molly_interfaces/msg/GreeterStatus.msg | 16 +++++++++++++ src/molly_interfaces/msg/Poi.msg | 12 ++++++++++ src/molly_interfaces/msg/PoiArray.msg | 5 ++++ src/molly_interfaces/msg/SpeechStatus.msg | 10 ++++++-- src/molly_interfaces/msg/Tour.msg | 7 ++++++ src/molly_interfaces/msg/TourArray.msg | 5 ++++ src/molly_interfaces/msg/TourCommand.msg | 12 +++++----- src/molly_interfaces/msg/TourState.msg | 27 +++++++++++++-------- src/molly_interfaces/msg/Visitors.msg | 11 +++++++++ src/molly_interfaces/package.xml | 6 +++-- src/molly_interfaces/srv/DeleteById.srv | 5 ++++ src/molly_interfaces/srv/Gesture.srv | 2 +- src/molly_interfaces/srv/GoToPoi.srv | 5 ++++ src/molly_interfaces/srv/SavePoi.srv | 8 +++++++ src/molly_interfaces/srv/SaveTour.srv | 6 +++++ src/molly_interfaces/srv/TourControl.srv | 2 +- 19 files changed, 159 insertions(+), 34 deletions(-) create mode 100644 src/molly_interfaces/msg/Conversation.msg create mode 100644 src/molly_interfaces/msg/GreeterStatus.msg create mode 100644 src/molly_interfaces/msg/Poi.msg create mode 100644 src/molly_interfaces/msg/PoiArray.msg create mode 100644 src/molly_interfaces/msg/Tour.msg create mode 100644 src/molly_interfaces/msg/TourArray.msg create mode 100644 src/molly_interfaces/msg/Visitors.msg create mode 100644 src/molly_interfaces/srv/DeleteById.srv create mode 100644 src/molly_interfaces/srv/GoToPoi.srv create mode 100644 src/molly_interfaces/srv/SavePoi.srv create mode 100644 src/molly_interfaces/srv/SaveTour.srv diff --git a/src/molly_interfaces/CMakeLists.txt b/src/molly_interfaces/CMakeLists.txt index 83f5adb..adb62b9 100644 --- a/src/molly_interfaces/CMakeLists.txt +++ b/src/molly_interfaces/CMakeLists.txt @@ -4,17 +4,33 @@ project(molly_interfaces) find_package(ament_cmake REQUIRED) find_package(rosidl_default_generators REQUIRED) find_package(std_msgs REQUIRED) +find_package(geometry_msgs REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} + # sites: points of interest and tours (stored with the site) + "msg/Poi.msg" + "msg/PoiArray.msg" + "msg/Tour.msg" + "msg/TourArray.msg" + # the guide "msg/TourCommand.msg" "msg/TourState.msg" + # visitors and interaction + "msg/Visitors.msg" "msg/SpeechStatus.msg" + "msg/GreeterStatus.msg" + "msg/Conversation.msg" + # services + "srv/SavePoi.srv" + "srv/SaveTour.srv" + "srv/DeleteById.srv" + "srv/GoToPoi.srv" "srv/TourControl.srv" "srv/GetTourState.srv" "srv/Say.srv" "srv/Ask.srv" "srv/Gesture.srv" - DEPENDENCIES std_msgs + DEPENDENCIES std_msgs geometry_msgs ) ament_export_dependencies(rosidl_default_runtime) diff --git a/src/molly_interfaces/README.md b/src/molly_interfaces/README.md index f37f9a7..ed49774 100644 --- a/src/molly_interfaces/README.md +++ b/src/molly_interfaces/README.md @@ -1,15 +1,21 @@ # molly_interfaces -The tour guide's own messages and services. Navigation, sites, POIs, tours, mapping, the path -finder and visitors come from -[dharma_interfaces](https://github.com/DarmawanRobotics/dharma_interfaces). Definitions: -[msg/](msg) and [srv/](srv). +Molly's own messages and services. Everything the Dharma stack offers (status of every +subsystem, sites, mapping, the path finder, navigation, the control mux) is in +[dharma_interfaces](https://github.com/DarmawanRobotics/dharma_interfaces); Molly adds what a tour +guide needs on top. Definitions: [msg/](msg) and [srv/](srv). -| Kind | Name | Used by | -|---|---|---| -| msg | `TourCommand`, `TourState` | `/tour/cmd`, `/tour/state` (latched) | -| msg | `SpeechStatus` | `interaction/speech_status` (latched) | -| srv | `TourControl`, `GetTourState` | `/tour/control`, `/tour/get_state` | -| srv | `Say`, `Ask`, `Gesture` | `interaction/say`, `interaction/ask`, `interaction/gesture` | +| Kind | Name | Used by | +| ---- | ------------------------------------------------- | -------------------------------------------------------------------------------------- | +| msg | `Poi`, `PoiArray`, `Tour`, `TourArray` | `site/pois`, `site/tours` (latched, `site_content_node`) | +| msg | `TourCommand`, `TourState` | `tour/cmd`, `tour/state` (latched, `guide_node`) | +| msg | `Visitors` | `perception/visitors` (`visitor_tracker_node`) | +| msg | `SpeechStatus`, `GreeterStatus`, `Conversation` | `interaction/speech_status`, `interaction/greeter` (latched), `interaction/conversation` | +| srv | `SavePoi`, `SaveTour`, `DeleteById` | `site/save_poi`, `site/save_tour`, `site/delete_poi`, `site/delete_tour` | +| srv | `GoToPoi` | `guide/go_to_poi` | +| srv | `TourControl`, `GetTourState` | `tour/control`, `tour/get_state` | +| srv | `Say`, `Ask`, `Gesture` | `interaction/say`, `interaction/ask`, `interaction/gesture` | -The full list of topics and services is in [docs/interfaces.md](../../docs/interfaces.md). +Status messages carry enum constants (`TourState.RUNNING`, `SpeechStatus.DONE`, +`GreeterStatus.WATCHING`), never strings or JSON. Every topic and service of the robot is listed +in [docs/interfaces.md](../../docs/interfaces.md). diff --git a/src/molly_interfaces/msg/Conversation.msg b/src/molly_interfaces/msg/Conversation.msg new file mode 100644 index 0000000..6733a8f --- /dev/null +++ b/src/molly_interfaces/msg/Conversation.msg @@ -0,0 +1,8 @@ +# conversation_node -> interaction/conversation: one question and its answer. + +std_msgs/Header header +string question +string answer +uint32 latency_ms +bool success +string message diff --git a/src/molly_interfaces/msg/GreeterStatus.msg b/src/molly_interfaces/msg/GreeterStatus.msg new file mode 100644 index 0000000..dd2d8e2 --- /dev/null +++ b/src/molly_interfaces/msg/GreeterStatus.msg @@ -0,0 +1,16 @@ +# interaction_node -> interaction/greeter (latched), on a change and every few seconds. + +uint8 OFF = 0 # switched off (interaction/set_greeter) +uint8 WAITING = 1 # nobody in front +uint8 WATCHING = 2 # somebody in front, not yet for dwell_sec +uint8 GREETING = 3 # a greeting is being said +uint8 GREETED = 4 # the visitor in front was greeted; the front must empty first +uint8 COOLDOWN = 5 # the last greeting is less than cooldown_sec ago +uint8 PAUSED = 6 # a tour runs, the robot walks or talks +uint8 UNAVAILABLE = 7 # no greeter on this robot (greeter_available false) + +std_msgs/Header header +bool enabled +uint8 state +float32 last_greet_age # s since the last greeting, -1 before the first one +string[] gestures # gesture names interaction/gesture runs diff --git a/src/molly_interfaces/msg/Poi.msg b/src/molly_interfaces/msg/Poi.msg new file mode 100644 index 0000000..9d4f53f --- /dev/null +++ b/src/molly_interfaces/msg/Poi.msg @@ -0,0 +1,12 @@ +# A point of interest of a site: a place the guide walks to and talks about (map frame). + +string id # stable id: a-z, 0-9, _ and -, unique per site +string name # shown to operators and visitors +string description # what it is; also given to the conversation model +float64 x # m, map frame +float64 y # m, map frame +float64 yaw # rad, heading the robot takes on arrival (towards the exhibit) +string narration # spoken on arrival; empty: nothing is said +string language # narration language ("id", "en"); empty: the speech default +string gesture # gesture on arrival; empty: none (interaction/gesture) +float32 dwell_sec # s, wait after the narration before moving on diff --git a/src/molly_interfaces/msg/PoiArray.msg b/src/molly_interfaces/msg/PoiArray.msg new file mode 100644 index 0000000..f6417df --- /dev/null +++ b/src/molly_interfaces/msg/PoiArray.msg @@ -0,0 +1,5 @@ +# site_content_node -> site/pois (latched): every POI of the active site. + +std_msgs/Header header # frame_id: map +string site # empty: no site loaded +Poi[] pois diff --git a/src/molly_interfaces/msg/SpeechStatus.msg b/src/molly_interfaces/msg/SpeechStatus.msg index f916d21..b55e641 100644 --- a/src/molly_interfaces/msg/SpeechStatus.msg +++ b/src/molly_interfaces/msg/SpeechStatus.msg @@ -1,8 +1,14 @@ -# speech_node -> latched interaction/speech_status, on every change. +# speech_node -> interaction/speech_status (latched), on every change. + +uint8 IDLE = 0 +uint8 SPEAKING = 1 +uint8 DONE = 2 +uint8 FAILED = 3 +uint8 CANCELLED = 4 std_msgs/Header header uint32 id # utterance this status is about (from Say), 0: none yet -string state # idle, speaking, done, failed, cancelled +uint8 state string text string language uint32 queued # utterances waiting after this one diff --git a/src/molly_interfaces/msg/Tour.msg b/src/molly_interfaces/msg/Tour.msg new file mode 100644 index 0000000..d2bd713 --- /dev/null +++ b/src/molly_interfaces/msg/Tour.msg @@ -0,0 +1,7 @@ +# An ordered list of POIs the guide walks through. + +string id # stable id: a-z, 0-9, _ and -, unique per site +string name +string description +string[] poi_ids # stops in visiting order +string return_poi_id # walk here after the last stop; empty: stay at the last stop diff --git a/src/molly_interfaces/msg/TourArray.msg b/src/molly_interfaces/msg/TourArray.msg new file mode 100644 index 0000000..6723cb6 --- /dev/null +++ b/src/molly_interfaces/msg/TourArray.msg @@ -0,0 +1,5 @@ +# site_content_node -> site/tours (latched): every tour of the active site. + +std_msgs/Header header +string site +Tour[] tours diff --git a/src/molly_interfaces/msg/TourCommand.msg b/src/molly_interfaces/msg/TourCommand.msg index e0afe6a..6fe66b0 100644 --- a/src/molly_interfaces/msg/TourCommand.msg +++ b/src/molly_interfaces/msg/TourCommand.msg @@ -1,10 +1,10 @@ -# Dashboard / handheld -> guide_node, on /tour/cmd or through /tour/control. +# Dashboard / handheld -> guide_node, on tour/cmd or through tour/control. -uint8 KIND_START=0 -uint8 KIND_PAUSE=1 -uint8 KIND_RESUME=2 -uint8 KIND_STOP=3 -uint8 KIND_SKIP=4 +uint8 START = 0 +uint8 PAUSE = 1 +uint8 RESUME = 2 +uint8 STOP = 3 +uint8 SKIP = 4 uint8 kind string tour_id # START: a saved tour of the active site, or diff --git a/src/molly_interfaces/msg/TourState.msg b/src/molly_interfaces/msg/TourState.msg index 39ef57c..5de2547 100644 --- a/src/molly_interfaces/msg/TourState.msg +++ b/src/molly_interfaces/msg/TourState.msg @@ -1,21 +1,28 @@ -# guide_node -> everyone, latched on /tour/state; republished on every change and every second. +# guide_node -> tour/state (latched), on every change and every publish_period_sec. -uint8 STATE_IDLE=0 -uint8 STATE_STARTING=1 -uint8 STATE_RUNNING=2 -uint8 STATE_PAUSED=3 -uint8 STATE_STOPPING=4 -uint8 STATE_ERROR=5 +uint8 IDLE = 0 +uint8 STARTING = 1 +uint8 RUNNING = 2 +uint8 PAUSED = 3 +uint8 STOPPING = 4 +uint8 ERROR = 5 + +uint8 ACTIVITY_NONE = 0 +uint8 ACTIVITY_NAVIGATING = 1 +uint8 ACTIVITY_WAITING_VISITORS = 2 +uint8 ACTIVITY_PERFORMING_MOTION = 3 +uint8 ACTIVITY_NARRATING = 4 +uint8 ACTIVITY_DWELLING = 5 +uint8 ACTIVITY_RETURNING = 6 std_msgs/Header header uint8 state +uint8 activity string tour_id # empty for an ad-hoc list of POIs string tour_name int32 current_poi_index # 0-based, -1 when idle int32 total_pois string current_poi_id string current_poi_name -# "", navigating, waiting_visitors, performing_motion, narrating, dwelling, returning -string activity string message # human-readable detail of the activity -string error_reason # set in STATE_ERROR +string error_reason # set in ERROR diff --git a/src/molly_interfaces/msg/Visitors.msg b/src/molly_interfaces/msg/Visitors.msg new file mode 100644 index 0000000..d68af72 --- /dev/null +++ b/src/molly_interfaces/msg/Visitors.msg @@ -0,0 +1,11 @@ +# visitor_tracker_node -> perception/visitors: people around the robot, base_link frame. + +std_msgs/Header header +geometry_msgs/Point[] positions # on the floor in base_link (z = 0) +float32[] confidences # 0-1, one per position +uint32 count +uint32 front # people in the front sector +uint32 behind # people in the rear sector (following the robot) +float32 nearest # m, -1 when nobody +float32 nearest_front # m, -1 when nobody in front +float32 nearest_behind # m, -1 when nobody behind diff --git a/src/molly_interfaces/package.xml b/src/molly_interfaces/package.xml index 5624dc2..c2cc841 100644 --- a/src/molly_interfaces/package.xml +++ b/src/molly_interfaces/package.xml @@ -2,14 +2,16 @@ molly_interfaces - 1.0.0 - The tour guide's own messages and services: tours and speech. Navigation, sites, mapping and the path finder are in dharma_interfaces. + 2.0.0 + Molly's own messages and services: points of interest and tours of a site, the guide, visitors, speech, the greeter and the conversation. The stack's types are in dharma_interfaces. Agus Darmawan Apache-2.0 + https://github.com/DarmawanRobotics/Molly ament_cmake rosidl_default_generators std_msgs + geometry_msgs rosidl_default_runtime rosidl_interface_packages diff --git a/src/molly_interfaces/srv/DeleteById.srv b/src/molly_interfaces/srv/DeleteById.srv new file mode 100644 index 0000000..23b9f30 --- /dev/null +++ b/src/molly_interfaces/srv/DeleteById.srv @@ -0,0 +1,5 @@ +# Remove a POI (also from the tours) or a tour of the active site. +string id +--- +bool success +string message diff --git a/src/molly_interfaces/srv/Gesture.srv b/src/molly_interfaces/srv/Gesture.srv index 7f1bf18..929f495 100644 --- a/src/molly_interfaces/srv/Gesture.srv +++ b/src/molly_interfaces/srv/Gesture.srv @@ -1,4 +1,4 @@ -# Run a robot gesture by name (one of the interaction node's `gestures`). +# Run a robot gesture by name (one of interaction_node's gestures); answers when it is done. string name --- bool success diff --git a/src/molly_interfaces/srv/GoToPoi.srv b/src/molly_interfaces/srv/GoToPoi.srv new file mode 100644 index 0000000..0449cd8 --- /dev/null +++ b/src/molly_interfaces/srv/GoToPoi.srv @@ -0,0 +1,5 @@ +# Walk to a POI of the active site with the path finder (planner/go_to at the POI's pose). +string id +--- +bool success +string message diff --git a/src/molly_interfaces/srv/SavePoi.srv b/src/molly_interfaces/srv/SavePoi.srv new file mode 100644 index 0000000..e5830ac --- /dev/null +++ b/src/molly_interfaces/srv/SavePoi.srv @@ -0,0 +1,8 @@ +# Create or update a POI of the active site; an empty poi.id creates one (id from the name). +# at_robot_pose: take x, y and yaw from the robot's current pose in the map. +Poi poi +bool at_robot_pose +--- +bool success +string message +Poi poi # as saved, with its id diff --git a/src/molly_interfaces/srv/SaveTour.srv b/src/molly_interfaces/srv/SaveTour.srv new file mode 100644 index 0000000..ce43fb6 --- /dev/null +++ b/src/molly_interfaces/srv/SaveTour.srv @@ -0,0 +1,6 @@ +# Create or update a tour of the active site; an empty tour.id creates one (id from the name). +Tour tour +--- +bool success +string message +Tour tour # as saved, with its id diff --git a/src/molly_interfaces/srv/TourControl.srv b/src/molly_interfaces/srv/TourControl.srv index 711281d..ed904e0 100644 --- a/src/molly_interfaces/srv/TourControl.srv +++ b/src/molly_interfaces/srv/TourControl.srv @@ -1,4 +1,4 @@ -# Same as publishing on /tour/cmd, with an answer. +# Same as publishing on tour/cmd, with an answer. TourCommand command --- bool success From a76dab88bc801030b51704f2aa4e482ea9aea470 Mon Sep 17 00:00:00 2001 From: Agus Darmawan Date: Thu, 29 Oct 2026 09:53:05 +0700 Subject: [PATCH 03/34] refactor(guide): tour engine and site content as pure cores with enums, unit tests --- src/molly_guide/config/guide_params.yaml | 39 -- src/molly_guide/launch/guide.launch.py | 27 - src/molly_guide/molly_guide/core/__init__.py | 0 src/molly_guide/molly_guide/core/config.py | 95 +++ .../molly_guide/core/site/__init__.py | 0 .../molly_guide/core/site/archive.py | 56 ++ .../molly_guide/core/site/store.py | 167 +++++ .../molly_guide/core/site/validate.py | 133 ++++ .../molly_guide/core/tour/__init__.py | 31 + .../molly_guide/core/tour/engine.py | 290 +++++++++ .../molly_guide/core/tour/followers.py | 89 +++ .../molly_guide/core/tour/model.py | 176 +++++ .../molly_guide/core/tour/request.py | 61 ++ .../molly_guide/core/tour/steps.py | 254 ++++++++ src/molly_guide/molly_guide/tour.py | 604 ------------------ src/molly_guide/package.xml | 15 +- src/molly_guide/setup.py | 20 +- src/molly_guide/test/test_copyright.py | 25 - src/molly_guide/test/test_flake8.py | 23 - src/molly_guide/test/test_guide_node.py | 228 ------- src/molly_guide/test/test_node_members.py | 116 ---- src/molly_guide/test/test_pep257.py | 23 - src/molly_guide/test/test_style.py | 10 + src/molly_guide/test/test_tour.py | 335 ---------- src/molly_guide/test/unit/test_engine.py | 288 +++++++++ src/molly_guide/test/unit/test_followers.py | 123 ++++ src/molly_guide/test/unit/test_request.py | 47 ++ .../test/unit/test_site_content.py | 122 ++++ 28 files changed, 1960 insertions(+), 1437 deletions(-) delete mode 100644 src/molly_guide/config/guide_params.yaml delete mode 100644 src/molly_guide/launch/guide.launch.py create mode 100644 src/molly_guide/molly_guide/core/__init__.py create mode 100644 src/molly_guide/molly_guide/core/config.py create mode 100644 src/molly_guide/molly_guide/core/site/__init__.py create mode 100644 src/molly_guide/molly_guide/core/site/archive.py create mode 100644 src/molly_guide/molly_guide/core/site/store.py create mode 100644 src/molly_guide/molly_guide/core/site/validate.py create mode 100644 src/molly_guide/molly_guide/core/tour/__init__.py create mode 100644 src/molly_guide/molly_guide/core/tour/engine.py create mode 100644 src/molly_guide/molly_guide/core/tour/followers.py create mode 100644 src/molly_guide/molly_guide/core/tour/model.py create mode 100644 src/molly_guide/molly_guide/core/tour/request.py create mode 100644 src/molly_guide/molly_guide/core/tour/steps.py delete mode 100644 src/molly_guide/molly_guide/tour.py delete mode 100644 src/molly_guide/test/test_copyright.py delete mode 100644 src/molly_guide/test/test_flake8.py delete mode 100644 src/molly_guide/test/test_guide_node.py delete mode 100644 src/molly_guide/test/test_node_members.py delete mode 100644 src/molly_guide/test/test_pep257.py create mode 100644 src/molly_guide/test/test_style.py delete mode 100644 src/molly_guide/test/test_tour.py create mode 100644 src/molly_guide/test/unit/test_engine.py create mode 100644 src/molly_guide/test/unit/test_followers.py create mode 100644 src/molly_guide/test/unit/test_request.py create mode 100644 src/molly_guide/test/unit/test_site_content.py diff --git a/src/molly_guide/config/guide_params.yaml b/src/molly_guide/config/guide_params.yaml deleted file mode 100644 index fb3a528..0000000 --- a/src/molly_guide/config/guide_params.yaml +++ /dev/null @@ -1,39 +0,0 @@ -guide_node: - ros__parameters: - # Language of the guide's own texts (POI narrations carry their own language) - language: id - # Said at the start and the end of a tour and when nobody follows; language:text, "" none - intro_texts: - - "id:Halo semuanya, saya Molly. Mari ikuti saya, kita mulai turnya." - - "en:Hello everyone, I am Molly. Please follow me, let's start the tour." - outro_texts: - - "id:Turnya sudah selesai. Terima kasih sudah berkeliling bersama saya!" - - "en:That is the end of the tour. Thank you for walking with me!" - follow_me_texts: - - "id:Ayo, ikuti saya ya." - - "en:Please follow me." - gestures: true # play the POI gestures (interaction/gesture) - narrate: true # say the POI narrations and the guide's texts - # Walking to a POI (planner/go_to, then planner/status arrived) - arrival_timeout_sec: 300.0 # walking time (waits for visitors excluded) - go_to_retries: 1 # tries after a failed walk - retry_delay_sec: 3.0 - on_failure: skip # skip: go on with the next POI | stop: tour in ERROR - gesture_timeout_sec: 25.0 - # Narration time limit: base + characters / chars_per_sec, then the tour goes on anyway - narration_timeout_base_sec: 15.0 - narration_chars_per_sec: 8.0 - # Followers (perception/visitors.behind): nobody behind for visitor_lost_sec while walking - # holds the walk (navigation/pause) and asks the visitors to follow; the walk goes on once - # somebody is behind for visitor_found_sec, or after visitor_wait_sec (then not again on - # this leg). Off without fresh visitor data or while the handheld drives (REMOTE). - wait_for_visitors: true - visitor_lost_sec: 6.0 - visitor_found_sec: 1.0 - visitor_wait_sec: 20.0 - visitors_timeout_sec: 2.0 - # START needs a localized robot in AUTO - require_localization: true - require_auto_mode: true - tick_hz: 10.0 - publish_period_sec: 1.0 # /tour/state also without a change diff --git a/src/molly_guide/launch/guide.launch.py b/src/molly_guide/launch/guide.launch.py deleted file mode 100644 index 1ba8a63..0000000 --- a/src/molly_guide/launch/guide.launch.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -import os - -from ament_index_python.packages import get_package_share_directory -from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument -from launch.substitutions import LaunchConfiguration -from launch_ros.actions import Node - - -def generate_launch_description(): - """Launch the guide (tours).""" - default_params = os.path.join( - get_package_share_directory('molly_guide'), 'config', 'guide_params.yaml' - ) - return LaunchDescription( - [ - DeclareLaunchArgument('params_file', default_value=default_params), - Node( - package='molly_guide', - executable='guide_node', - name='guide_node', - output='screen', - parameters=[LaunchConfiguration('params_file')], - ), - ] - ) diff --git a/src/molly_guide/molly_guide/core/__init__.py b/src/molly_guide/molly_guide/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/molly_guide/molly_guide/core/config.py b/src/molly_guide/molly_guide/core/config.py new file mode 100644 index 0000000..4a226a5 --- /dev/null +++ b/src/molly_guide/molly_guide/core/config.py @@ -0,0 +1,95 @@ +"""Configuration of guide_node and site_content_node (typed parameters).""" + +from __future__ import annotations + +from dataclasses import dataclass + +from dharma_utils.config import param + +ON_FAILURE = ('skip', 'stop') +INTRO_TEXTS = ( + 'id:Halo semuanya, saya Molly. Mari ikuti saya, kita mulai turnya.', + "en:Hello everyone, I am Molly. Please follow me, let's start the tour.", +) +OUTRO_TEXTS = ( + 'id:Turnya sudah selesai. Terima kasih sudah berkeliling bersama saya!', + 'en:That is the end of the tour. Thank you for walking with me!', +) +FOLLOW_ME_TEXTS = ('id:Ayo, ikuti saya ya.', 'en:Please follow me.') + + +@dataclass(frozen=True) +class GuideConfig: + """How a tour runs: texts, timeouts, retries and waiting for the visitors.""" + + language: str = param('id', live=False, doc="language of the guide's own texts") + intro_texts: tuple[str, ...] = param( + INTRO_TEXTS, live=False, doc='said at the start of a tour, language:text' + ) + outro_texts: tuple[str, ...] = param( + OUTRO_TEXTS, live=False, doc='said at the end of a tour, language:text' + ) + follow_me_texts: tuple[str, ...] = param( + FOLLOW_ME_TEXTS, live=False, doc='said when nobody follows, language:text' + ) + gestures: bool = param(True, doc='play the POI gestures (interaction/gesture)') + narrate: bool = param(True, doc="say the POI narrations and the guide's texts") + arrival_timeout_sec: float = param( + 300.0, min=5.0, max=3600.0, unit='s', doc='walking time to a POI (waits not counted)' + ) + go_to_retries: int = param(1, min=0, max=10, doc='tries after a failed walk') + retry_delay_sec: float = param(3.0, min=0.0, max=120.0, unit='s', doc='wait before a retry') + on_failure: str = param( + 'skip', choices=ON_FAILURE, doc='unreachable POI: skip it, or stop the tour in ERROR' + ) + gesture_timeout_sec: float = param( + 25.0, min=1.0, max=300.0, unit='s', doc='a gesture that takes longer is given up' + ) + narration_timeout_base_sec: float = param( + 15.0, min=1.0, max=600.0, unit='s', doc='narration time limit: base + length / rate' + ) + narration_chars_per_sec: float = param( + 8.0, min=1.0, max=100.0, unit='1/s', doc='narration time limit: characters per second' + ) + wait_for_visitors: bool = param( + True, doc='hold the walk and ask the visitors to follow when nobody is behind' + ) + visitor_lost_sec: float = param( + 6.0, min=0.5, max=120.0, unit='s', doc='nobody behind this long: wait for them' + ) + visitor_found_sec: float = param( + 1.0, min=0.0, max=60.0, unit='s', doc='somebody behind this long: walk on' + ) + visitor_wait_sec: float = param( + 20.0, min=1.0, max=600.0, unit='s', doc='longest wait, then not again on this leg' + ) + visitors_timeout_sec: float = param( + 2.0, min=0.1, max=30.0, unit='s', doc='older perception/visitors: no waiting' + ) + require_localization: bool = param(True, doc='START needs localization/status localized') + require_auto_mode: bool = param(True, doc='START needs the control mux in AUTO') + stop_settle_sec: float = param( + 0.5, min=0.0, max=10.0, unit='s', doc='STOPPING lasts this long before IDLE' + ) + tick_hz: float = param(10.0, min=1.0, max=50.0, unit='Hz', live=False, doc='timer rate') + publish_period_sec: float = param( + 1.0, min=0.1, max=10.0, unit='s', doc='tour/state also without a change' + ) + goal_tolerance: float = param( + 0.05, min=0.001, max=1.0, unit='m', doc='planner/status goal counts as the POI within' + ) + + +@dataclass(frozen=True) +class SiteContentConfig: + """Where the POIs and tours of the sites live.""" + + sites_dir: str = param( + '~/dev/Molly/map', live=False, doc='one directory per site (same as dharma_mapping)' + ) + refresh_sec: float = param( + 2.0, min=0.2, max=60.0, unit='s', doc='files re-read when changed on disk' + ) + archive_with_map: bool = param( + True, doc='move POIs and tours into the backup a mapping reset makes of the site' + ) diff --git a/src/molly_guide/molly_guide/core/site/__init__.py b/src/molly_guide/molly_guide/core/site/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/molly_guide/molly_guide/core/site/archive.py b/src/molly_guide/molly_guide/core/site/archive.py new file mode 100644 index 0000000..2477587 --- /dev/null +++ b/src/molly_guide/molly_guide/core/site/archive.py @@ -0,0 +1,56 @@ +""" +POIs and tours follow the map when a mapping reset archives a site. + +A reset (dharma_mapping `mapping/start {reset: true}`) moves the site's map, tags and routes into +a new `/backup-