Skip to content

feat(blocks): register the parameters of every block, so set_param, parameters() and --set work - #940

Draft
petercorke wants to merge 2 commits into
mainfrom
feat/block-parameters
Draft

petercorke wants to merge 2 commits into
mainfrom
feat/block-parameters

Conversation

@petercorke

@petercorke petercorke commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Thanks for contributing to RTB!

Summary

Register the parameters of every RTB block with bdsim's parameter registry, so block.set_param(), block.parameters() and bdsim's --set and --param work on them. None was registered: parameters() returned {} for every RTB block.

Every __init__ argument of the 27 blocks in arm.py, mobile.py, spatial.py and uav.py is registered with add_param:

  • when="never": robot and model, which fix the ports and states.
  • when="setup": anything start() reads, such as q0, T, trajectory end points and plot options. It can be set before the run starts, not during it.
  • when="anytime": everything else.
  • A Python property where the block derived state from the argument: FDyn/FDyn_X q0 (the first half of the initial state), Jacobian frame/representation/inverse/pinv (they rebuild the function and check each other), CirclePath frequency/phase (kept in the unit given), Point2Tr T, the vehicle limits and L/w of Bicycle/Unicycle/DiffSteer (written into the vehicle model), MultiRotor x0 (keeps its short forms) and MultiRotorMixer wmax/wmin.

tests/test_block_parameters.py checks that no argument is left out, and has behaviour tests for the properties.

Fixes found on the way, in this commit because the registration made them visible:

  • IKine.start() took no simstate, so any run with an IKINE block failed.
  • IKine ignored its seed argument and always used 0. It is used now; the default is still 0.
  • JTraj, CTraj, Trapezoidal and Traj overwrote T with the length of the first run, so a later run of a different length used the old one.

Not fixed, found: CTRAJ, TRAJ and TRAPEZOIDAL cannot be compiled into a diagram, because bdsim's compile() evaluates outputs before start(); this is so on main. Trapezoidal also fails when q0 and qf are vectors. The tests start those blocks directly.

VehiclePlot.shape cannot be a parameter, since a block already has a shape property. It is the one exception in the test. petercorke/bdsim#255 removes Block.shape, after which it can be.

Public behaviour: set_param and --set now work on RTB blocks, and seed and per-run T behave as above. No change to numerical results otherwise.

Conflicts with #938 in FDyn.__init__ (both touch the initial acceleration); I will rebase whichever is second.

Related: #937 changes how the vehicle limits are stored, which the vehicle-limit properties here write to.

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

Related issue

None.

Checklist

  • I checked that no other open PR already addresses this Issue
  • PR title follows Conventional Commits (type: description)
  • Tests pass locally (pytest): 2470 passed, 9 skipped
  • Added/updated tests for this change
  • New/changed code is type-hinted with modern syntax
  • Docstrings updated
  • PR is as small/focused as practical: it is a large change by nature, and includes three small bug fixes that could be split out
  • 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

…arameters() and --set work

Every __init__ argument of the arm, mobile, spatial and UAV blocks is registered with
add_param, with when="anytime", "setup" (read by start()) or "never" (the robot and
model, which fix the ports). Values that the block derived state from are properties:
FDyn q0, Jacobian frame/representation/inverse/pinv, CirclePath frequency/phase,
Point2Tr T, the vehicle limits and dimensions, MultiRotor x0 and MultiRotorMixer
wmax/wmin. tests/test_block_parameters.py checks that none is left out.

Fixes found on the way:
- IKine.start() took no simstate, so any run with an IKINE block failed
- IKine ignored its seed argument, it is now used (the default is still 0)
- JTraj, CTraj, Trapezoidal and Traj overwrote T with the length of the first run,
  so a later run of a different length used the old one

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke petercorke self-assigned this Nov 15, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 101 complexity · 4 duplication

Metric Results
Complexity 101
Duplication 4

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.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke marked this pull request as draft November 15, 2026 02:55
@petercorke

Copy link
Copy Markdown
Owner Author

Held as a draft: this needs bdsim 1.5.0, which is not released yet. add_param(when=...) and the parameter registry are new in 1.5.0, and RTB's CI installs the latest bdsim from PyPI (1.4.0), so the jtraj tests fail there with Block.add_param() got an unexpected keyword argument 'when'; the mypy failure was unused type: ignore comments, removed in the last commit. When bdsim 1.5.0 is on PyPI: bump the bdsim requirement in pyproject.toml to >=1.5.0, re-run CI, and merge.

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