dynamiclinkage

Interface to dynamic compatible joints

The dynamiclinkage module is an interface between Pymunk and a kinematic linkage.

It provides various classes to overwrite the pylinkage.Joint objects. It also includes a DynamicLinkage that inherits from pylinkage.linkage.Linkage. Eventually a handy convert_to_dynamic_linkage method can generate a DynamicLinkage from a pylinkage.linkage.Linkage.

class leggedsnake.dynamiclinkage.DynamicJoint(body0=None, body1=None, space=None, radius=0.3, density=1, shape_filter=None)

Bases: ABC

Dynamic, pymunk compatible equivalent of kinematic Joint.

__init__(body0=None, body1=None, space=None, radius=0.3, density=1, shape_filter=None)

Partial class to generate a DynamicJoint.

A DynamicJoint is a Joint that can handle Pymunk Bodies.

Parameters:
  • body0 (pymunk.body.Body, optional) – First Body to link to. The default is None.

  • body1 (pymunk.body.Body, optional) – Second Body to link to. The default is None

  • space (pymunk.space.Space, optional) – Simulation space in which the DynamicJoint exists. The default is None.

  • radius (float, optional) – DynamicJoint will generate hulls of this radius. The default is .3.

  • density (float, optional) – Density of the hull, mass will be computed accordingly. The default is 1.

  • shape_filter (pymunk.shapes.ShapeFilter, optional) – Prevent hulls from colliding with each other. Useful is the same linkage for instance. The default is None.

_abc_impl = <_abc._abc_data object>
reload()

Reload DynamicJoint coordinates.

Coordinates only depend on Body position and DO NOT use any linkage constraint.

Return type:

None.

class leggedsnake.dynamiclinkage.DynamicLinkage(joints, space, density=1, load=0, name=None, thickness=0.1)

Bases: Linkage

Dynamic counterpart of a kinematic linkage.Linkage.

It has several attributes linked to its dynamic nature and is close to an empty shell in the ways you will use it.

Please note that it carries a load, which is relevant with real-world simulation where the weight of legs is small compared to the weight of the frame.

__init__(joints, space, density=1, load=0, name=None, thickness=0.1)

Instanciate a new DynamicLinkage.

Parameters:
  • joints (linkage.Joint) – Joints to be part of the linkage. Kinematic joints will be converted to their dynamic equivalents.

  • space (pymunk.Space) – Space in which linkage should be instantiated.

  • density (float, optional) – Density of the Bodies in the linkage. The default is 1.

  • load (float, optional) – Mass of the load to carry. The default is 0.

  • name (TYPE, optional) – User-friendly name for the linkage. The default is None. It will be set to str(id(self)) if not provided.

  • thickness (float, optional) – ratio bar length/width for each bar (radius in pymunk). The default is .1.

Return type:

None.

_thickness
body
build_load(position, load_mass)

Create the load this linkage has to carry.

convert_to_dynamic_joints(joints)

Convert a kinematic joint in its dynamic counterpart.

density
filter
height
joint_to_rigidbodies
mass
mechanical_energy
rigidbodies
space
class leggedsnake.dynamiclinkage.DynamicPivot(x=0, y=0, joint0=None, space=None, joint1=None, distance0=None, distance1=None, name=None, radius=0.3, density=1, shape_filter=None)

Bases: Pivot, DynamicJoint

Dynamic counterpart of a Pivot joint.

__init__(x=0, y=0, joint0=None, space=None, joint1=None, distance0=None, distance1=None, name=None, radius=0.3, density=1, shape_filter=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>
r0
r1
reload()

Reload DynamicJoint coordinates.

Coordinates only depend on Body position and DO NOT use any linkage constraint.

Return type:

None.

set_anchor_a(joint, distance=None)

Set anchor_a characteristics.

Parameters:
  • joint (DynamicJoint) – DynamicJoint to use as anchor_a.

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

Return type:

None.

set_anchor_b(joint, distance=None)

Set anchor_b characteristics.

Parameters:
  • joint (DynamicJoint) – DynamicJoint to use as anchor_b.

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

Return type:

None.

class leggedsnake.dynamiclinkage.Motor(x=None, y=None, joint0=None, space=None, distance=None, angle=None, name=None, radius=0.3, density=1, shape_filter=None)

Bases: Crank, DynamicJoint

A Motor is a crank.

It makes a link between a body and a second link it creates. It attaches them with a PivotJoint, and adds a SimpleMotor over it. The bodies are now constrained to rotate around one each other.

The Motor is placed at the extremity of the body it creates.

__init__(x=None, y=None, joint0=None, space=None, distance=None, angle=None, name=None, radius=0.3, density=1, shape_filter=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
r
reload()

Reload DynamicJoint coordinates.

Coordinates only depend on Body position and DO NOT use any linkage constraint.

Return type:

None.

set_anchor_a(joint, distance=None)

Set anchor_a characteristics.

Parameters:
  • joint (DynamicJoint) – DynamicJoint to use as anchor_a.

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

Return type:

None.

class leggedsnake.dynamiclinkage.Nail(x=0, y=0, name=None, body=None, space=None, radius=0.3, density=1, shape_filter=None)

Bases: Static, DynamicJoint

A simple point to follow a rigidbody.

It is special since it DOES NOT generate bodies.

__init__(x=0, y=0, name=None, body=None, space=None, radius=0.3, density=1, shape_filter=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>
reload()

Reload position based on linked body rotation and position.

class leggedsnake.dynamiclinkage.PinUp(x=0, y=0, joint0=None, space=None, joint1=None, distance=None, angle=None, name=None, radius=0.3, density=1, shape_filter=None)

Bases: Fixed, DynamicJoint

Dynamic counterpart of Fixed joint.

Add two pm.Segment to the linked body.

__init__(x=0, y=0, joint0=None, space=None, joint1=None, distance=None, angle=None, name=None, radius=0.3, density=1, shape_filter=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
r
reload()

Reload DynamicJoint coordinates.

Coordinates only depend on Body position and DO NOT use any linkage constraint.

Return type:

None.

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

Set first anchor characteristics.

Parameters:
  • joint (DynamicJoint) – DynamicJoint to use as anchor_a.

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

  • angle (float, optional) – Angle (in radians) (joint1, joint0, self). The default is None.

Return type:

None.

set_anchor_b(joint)

Set second anchor characteristics.

It will create errors if called before anchor_a is properly defined. SIDE EFFECT: creates two Segment objects and adds them to self.space.

Parameters:

joint (DynamicJoint) – Joint to use as anchor_b.

Return type:

None.

leggedsnake.dynamiclinkage.convert_to_dynamic_linkage(kinematic_linkage, space, density=1, load=1)

Convert a classic Linkage to its dynamic counterpart.