physicsengine

Dynamic Simulator

The physicsengine module gives a dynamic behavior to legged mechanism.

It uses the 2D physics engine chipmunk, this is why it can only be used on planar mechanisms. In theory, you can use any type of mechanism, and not only planar mechanisms. In practice, we do generate the road and some other parameters as the gravity, so it can be difficult to test something other than a walker.

Created on Sat May 25 2019 14:56:01.

@author: HugoFara

class leggedsnake.physicsengine.World(space=None, road_y=-5)

Bases: object

A world contains a space of simulation, at least one linkage, and a road.

It is not intended to be rendered visually per se, see VisualWorld for this purpose.

__init__(space=None, road_y=-5)

Initiate rigidbodies and simulation.

Add rigidbodies in linkage.

Parameters:
  • space (pymunk.space.Space, optional) – Space of simulation. The default is None.

  • road_y (float, optional) – The ordinate of the ground. Useful when linkages have long legs. The default is -5.

add_linkage(linkage, load=0)

Add a DynamicLinkage to the simulation.

Parameters:
  • linkage (pylinkage.Linkage or leggedsnake.DynamicLinkage) – Linkage to add. We use the linkage’s space if it is a DynamicLinkage.

  • load (float, optional) – Load to add the center of the linkage. Has no effect when using a DynamicLinkage. The default is 0.

build_road(positive=False)

Build a road part.

Parameters:

positive (if False (default), the road part will be added on the left.) –

update(dt=None)

Update simulation.

Parameters:

dt (float | None) – Time of the step (delta-time). Uses params[“simul”][“physics_period”] if None.

leggedsnake.physicsengine.linkage_bb(linkage)

Return the bounding box for this linkage.

The bounding box is in form (min_y, max_x, max_y, min_x).

Parameters:

linkage (pylinkage.linkage.Linkage) – The linkage from which to get the bounding box.

leggedsnake.physicsengine.recalc_linkage(linkage)

Assign a good position to all joints.

leggedsnake.physicsengine.set_space_constraints(space)

Set the solver if they are many constraints.