examples package
Submodules
examples.fourbar_linkage module
The fourbar_linkage module demonstrates the features of pylinkage.
It is not intended to be imported in another project, but feel welcome to copy-paste chunks of code.
Created on Sat Jun 19, 12:32:37 2021.
@author: HugoFara
- examples.fourbar_linkage.define_linkage()
Define a simple four-bar linkage.
- Returns:
A demo four-bar linkage.
- Return type:
pylinkage.Linkage
- examples.fourbar_linkage.main()
Define and optimize a demo linkage.
examples.inverted_stroke_engine module
An inverted four-stroke engine, that converts a rotary motion into a linear one.
See: https://en.wikipedia.org/wiki/Four-stroke_engine for details
- examples.inverted_stroke_engine.create_stroke_engine_linkage()
Create an inverted stroke engine linkage.
- examples.inverted_stroke_engine.view_linkage()
View a stroke engine linkage in action
examples.strider module
Kinematic Strider linkage, a type of walking linkage.
The original linkage can be found at https://www.diywalkers.com/strider-linkage-plans.html
- examples.strider.LAP_PER_SECOND = 100
Parameters that can change without changing joints between objects.
Can be distance between joints, or an angle. Units are given relative to crank length, which is normalized to 1.
- examples.strider.complete_strider(constraints, prev)
Take two sequences to define strider linkage.
- Parameters:
constraints (tuple[float] | tuple[tuple[float]]) – The sequence of geometrical constraints.
prev (tuple[tuple[float, float]]) – Coordinates to set by default.
- Return pylinkage.Linkage:
A strider linkage
- examples.strider.history_saver(evaluator, history, linkage, dims, pos)
Save the history to a list.
- Parameters:
evaluator – Evaluation function
history – History list
linkage – Input linkage
dims – Dimensions
pos – Initial positions
- examples.strider.main()
Build and optimize a strider linkage.
You can find it at https://www.diywalkers.com/strider-linkage-plans.html
- examples.strider.param2dimensions(param=(2, 0.7853981633974483, 1.8, 2.6, 1.4, 3.3415926535897933, 2.5, 1.8), flat=False)
Expand dimensions them to fit in strider.set_num_constraints.
Dimensions parameters are written in short form due to symmetry.
- Parameters:
param – Short form for dimensions (Default value = DIMENSIONS)
flat – If the output should be a flat list (Default value = False)
- Returns:
Expanded dimensions
- examples.strider.show_optimized(linkage, data, n_show=10, duration=5, symmetric=True)
Show the optimized linkages.
- Parameters:
linkage – Linkage to modify.
data – Linkage data
n_show – Number of linkages to show (Default value = 10)
duration – Duration of each animation (Default value = 5)
symmetric – If the input dimensions should be symmetric (Default value = True)
- examples.strider.swarm_optimizer(linkage, dimensions=(2, 0.7853981633974483, 1.8, 2.6, 1.4, 3.3415926535897933, 2.5, 1.8), show=0, save_each=0, n_agents=300, n_iterations=400, *args)
Optimize linkage geometrically using PSO.
- Parameters:
linkage (pylinkage.linkage.Linkage) – The linkage to optimize.
dimensions (list[float]) – The dimensions that should vary. Default value = DIMENSIONS.
show (int) – Type of visualization. The default is 0. - 0 to avoid any visualization - 1 for polar graph - 2 for tiled 2D representation
save_each (int) – If show is 0, save the image each {save_each} frame. The default is 0.
n_agents (int) – Number of agents to simulate. The default is 300.
n_iterations (int) – Number of iterations to run through. The default is 400.
args (list) – Arguments to pass to the particle swarm optimization.
- Returns:
List of fittest linkages.
- Return type:
list
- examples.strider.sym_stride_evaluator(linkage, dimensions, initial_positions)
Give score to each dimension set for symmetric strider.
- Parameters:
linkage (pylinkage.Linkage) – Input linkage
dimensions (tuple) – Dimensions
initial_positions (tuple) – Initial positions
- Returns:
Score
- Return type:
float
- examples.strider.view_swarm_polar(linkage, dimensions=(2, 0.7853981633974483, 1.8, 2.6, 1.4, 3.3415926535897933, 2.5, 1.8), save_each=0, n_agents=300, n_iterations=400)
Draw an animation of the swarm in a polar graph.
- Parameters:
linkage (pylinkage.Linkage) – Input linkage
dimensions (Sized) – Dimensions (Default value = DIMENSIONS)
save_each (int | None) – To save the linkage state (Default value = 0)
n_agents (int) – Number of agents (Default value = 300)
n_iterations (int) – NUmber of iterations (Default value = 400)
- examples.strider.view_swarm_tiled(linkage, dimensions=(2, 0.7853981633974483, 1.8, 2.6, 1.4, 3.3415926535897933, 2.5, 1.8), save_each=0, n_agents=300, n_iterations=400)
Represent the final state of the best linkages.
- Parameters:
linkage (Linkage) – Linkage to edit
dimensions (Sized) – Dimensions (Default value = DIMENSIONS)
save_each (int | None) – Period of state save (Default value = 0)
n_agents (int) – Number of agents (Default value = 300)
n_iterations (int) – NUmber of iterations (Default value = 400)
Module contents
This package feature some simple modules to demonstrate the capabilities of pylinkage.
Created on Sat Jun 26 17:29:26 2021.
@author: HugoFara.