Skip to content

docs(examples): make every example script run, animate oscillating cranks - #51

Merged
HugoFara merged 1 commit into
mainfrom
fix/examples
Sep 12, 2026
Merged

HugoFara merged 1 commit into
mainfrom
fix/examples

Conversation

@HugoFara

Copy link
Copy Markdown
Owner

Summary

Four of the twelve scripts under docs/examples/ failed — on 1.1.1 too. They are literalincluded in the docs' Examples page, so they were broken there as well.

What was wrong

  • The three synthesis demos called len(result) and if result: on a SynthesisResult, which lost __len__/__bool__ before 1.0.
  • Once past that, motion_generation_demo stopped on the first double-rocker it tried to animate: every demo drove whatever synthesis returned with a full-turn Crank, which cannot pass the position where coupler and rocker align. fourbar_from_lengths_demo failed the same way on a non-Grashof entry.
  • The Grashof-type table in fourbar_from_lengths_demo labelled (2, 4, 3, 1) double-crank and (3, 4, 3, 2) double-rocker — both are change points — and its rocker-crank could not assemble at crank angle 0.
  • Three demos ran but always came back empty: five-position approximate function generation (angle pairs starting at 0 give the Freudenstein fit a negative crank length), the straight-line path (three exactly collinear points are degenerate for Burmester theory), and both fixed-ground-pivot demos (arbitrary frame points never lie on the center-point curve; the constraint filters, it does not solve for a frame).

One library change

solution_to_linkage() now honours FourBarSolution.arc_limits. The field existed but nothing in pylinkage read it (the editor server fills it and builds its own mechanism dict). Set it — from crank_angle_limits() — and the linkage is built around an ArcCrank sweeping that range instead of a Crank. The limits are relative to the ground line as crank_angle_limits() returns them, and are placed on whichever side of the ground line the crank starts. Nothing sets the field inside pylinkage, so existing output is unchanged. Tests cover both sides of the ground line and rotated frames.

The demos animate through a small show() helper that does exactly that and prints the swept range when the crank oscillates.

Demo content

  • Grashof table lengths now match their labels; the table assembles with the crank vertical.
  • Approximate function generation uses five positions in the upper quadrant; the fit is within 0.4°.
  • Straight line: middle point bowed by 0.02.
  • Fixed pivots (path and motion): synthesize freely, list the pivots the solutions propose, fix one pair rounded to a tenth, re-synthesize. That is the workflow that produces a linkage.
  • The five-pose demo still returns nothing; that is what it sets out to show.

Verification

  • All twelve docs/examples/*.py run to completion under -W error::DeprecationWarning (matplotlib on Agg).
  • Full suite 2561 passed with deprecations as errors; ruff, mypy clean.

…anks

Four of the twelve scripts under docs/examples/ failed on 1.1.1 already.
The three synthesis demos called len(result) and 'if result:' on a
SynthesisResult, which lost __len__ and __bool__ before 1.0. Fixed, the
motion demo then stopped on the first double-rocker it animated: every
demo drove whatever synthesis returned with a full-turn Crank, which
cannot pass the position where coupler and rocker align.

solution_to_linkage() now honours FourBarSolution.arc_limits, a field
that existed but nothing in pylinkage read: set from
crank_angle_limits(), the linkage is built around an ArcCrank sweeping
that range on whichever side of the ground line the crank starts. The
demos animate through a small show() helper that does exactly that and
says so when the crank oscillates.

Also corrects the teaching content the scripts had wrong:

- fourbar_from_lengths_demo labelled (2,4,3,1) double-crank and
  (3,4,3,2) double-rocker; both are change points. Replaced with lengths
  that are what they claim, and the table assembles with the crank
  vertical so the rocker-crank closes.
- Three demos always came back empty: the five-position approximate
  function generation (its angle pairs gave a negative crank length),
  the straight-line path (three collinear points are degenerate for
  Burmester theory; the middle point is now bowed by a hundredth), and
  both fixed-ground-pivot demos. Arbitrary frame points never lie on the
  center-point curve, so those two now synthesize freely, list the
  pivots the solutions propose, and fix one pair, which is the workflow
  that works.

All twelve scripts run to completion with DeprecationWarning as an
error.
@HugoFara HugoFara added the bug Something isn't working label Sep 12, 2026
@HugoFara

Copy link
Copy Markdown
Owner Author

Also related to #25 by @the-moog . This PR fixes broken example codes.

@HugoFara
HugoFara merged commit 94445f9 into main Sep 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant