linkage

Joint and Linkage definition

The linkage module defines useful classes for linkage definition.

Created on Fri Apr 16, 16:39:21 2021.

@author: HugoFara

class pylinkage.linkage.Crank(x=None, y=None, joint0=None, distance=None, angle=None, name=None)

Bases: Joint

Define a crank joint.

__init__(x=None, y=None, joint0=None, distance=None, angle=None, name=None)

Define a crank (circular motor).

Parameters:
  • x (float, optional) – initial horizontal position, won’t be used thereafter. The default is None.

  • y (float, optional) – initial vertical position. The default is None.

  • joint0 (Union[Joint, tuple[float]], optional) – first reference joint. The default is None.

  • distance (float, optional) – distance to keep between joint0 and self. The default is None.

  • angle (float, optional) – It is the angle (horizontal axis, joint0, self). Should be in radian and in trigonometric order. The default is None.

  • name (str, optional) – user-friendly name. The default is None.

Return type:

None.

_abc_impl = <_abc._abc_data object>
angle
get_constraints()

Return the distance to the center of rotation.

r
reload(dt=1)

Make a step of crank.

set_anchor0(joint, distance=None)

First joint anchor and fixed distance.

set_constraints(distance=None, *args)

Set geometric constraints, only self.r is affected.

class pylinkage.linkage.Fixed(x=None, y=None, joint0=None, joint1=None, distance=None, angle=None, name=None)

Bases: Joint

Define a joint using parents locations only, with no ambiguity.

__init__(x=None, y=None, joint0=None, joint1=None, distance=None, angle=None, name=None)

Create a point, of position fully defined by its two references.

Parameters:
  • x (float, optional) – Position on horizontal axis. The default is 0.

  • y (float, optional) – Position on vertical axis. The default is O.

  • name (str, optional) – Friendly name for human readability. The default is None.

  • joint0 (Union[Joint, tuple[float]], optional) – Linked pivot joint 1 (geometric constraints). The default is None.

  • joint1 (Union[Joint, tuple[float]], optional) – Other pivot joint linked. The default is None.

  • distance (float, optional) – Distance to keep constant between joint0 and self. The default is None.

  • angle (float, optional) – Angle (joint1, joint0, self). Should be in radian and in trigonometric order. The default is None.

_abc_impl = <_abc._abc_data object>
angle
get_constraints()

Return the constraining distance and angle parameters.

r
reload()

Compute point coordinates.

We know point position relative to its two parents, which gives a local space. We know the orientation of local space, so we can solve the whole. Local space is defined by link[0] as the origin and (link[0], link[1]) as abscissas axis.

set_anchor0(joint, distance=None, angle=None)

First joint anchor and characteristics.

set_anchor1(joint)

Second joint anchor.

set_constraints(distance=None, angle=None)

Set geometric constraints.

class pylinkage.linkage.Joint(x=0, y=0, joint0=None, joint1=None, name=None)

Bases: ABC

Geometric constraint expressed by two joints.

Abstract class should always be inherited.

__init__(x=0, y=0, joint0=None, joint1=None, name=None)

Create Joint.

Parameters:
  • x (float, optional) – Position on horizontal axis. The default is 0.

  • y (float, optional) – Position on vertical axis. The default is O.

  • name (str, optional) – Friendly name for human readability. The default is None.

  • joint0 (Union[Joint, tuple[float]], optional) – Linked pivot joint 1 (geometric constraints). The default is None.

  • joint1 (Union[Joint, tuple[float]], optional) – Other pivot joint linked. The default is None.

_abc_impl = <_abc._abc_data object>
coord()

Return cartesian coordinates.

abstract get_constraints()

Return geometric constraints applying to this Joint.

joint0
joint1
name
abstract set_constraints(*args)

Set geometric constraints applying to this Joint.

set_coord(*args)

Take a sequence or two scalars, and assign them to object x, y.

x
y
class pylinkage.linkage.Linkage(joints, order=None, name=None)

Bases: object

A linkage is a set of Joint objects.

It is defined as a kinematic linkage. Coordinates are given relative to its own base.

__init__(joints, order=None, name=None)

Define a linkage, a set of joints.

Parameters:
  • joints (list[Joint]) – All Joint to be part of the linkage

  • order (list[Joint]) – Sequence to manually define resolution order for each step. It should be a subset of joints. Automatic computed order is experimental! The default is None.

  • name (str, optional) – Human-readable name for the Linkage. If None, take the value str(id(self)). The default is None.

_cranks
_solve_order
get_coords()

Return the positions of each element in the system.

get_num_constraints(flat=True)

Return numeric constraints of this linkage.

Parameters:

flat (bool) – Whether to force one-dimensional representation of constraints. The default is True.

Returns:

constraints – List of geometric constraints.

Return type:

list

get_rotation_period()

Return the number of iterations to finish in the previous state.

Formally, it is the common denominator of all crank periods.

Return type:

Number of iterations with dt=1.

hyperstaticity()

Return the hyperstaticity (over-constrainment) degree of the linkage in 2D.

joints
name
rebuild(pos=None)

Redefine linkage joints and given initial positions to joints.

Parameters:

pos (tuple[tuple[int]]) – Initial positions for each joint in self.joints. Coordinates do not need to be precise, they will allow us the best fitting position between all possible positions satisfying constraints.

set_coords(coords)

Set coordinates for all joints of the linkage.

set_num_constraints(constraints, flat=True)

Set numeric constraints for this linkage.

Numeric constraints are distances or angles between joints.

Parameters:
  • constraints (sequence) – Sequence of constraints to pass to the joints.

  • flat (bool) – If True, constraints should be a one-dimensional sequence of floats. If False, constraints should be a sequence of tuples of digits. Each element will be passed to the set_constraints method of each corresponding Joint. The default is True.

step(iterations=None, dt=1)

Make a step of the linkage.

Parameters:
  • iterations (int, optional) – Number of iterations to run across. If None, the default is self.get_rotation_period().

  • dt (int, optional) – Amount of rotation to turn the cranks by. All cranks rotate by their self.angle * dt. The default is 1.

Yields:

generator – Iterable of the joints’ coordinates.

class pylinkage.linkage.Pivot(x=0, y=0, joint0=None, joint1=None, distance0=None, distance1=None, name=None)

Bases: Joint

Center of pivot joint.

__init__(x=0, y=0, joint0=None, joint1=None, distance0=None, distance1=None, name=None)

Set point position, parents, and if it is fixed for this turn.

Parameters:
  • x (float, optional) – Position on horizontal axis. The default is 0.

  • y (float, optional) – Position on vertical axis. The default is O.

  • name (str, optional) – Friendly name for human readability. The default is None.

  • joint0 (Union[Joint, tuple[float]], optional) – Linked pivot joint 1 (geometric constraints). The default is None.

  • joint1 (Union[Joint, tuple[float]], optional) – Other pivot joint linked. The default is None.

  • distance0 (float, optional) – Distance from joint0 to the current Joint. The default is None.

  • distance1 (float, optional) – Distance from joint1 to the current Joint. The default is None.

_abc_impl = <_abc._abc_data object>
circle(joint)

Return the first link between self and parent as a circle.

Circle is a tuple (abscisse, ordinate, radius).

get_constraints()

Return the two constraining distances of this joint.

r0
r1
reload()

Compute the position of pivot joint, use the two linked joints.

set_anchor0(joint, distance=None)

Set the first anchor for this Joint.

Parameters:
  • joint (Union[Joint, tuple[float]]) – The joint to use as anchor.

  • distance (float, optional) – Distance to keep constant from the anchor. The default is None.

Return type:

None.

set_anchor1(joint, distance=None)

Set the second anchor for this Joint.

Parameters:
  • joint (Union[Joint, tuple[float]]) – The joint to use as anchor.

  • distance (float, optional) – Distance to keep constant from the anchor. The default is None.

Return type:

None.

set_constraints(distance0=None, distance1=None)

Set geometric constraints.

class pylinkage.linkage.Static(x=0, y=0, name=None)

Bases: Joint

Special case of Joint that should not move.

Mostly used for the frame.

__init__(x=0, y=0, name=None)

A Static joint is a point in space to use as anchor by other joints.

It is NOT a kind of joint as viewed in engineering terms!

xfloat, optional

Position on horizontal axis. The default is 0.

yfloat, optional

Position on vertical axis. The default is O.

namestr, optional

Friendly name for human readability. The default is None.

_abc_impl = <_abc._abc_data object>
get_constraints()

Return an empty tuple.

reload()

Do nothing, for consistency only.

set_anchor0(joint)

First joint anchor.

set_anchor1(joint)

Second joint anchor.

set_constraints(*args)

Do nothing, for consistency only.