klampt.model.access module

Defines a convenient object-oriented interface for accessing worlds, robots, objects, links, etc. For example, you can write

from klampt.model import access
wm = access.map(world)

instead of


Most notably used in the klampt.sim.batch module.

Helpers for accessing world/simulation variables using a class-style interface.

For example,:

from klampt import access

retrieves the name of robot 0. This saves a little writing compared to world.robot(0).getConfig().

You can also write:

access.map(world).robots[0].config = [q1,...,qn]

to set the configuration of robot 0, rather than world.robot(0).setConfig([q1,…,qn]).

Conveniently, you can write expressions like:

access.map(world).robots[0].config[4] = 3.5

Which is a shortcut to:

q = world.robot(0).getConfig()
q[4] = 3.5
class klampt.model.access.map(obj, setter=None)[source]

Bases: object

A class-style interface for accessing all elements of a WorldModel or Simulator.

The following class hierarchy is supported:

  • * indicates read-only

  • # indicates sub-item set access is supported (otherwise, to set you have to set the entire object)


  • *robots (list/dict of RobotModels)

  • *rigidObjects (list/dict of RigidObjectModels)

  • *terrains (list/dict of TerrainModels)

  • *elements (list/dict of all elements by id)

  • *[string]: accesses objects by name


  • *name (string)

  • *id (int)

  • *links (list/dict of RobotModelLinks)

  • #config (list of floats)

  • #velocity (list of floats)

  • #jointLimits (pair of lists of floats)

  • velocityLimits (list of floats)

  • accelerationLimits (list of floats)

  • torqueLimits (list of floats)

  • *[string]: accesses links by name


  • *name (string)

  • *id (int)

  • *robot (RobotModel)

  • parent (int)

  • geometry (Geometry3D)

  • appearance (Appearance)

  • mass (Mass)

  • #parentTransform (se3 object (R,t))

  • #transform (se3 object (R,t))

  • #axis (3-list of floats)

  • *name (string)

  • *id (int)

  • geometry (Geometry3D)

  • appearance (Appearance)

  • mass (Mass)

  • contactParameters (ContactParameters)

  • # transform (se3 object (R,t))

  • # velocity (pair of 3D vectors w,v giving angular and translational velocity)

  • *name (string)

  • *id (int)

  • geometry (Geometry3D)

  • appearance (Appearance)


  • *world (WorldModel)

  • *bodies (list of SimBodys)

  • *controllers (list/dict of SimRobotControllers)

  • *time (float)

  • *robots (list/dict of SimRobots)

  • *rigidObjects (list/dict of SimBodys)

  • *terrains (list of SimBodys)

  • gravity (3-list of floats)

  • [string]: accesses bodies by name

  • *actualConfig (list of floats)

  • *actualVelocity (list of floats)

  • *actualTorques (list of floats)

  • *config (an alias of actualConfig)

  • *velocity (an alias of actualVelocity)

  • *torques (an alias of actualTorques)

  • *links (list/dict of SimLinks)


  • # transform (se3 object (R,t))

  • # velocity (pair of 3D vectors w,v giving angular and translational velocity)


  • enabled (bool)

  • collisionPadding (float)

  • surface (ContactParameters)

  • # transform (se3 object (R,t))

  • # objectTransform (se3 object (R,t))

  • # velocity (pair of 3D vectors w,v giving angular and translational velocity)

  • # objectVelocity (pair of 3D vectors w,v giving angular and translational velocity)


  • *commandedConfig (list of floats)

  • *commandedVelocity (list of floats)

  • *sensedConfig (list of floats)

  • *sensedVelocity (list of floats)

  • *sensors (list/dict of SimRobotSensors)

dicts, lists, tuples: behave like normal

Other objects (e.g., ContactParameters, Mass, Geometry3D): must be operated with using the standard Klamp’t API.

klampt.model.access.get_item(obj, name)[source]

Given a attribute item like ‘robots[2].links[4].name’, evaluates the value of the item in the object.

Note: not secure! Uses eval()

klampt.model.access.set_item(obj, name, value)[source]

Given a config dict, sets the object’s configuration accordingly

Note: not secure! Uses exec

klampt.model.access.get_dict(world, items)[source]

Retrieves a dictionary of elements referred to by the given list of items.

Note: not secure! Uses eval()

klampt.model.access.set_dict(world, config)[source]

Sets the values in the dictionary config, which maps element names to values which should be set in the world.

Note: not secure! Uses exec

class klampt.model.access.Vectorizer(world, items)[source]

Bases: object

A class that retrieves named items in a world and places them into a flattened vector. Useful for planning.


Flattens the selected items in the world into a vector


Un-flattens the selected elements in the world from a vector