Mechanisms
Build things that move: linkages, cams, Geneva drives, gear trains, rack
and lead-screw stages, flexures. Each mechanism is sized and checked for
you (Grashof class, tooth counts, cam undercut), assembled from parts that
connect through interfaces, and posed by one input: change the crank
angle and the whole linkage follows. This is the cadbuildr-mechanisms
library, built on Foundation and the standard library cadbuildr-stdlib (its
gears, bearings, shafts and lead screws are the real parts inside).
Prerequisites: pip install cadbuildr-mechanisms (it installs
cadbuildr-foundation and cadbuildr-stdlib).
A four-bar linkage in one line
from cadbuildr.foundation import show
from cadbuildr.mechanisms import FourBar
fb = FourBar(ground=100, crank=30, coupler=90, rocker=70, crank_angle=45)
print(fb.grashof.kind) # crank-rocker: the crank turns fully
show(fb)Link lengths are pivot-to-pivot distances in mm: ground between the two
fixed pivots, crank (input), coupler (floating), rocker (output).
crank_angle is the pose in degrees. In the app, the configuration bar
shows it as an input: type a new angle and the linkage moves.
From Python, move a built mechanism with set_pose:
for angle in range(0, 360, 30):
fb.set_pose(angle) # re-solves and moves every linkIf the crank cannot reach an angle (a rocker input past its limit), you get
a LinkageLockError that names the reachable range. branch="crossed"
picks the other assembly of the same links; coupler_point= /
coupler_offset= add a third pin on the coupler whose path you can trace.
The “Chebyshev straight-line” configuration is a crossed four-bar whose
coupler midpoint runs within 0.25 mm of a straight line.
Check a design before building it
The sizing math lives in cadbuildr.mechanisms.kinematics and needs no CAD:
from cadbuildr.mechanisms.kinematics import grashof, planetary_check, belt_center_distance
grashof(100, 70, 30, 80).kind # 'double-rocker'
planetary_check(15, 12, 4).problems # (sun + ring) / planets is not an integer...
belt_center_distance(400, 20, 40) # centre distance for a 400 mm beltWhat is in the library
| Mechanism | Pose input | What it checks |
|---|---|---|
FourBar | crank_angle | Grashof class, reachable range, loop closure |
SliderCrank | crank_angle | rod long enough for a full turn |
ScotchYoke | crank_angle | pin stays in the yoke slot |
CamFollower (DiscCam + roller / flat / knife follower) | cam_angle | profile undercut |
GenevaDrive | driver_angle | slot count, pin size vs centre distance |
PlanetaryGearbox | input_angle | ring = sun + 2 x planet, equal spacing, planet clearance |
SimpleGearTrain | input_angle | gear large enough for the shaft |
RackPinionStage | pinion_angle | pinion vs shaft |
LeadScrewStage | screw_angle | carriage stroke |
NotchHinge, ParallelFlexure | — | stiffness and safe stroke per material |
Cams are generated from a motion law: law="cycloidal" (smoothest,
default), "harmonic", "polynomial_345" or "uniform", over a
dwell-rise-dwell-return program (rise_deg, dwell_deg, return_deg).
Gears that turn together
The planetary gearbox is made of standard-library spur gears, two deep groove bearings and a shaft, plus a ring gear and a planet carrier. Turning the input moves the carrier and the planets at the right ratios because the joints are linked by joint relations, not by computed angles:
from cadbuildr.mechanisms import PlanetaryGearbox
pg = PlanetaryGearbox(sun=15, planet=12, planets=3)
pg.ratio # 3.6
pg.set_input_angle(360)
pg.carrier_angle_deg # 100.0The same works in your own assemblies:
from cadbuildr.foundation import GearRelation
assembly.add_relation(GearRelation(driver=input_joint, driven=output_joint,
ratio=12 / 36, reverse=True))
input_joint.set_angle(1.0) # the output joint turns -1/3 radRackPinionStage uses a RackPinionRelation (travel = angle x pitch
radius) and LeadScrewStage a ScrewRelation (travel = lead per turn).
Build your own mechanism
Link parts stack layer on layer. Each end has a top and a bottom pivot;
pin a link’s bottom pivot onto the top pivot of the link below it with
connect, and the joint angle is measured from that link’s direction:
from cadbuildr.foundation import Assembly
from cadbuildr.mechanisms import Link
asm = Assembly()
ground = Link(length=100, role="ground")
asm.ground(ground)
crank = Link(length=30, role="crank")
joint = asm.connect(crank.interface("a_bottom"), ground.interface("a_top"), angle=0.5).joint
joint.set_angle(1.2)Close a loop by connecting two pivots that are both already placed:
connect checks they meet, and asm.check() reports a loop error if a
later pose breaks it.