Skip to content

fix(mobile): type ParticleFilter, and fix x0, gif and mp4 output - #883

Merged
petercorke merged 6 commits into
mainfrom
typing/mobile-particlefilter
Oct 22, 2026
Merged

petercorke merged 6 commits into
mainfrom
typing/mobile-particlefilter

Conversation

@petercorke

Copy link
Copy Markdown
Owner

What

ParticleFilter was the last module in mobile/ that mypy ignored. This annotates it, so it is checked and held to disallow_untyped_defs with the other modules, and fixes the bugs that the types showed.

It carries the three commits of #735 (circular particle heading moments) from @Afloat16, with their authorship, so this supersedes #735. The typing could not be done in the same file while that PR was open.

Bugs fixed (public behavior changes)

  • run_animation(format="gif") and "mp4" raised AttributeError (self.dt does not exist). They use robot.dt and an integer frame rate, and a missing file name is a ValueError.
  • x0 was ignored when given: _init set the particles only for x0=None. A state (x, y, theta) now puts every particle there, and a matrix with a row per particle gives each its own. It is copied, and any other shape is a ValueError. run_animation did not pass x0 on at all.
  • The map property read self._map and verbose read self._verbose, neither of which was ever set, and the verbose argument was ignored.
  • No workspace is a ValueError that says so, not a TypeError from indexing None.

The history is now a PFlog NamedTuple with the same field names. Numerical results of the filter are unchanged by this PR beyond #735's heading moments.

Checked

  • mypy: clean on 165 files, with ParticleFilter removed from the list of modules still to do.
  • 17 new tests in tests/test_particle_filter_api.py (gif and mp4 written, x0 in all its forms and copy semantics, map, verbose, the errors), and fix(mobile): use circular particle heading moments #735's tests.
  • Full suite: 2335 passed, 9 skipped. tests/test_servo_half_turn.py was left out because it fails with a compiled extension built before fix(ik): preserve arbitrary half-turn pose error magnitude #793, which is a local build matter.
  • Not run: the example in the class docstring with a live animation window.

Co-authored-by: Afloat 132809511+Afloat16@users.noreply.github.com

🤖 Generated with Claude Code

Afloat16 and others added 6 commits October 22, 2026 14:39
…ound

ParticleFilter is checked by mypy and under disallow_untyped_defs, so it
leaves the list of modules still to do.  The history is now a PFlog
NamedTuple, with the same field names.

Bugs that were hidden because the module was ignored:
- run_animation(format="gif" or "mp4") used self.dt, which does not exist,
  so both raised AttributeError.  It uses robot.dt, and the frame rate is
  an integer as the writers require.  A gif or mp4 without a file name is
  a ValueError.
- the map property returned self._map, which was never set, and verbose
  returned self._verbose, which was never set (and the argument was
  ignored).  map is the map of the sensor, and verbose is what was given.
- no workspace is a ValueError saying so, not a TypeError from indexing None.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
_init handled x0=None (the constructor's x0, else random over the
workspace) but did nothing when x0 was given, so the particles were never
set.  A vector (x, y, theta) now puts every particle there and a matrix with
a row per particle gives each its own state; the array is copied, since the
particles are updated in place.  Any other shape is a ValueError.

The constructor docstring is raw, as its \theta was a tab.  An mp4 test
runs when ffmpeg is available.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…to run_animation

The constructor documents the three cases (None, a state for every
particle, a row for each particle) in a table, that identical particles are
spread by the noise R, and that the array is copied.  run and run_animation
refer to it, and _init's comment is current.

run_animation took x0 but never passed it on, so it started from the
constructor's value whatever it was given.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 17 high

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

Results:
17 new issues

Category Results
ErrorProne 2 high
Security 15 high

View in Codacy

🟢 Metrics 27 complexity · 0 duplication

Metric Results
Complexity 27
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.

@petercorke
petercorke merged commit 6b85d77 into main Oct 22, 2026
22 of 23 checks passed
@petercorke
petercorke deleted the typing/mobile-particlefilter branch October 22, 2026 05:15
@github-actions github-actions Bot mentioned this pull request Oct 22, 2026
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
src/roboticstoolbox/mobile/ParticleFilter.py 0.00% 69 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #883   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        146     146           
  Lines      17212   17241   +29     
=====================================
- Misses     17212   17241   +29     

☔ 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.

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.

2 participants