Skip to content

fix(mobile): resolve the workspace in one place, with a documented precedence - #776

Merged
petercorke merged 3 commits into
mainfrom
refactor/mobile-workspace
Oct 15, 2026
Merged

petercorke merged 3 commits into
mainfrom
refactor/mobile-workspace

Conversation

@petercorke

Copy link
Copy Markdown
Owner

What

A workspace ([xmin, xmax, ymin, ymax]) was accepted by seven classes and resolved four different ways, with two directions of authority and no documentation. This makes it one function and one rule.

Before

  • VehicleBase, LandmarkMap: try: workspace.workspace except AttributeError. Drivers: hasattr. Maps/grids: expand_dims only, so an object with a workspace was not accepted. EKF and ParticleFilter: their own variants.
  • EKF overwrote the vehicle's private _workspace with its map's; ParticleFilter used a different order.
  • A vehicle's workspace never reached its driver, so RandomPath always needed its own.

After

  • roboticstoolbox.mobile.workspace.resolve_workspace(*sources): scalar, 2-vector, 4-vector, or an object with a workspace; the first usable candidate wins.
  • Precedence, documented in a new "The workspace" section of mobile.rst: explicit argument, then a map with a concrete extent, then the vehicle, then none. Something with a concrete extent beats something declared.
  • VehicleBase.workspace has a setter; EKF uses it rather than writing a private attribute.
  • RandomPath uses its vehicle's workspace when it has none. The error for "no workspace at all" therefore moves from construction to init(). This is the one deliberate behaviour change; the old test is updated.
  • The duck typing used in the book (RandomPath(workspace=map), Bicycle(workspace=map)) is unchanged.

Bugs fixed along the way

  • Bicycle(workspace=np.array([-5, 5])) raised "truth value of an array is ambiguous".
  • EKF(workspace=...) raised NameError (dim).
  • A BinaryOccupancyGrid made from a non-square workspace had width and height swapped: [0, 10, 2, 8] gave bounds [0, 6, 2, 12].
  • PolygonMap(polygons=[]) shared its default list between maps.

Testing

17 new tests (tests/test_mobile_workspace.py) for the resolver, the precedence, each class and the four bugs. Full suite: 19 failed on both main and this branch with identical names (the known C++ extension tests), 943 passed against 926. mypy is clean.

Conflicts to expect: #772 (drivers) and #774 (VehicleBase) touch neighbouring lines of drivers.py and Vehicle.py; I will rebase whichever merges second.

Relates to petercorke/rvc-ecosystem#15 (naming convention).

🤖 Generated with Claude Code

@codacy-production

codacy-production Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
ErrorProne 2 high

View in Codacy

🟢 Metrics 24 complexity · 0 duplication

Metric Results
Complexity 24
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (f59eee8) to head (650603d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/mobile/drivers.py 0.00% 24 Missing ⚠️
src/roboticstoolbox/mobile/workspace.py 0.00% 17 Missing ⚠️
src/roboticstoolbox/mobile/EKF.py 0.00% 8 Missing ⚠️
src/roboticstoolbox/mobile/OccGrid.py 0.00% 6 Missing ⚠️
src/roboticstoolbox/mobile/Vehicle.py 0.00% 5 Missing ⚠️
src/roboticstoolbox/mobile/landmarkmap.py 0.00% 5 Missing ⚠️
src/roboticstoolbox/mobile/ParticleFilter.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #776   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        143     144    +1     
  Lines      14671   14689   +18     
=====================================
- Misses     14671   14689   +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke force-pushed the refactor/mobile-workspace branch from 57ab852 to 825f136 Compare October 15, 2026 01:07
petercorke and others added 2 commits October 15, 2026 11:17
…ecedence

A workspace was resolved four different ways in seven classes, with two
directions of authority (EKF overwrote the vehicle's private _workspace with the
map's, ParticleFilter used another order) and the vehicle's workspace never
reached its driver.

- roboticstoolbox.mobile.workspace.resolve_workspace: scalar, 2-vector, 4-vector
  or an object with a workspace attribute, first usable candidate wins
- precedence: explicit argument, map, vehicle (documented in mobile.rst)
- VehicleBase, drivers, LandmarkMap, BaseMap/PolygonMap, EKF and ParticleFilter
  use it; objects with a workspace are now accepted by the maps
- VehicleBase.workspace has a setter; EKF uses it instead of writing _workspace
- RandomPath takes the workspace of its vehicle when it has none of its own, so
  the error for no workspace moves from construction to init

Also fixes, found on the way:
- Bicycle(workspace=<ndarray>) raised on the truth value of an array
- EKF(workspace=...) raised NameError (dim)
- a BinaryOccupancyGrid made from a non-square workspace had width and height
  swapped
- PolygonMap(polygons=[]) shared its default list between maps

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke force-pushed the refactor/mobile-workspace branch from 825f136 to 9b70b32 Compare October 15, 2026 01:17
@petercorke
petercorke merged commit 07090ed into main Oct 15, 2026
22 of 23 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 15, 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.

1 participant