Skip to content

fix(trajectory): trapezoidal_func gives scalars for a scalar time, and is an object - #808

Merged
petercorke merged 4 commits into
chore/typing-trajectoryfrom
fix/trapezoidal-func-scalar
Oct 16, 2026
Merged

petercorke merged 4 commits into
chore/typing-trajectoryfrom
fix/trapezoidal-func-scalar

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Stacked on #807 (the base of this PR is its branch, so the diff is only the three commits here; it is retargeted to main when #807 merges).

A scalar time gave arrays with one element from trapezoidal_func and scalars from quintic_func, and a 2-D array of times raised an error. The Cartesian block even had both shapes in one variable (s = self.trapezoidalfunc(t)[0] against s = min(t / self.T, 1.0)).

  • trapezoidal_func(q0, qf, T, V) has the same name and arguments but returns a TrapezoidalProfile, an object that is called in the same way, with tb and V as declared attributes rather than attributes attached to a function. The Protocol and the cast from chore(typing): annotate tools/trajectory.py #807 go.
  • A scalar time gives scalars; an array of any shape gives arrays of that shape.
  • The bdsim Traj block validates traj at construction (it failed with an UnboundLocalError when the simulation started) and calls the two builders explicitly, so they no longer have to look alike.

Behaviour change

The bdsim Trapezoidal block output three arrays with one element each per step, and now outputs three scalars, which is what its port table says (float). The Traj block output is unchanged. Both docstrings carry a versionchanged note.

The book uses quintic, trapezoidal, mtraj, jtraj and mstraj, not the _func versions, so no errata.

Tests

tests/test_trapezoidal_profile.py, written first: 4 of 11 failed on the base (scalar shape, 2-D shape, the object, Traj validation), then all pass. Full suite: same 29 failures as main here (stale compiled extension); mypy clean on 164 files.

Related issue

Follows #807 and #805.

🤖 Generated with Claude Code

petercorke and others added 4 commits October 16, 2026 10:30
…d is an object

A scalar time gave arrays with one element from trapezoidal_func and scalars
from quintic_func, and the Cartesian block had both in the one variable.  The
profile is now a TrapezoidalProfile, called as before, with the attributes tb
and V declared instead of attached to a function, which also removes the
Protocol and the cast.

Traj validates traj at construction, rather than failing with an
UnboundLocalError in start(), and calls the two builders explicitly.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 0 duplication

Metric Results
Complexity 12
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 a6412b4 into chore/typing-trajectory Oct 16, 2026
3 checks passed
petercorke added a commit that referenced this pull request Oct 16, 2026
* chore(typing): annotate tools/trajectory.py

Remove the module from the mypy ignore list and annotate it.  mypy found
real faults that the missing annotations had hidden:

- Trajectory.qplot called xplot, which was never imported: NameError.
- jtraj documented array_like for the time but only accepted an ndarray.
- the verbose message in mstraj had a non-f-string with {slowest}.
- Trajectory.qd and qdd returned None when the trajectory had no data; they
  now raise ValueError, as the return type is an array.

trapezoidal_func returns a TrapezoidalFunc, a Protocol that says the function
has the attributes tb and V.  tblend, arrive, info and via, set by trapezoidal
and mstraj, are declared on Trajectory.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(trajectory): trapezoidal_func gives scalars for a scalar time, and is an object (#808)

* test(trajectory): scalar time gives scalars, trapezoid is an object, Traj validates traj

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test(trajectory): import TrapezoidalProfile inside its test

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(trajectory): trapezoidal_func gives scalars for a scalar time, and is an object

A scalar time gave arrays with one element from trapezoidal_func and scalars
from quintic_func, and the Cartesian block had both in the one variable.  The
profile is now a TrapezoidalProfile, called as before, with the attributes tb
and V declared instead of attached to a function, which also removes the
Protocol and the cast.

Traj validates traj at construction, rather than failing with an
UnboundLocalError in start(), and calls the two builders explicitly.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* docs(blocks): versionchanged notes for the Trapezoidal and Traj blocks

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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