Skip to content

fix: FDyn qdd output is an array from the first evaluation, and reset each run - #938

Open
petercorke wants to merge 2 commits into
mainfrom
fix/fdyn-qdd-output
Open

petercorke wants to merge 2 commits into
mainfrom
fix/fdyn-qdd-output

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Thanks for contributing to RTB!

Summary

FDyn cached its joint acceleration as self._qdd = None, so output port 2 (qdd) returned None until the first deriv() and an ndarray afterwards. bdsim now asserts that an output keeps the same type from one evaluation to the next, so every run with FDyn fails at the first step:

[fdyn block: forward dynamics.output] at t=0.000029
  AssertionError: output 2 changed signature: was NoneType, now ndarray(6,)

This is what breaks the icra2026 notebook in bdsim.

  • FDyn now starts the cache as np.zeros(n), so port 2 is always an ndarray.
  • FDyn and FDyn_X get a reset() that clears the cache. bdsim calls it once per run, so a run no longer starts with the last acceleration of the previous one (FDyn_X already had the zero placeholder but kept the stale value between runs).
  • output() still returns the value cached from the last deriv(); it cannot compute qdd itself because it needs the torque input, which bdsim may not have resolved yet when it calls output() (tech-debt: stateful blocks whose output() needs a resolved input (FDyn_X.xdd case) bdsim#81). The first qdd sample is therefore 0, not the true value, as it already was for FDyn_X.

Public behaviour: the qdd port no longer yields None before the first derivative, and the first sample of a second run is 0 instead of the previous run's last value. No change to the dynamics or the other ports.

Tests: test_fdyn_qdd_is_always_an_array and test_fdyn_runs_twice (a real bdsim diagram run twice with qdd watched). Both fail on main and pass here; tests/test_blocks.py passes.

This change was written with AI assistance (Claude Code); I read the diff myself.

Related issue

Related to petercorke/bdsim#81

Checklist

  • I checked that no other open PR already addresses this Issue, and commented on the Issue to claim it
  • PR title follows Conventional Commits (type: description)
  • Tests pass locally (pytest)
  • Added/updated tests for this change, if applicable
  • New/changed code is type-hinted with modern syntax
  • Docstrings updated
  • PR is as small/focused as practical
  • I understand that the Codacy check is advisory
  • If this change alters numerical results or public behaviour, I have said so in the summary above
  • If an AI assistant wrote or helped with this change, I have said so in the summary above, and I have read the diff myself
  • No test files, data files, or notebooks specific to your own project

🤖 Generated with Claude Code

…nd reset each run

FDyn initialised its cached joint acceleration to None, so port 2 returned
None until the first deriv() and an ndarray afterwards. bdsim now asserts that
an output keeps its type, so any run with FDyn failed at the first step. Start
from a zero array instead, and clear the cache in reset() so a run does not see
the last acceleration of the previous one. FDyn_X had the same stale cache
across runs and gets the same reset().

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

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

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

This branch has not been deployed

No deployments
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