Skip to content

feat: auto-localization assist — yaw sweep until localized - #167

Draft
xiaolefang-dm wants to merge 9 commits into
mainfrom
xiaole/auto-localization-assist
Draft

feat: auto-localization assist — yaw sweep until localized#167
xiaolefang-dm wants to merge 9 commits into
mainfrom
xiaole/auto-localization-assist

Conversation

@xiaolefang-dm

Copy link
Copy Markdown
Contributor

Summary

When the Assist toggle is enabled on the Operate page, pressing Nav ON will:

  1. Start (begins visual relocalization attempts)
  2. NOT start — instead run a yaw sweep loop:
    • Dwell 5s at current heading
    • CW 20°, dwell 5s
    • CCW 40° (net −20° from start), dwell 5s
    • CW 60° (net +40° from start), dwell 5s
    • …expanding sweep until localized
  3. Once localization succeeds → stop sweep → start cmd_vel_control normally

This helps in scenarios where the robot's current view doesn't match any map keyframe, avoiding indefinite waiting.

Changes

File What
app/backend/node_manager.py Loc-assist state, sweep thread, auto-stop on localization
app/backend/routers/nav.py POST/GET /nav/loc-assist endpoints
app/frontend/lib/core/models.dart locAssistEnabled in DeviceStatus
app/frontend/lib/pages/operate_tab.dart _LocAssistToggle button widget

Testing

  • Python AST parse OK
  • Dart analyze (only pre-existing info warnings)
  • Flutter build web ✓ on Nano (tinynav-dev container)
  • Backend import + startup OK
  • Real robot localization test (pending)

Toggle off = original behavior

When Assist is OFF, Nav ON works exactly as before (map_node + cmd_vel_control start together).

When the 'Assist' toggle is enabled on the Operate page:
- Nav ON starts map_node but NOT cmd_vel_control
- Backend runs a yaw sweep (±expanding angles, 5s dwell each)
- Once localized, sweep stops and cmd_vel_control starts normally

Backend changes (node_manager.py):
- _loc_assist_enabled / _loc_assist_thread / _loc_assist_stop_event state
- _loc_assist_loop(): expanding yaw sweep pattern via /cmd_vel
- _on_localization_achieved(): stops sweep, launches cmd_vel_control
- cmd_start_nav_nodes skips cmd_vel_control when assist is on
- cmd_stop_nav_nodes stops assist thread
- get_status() includes locAssistEnabled

API (routers/nav.py):
- POST /nav/loc-assist {enabled: bool} — toggle
- GET /nav/loc-assist — read state

Frontend:
- DeviceStatus.locAssistEnabled field
- _LocAssistToggle button on Operate page (bottom-right, above Nav)
@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.17 s (240.8 files/s, 37919.8 lines/s)
Language files blank comment code
Python 13 669 312 3720
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 990 412 5213

@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.18 s (239.4 files/s, 37710.8 lines/s)
Language files blank comment code
Python 13 669 312 3720
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 990 412 5213

@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.18 s (236.0 files/s, 37274.9 lines/s)
Language files blank comment code
Python 13 670 312 3739
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 991 412 5232

@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.18 s (233.7 files/s, 36926.1 lines/s)
Language files blank comment code
Python 13 670 312 3739
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 991 412 5232

@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.14 s (301.9 files/s, 47689.5 lines/s)
Language files blank comment code
Python 13 670 312 3739
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 991 412 5232

@github-actions

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.17 s (240.5 files/s, 37986.1 lines/s)
Language files blank comment code
Python 13 670 312 3739
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 991 412 5232

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
cloc github.com/AlDanial/cloc v 2.04 T=0.18 s (228.2 files/s, 36310.5 lines/s)
Language files blank comment code
Python 13 673 306 3791
Markdown 4 155 6 426
C++ 4 60 38 409
Bourne Shell 15 41 9 272
Dockerfile 1 31 32 204
JSON 2 8 0 58
TOML 1 4 0 58
make 1 18 15 49
CMake 1 4 0 17
-------- -------- -------- -------- --------
SUM: 42 994 406 5284

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.

1 participant