interface
Joint definition
Definition of the different joints used for pylinkage.
- class pylinkage.interface.joint.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
- xfloat, optional
initial horizontal position, won’t be used thereafter. The default is None.
- yfloat, optional
initial vertical position. The default is None.
- joint0Union[Joint, tuple[float]], optional
first reference joint. The default is None.
- distancefloat, optional
distance to keep between joint0 and self. The default is None.
- anglefloat, optional
It is the angle (horizontal axis, joint0, self). Should be in radian and in trigonometric order. The default is None.
- namestr, optional
user-friendly name. The default is None.
Returns
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.
- Parameters:
dt (float) – Fraction of step to do (Default value = 1)
- set_anchor0(joint, distance=None)
First joint anchor and fixed distance.
- Parameters:
joint –
distance – (Default value = None)
- set_constraints(distance=None, *args)
Set geometric constraints, only self.r is affected.
- Parameters:
distance (float) – Distance from the reference point. (Default value = None)
args – Unused, but preserves the object structure.
- class pylinkage.interface.joint.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.
Arguments
- 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.
- joint0Union[Joint, tuple[float]], optional
Linked pivot joint 1 (geometric constraints). The default is None.
- joint1Union[Joint, tuple[float]], optional
Other pivot joint linked. The default is None.
- distancefloat, optional
Distance to keep constant between joint0 and self. The default is None.
- anglefloat, 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.
- Parameters:
joint –
distance – (Default value = None)
angle – (Default value = None)
- set_anchor1(joint)
Second joint anchor.
- Parameters:
joint –
- set_constraints(distance=None, angle=None)
Set geometric constraints.
- Parameters:
distance – (Default value = None)
angle – (Default value = None)
- class pylinkage.interface.joint.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.
Arguments
- 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.
- joint0Union[Joint, tuple[float]], optional
Linked pivot joint 1 (geometric constraints). The default is None.
- joint1Union[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.
- Parameters:
args (tuple[float, float] | tuple[tuple[float, float]]) – Coordinates to set, either as two elements or as a tuple of 2 elements
- x
- y
- class pylinkage.interface.joint.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.
Arguments
- 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.
- joint0Union[Joint, tuple[float]], optional
Linked pivot joint 1 (geometric constraints). The default is None.
- joint1Union[Joint, tuple[float]], optional
Other pivot joint linked. The default is None.
- distance0float, optional
Distance from joint0 to the current Joint. The default is None.
- distance1float, 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.
- Parameters:
joint (Joint) – Parent joint
- Returns:
Circle is a tuple (abscisse, ordinate, radius).
- Return type:
tuple[float, float, float]
- 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 (Joint | tuple[float]) – The joint to use as anchor.
distance (float) – Distance to keep constant from the anchor. The default is None.
- set_anchor1(joint, distance=None)
Set the second anchor for this Joint.
- Parameters:
joint (Joint | tuple[float]) – The joint to use as anchor.
distance (float) – Distance to keep constant from the anchor. The default is None.
- set_constraints(distance0=None, distance1=None)
Set geometric constraints.
- Parameters:
distance0 – (Default value = None)
distance1 – (Default value = None)
- class pylinkage.interface.joint.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.
- Parameters:
joint –
- set_anchor1(joint)
Second joint anchor.
- Parameters:
joint –
- set_constraints(*args)
Do nothing, for consistency only.
- Parameters:
args – Unused
Linkage definition
The linkage module defines useful classes for linkage definition.
Created on Fri Apr 16, 16:39:21 2021.
@author: HugoFara
- class pylinkage.interface.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 (Iterable[Joint]) – All Joint to be part of the linkage.
order (Iterable[Joint]) – Sequence to manually define resolution order for each step. It should be a subset of joints. Automatic computed order is experimental! (Default value = None).
name (str) – Human-readable name for the Linkage. If None, take the value str(id(self)). (Default value = None).
- _cranks
- _solve_order
- get_coords()
Return the positions of each element in the system.
- get_num_constraints(flat=True)
Numeric constraints of this linkage.
- Parameters:
flat (bool) – Whether to force one-dimensional representation of constraints. The default is True.
- Returns:
List of geometric constraints.
- Return type:
list
- get_rotation_period()
The number of iterations to finish in the previous state.
Formally, it is the common denominator of all crank periods.
- Returns:
Number of iterations with dt=1.
- Return type:
int
- 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. (Default value = None)
- set_completely(dimensions, positions, flat=True)
Set both dimension and initial positions.
- Parameters:
dimensions (tuple[float] | tuple[tuple[float, float]]) – List of dimensions.
positions (tuple[tuple[float, float]]) – Initial positions
flat (bool) – If the dimensions are in “flat mode”. The default is True.
- set_coords(coords)
Set coordinates for all joints of the linkage.
- Parameters:
coords –
- set_num_constraints(constraints, flat=True)
Set numeric constraints for this linkage.
Numeric constraints are distances or angles between joints.
- Parameters:
constraints (Iterable) – 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. (Default value = True)
- step(iterations=None, dt=1)
Make a step of the linkage.
- Parameters:
iterations (int) – Number of iterations to run across. If None, the default is self.get_rotation_period(). (Default value = None)
dt (float) – Amount of rotation to turn the cranks by. All cranks rotate by their self.angle * dt. The default is 1. (Default value = 1)
- Returns:
Iterable of the joints’ coordinates.
- Return type:
Generator[tuple[float, float]]
Exceptions
The exceptions module is a simple quick way to access the built-in exceptions.
Created on Wed Jun 16, 15:20:06 2021.
@author: HugoFara