phobos.model package

Submodules

phobos.model.controllers module

phobos.model.controllers.createController(controller, reference, origin=Matrix(((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0))), annotations=None)

This function creates a new controller specified by its parameters.

If an annotation category or the keyword ‘all’ is specified, the respective annotations for the controller will be added as objects.

Parameters:
  • controller (dict) – phobos representation of the new controller
  • reference (bpy_types.Object) – object to add a parent relationship to
  • origin (mathutils.Matrix, optional) – new controllers origin (Default value = mathutils.Matrix())
  • annotations (list(str, optional) – list of annotation keys or ‘all’ to add to as annotation

objects (Default value = None)

Returns:bpy.types.Object – new created controller object
phobos.model.controllers.deriveController(obj)
Parameters:obj

Returns:

phobos.model.geometries module

phobos.model.geometries.createGeometry(viscol, geomsrc, linkobj=None)

Creates Blender object for visual or collision objects.

If the creation fails, nothing is returned.

These entries in the dictionary are mandatory:

geometry:
type: type of geometry (mesh, box, cylinder, sphere)

Depending on the geometry type other values are required: size, radius, length

These entries are optional:

geometry:
scale: scale for the new geometry
material: material name to assign to the visual
pose: specifies the placement of the new object relative to the optional linkobj
translation: position vector for the new object
rotation_euler: rotation for the new object

Furthermore any generic properties, prepended by a $ will be added as custom properties to the visual/collision object. E.g. $test/etc would be put to visual/test/etc for a visual object. However, these properties are extracted only in the first layer of hierarchy.

Parameters:
  • viscol (dict) – visual/collision model dictionary representation
  • geomsrc (str) – phobostype of the new object
  • linkobj (bpy.types.Object, optional) – link object to attach the visual/collision object to

(Default value = None)

Returns:the new geometry object or nothing
Return type:bpy.types.Object or None
phobos.model.geometries.deriveScale(obj)

Returns the scale of the specified object.

Object scale is gathered from the matrix_world, as the link scales in Blender might change the mesh scale, too.

Parameters:obj (bpy.types.Object) – object to derive the scale of
Returns:three scale floats (x, y, z) combined from all parents and the object itself
Return type:list
phobos.model.geometries.getLargestDimension(geometry)
Parameters:geometry

Returns:

phobos.model.inertia module

Contains all functions to model inertias within Blender.

phobos.model.inertia.calculateBoxInertia(mass, size)

Returns upper diagonal of inertia tensor of a box as tuple.

Parameters:
  • mass (float) – The box’ mass.
  • size (iterable) – The box’ size.
Returns:

tuple(6)

phobos.model.inertia.calculateCylinderInertia(mass, r, h)

Returns upper diagonal of inertia tensor of a cylinder as tuple.

Parameters:
  • mass (float) – The cylinders mass.
  • r (float) – The cylinders radius.
  • h (float) – The cylinders height.
Returns:

tuple(6)

phobos.model.inertia.calculateEllipsoidInertia(mass, size)

Returns upper diagonal of inertia tensor of an ellipsoid as tuple.

Parameters:
  • mass (float) – The ellipsoids mass.
  • size – The ellipsoids size.
Returns:

tuple(6)

phobos.model.inertia.calculateMeshInertia(mass, data)

Calculates and returns the inertia tensor of arbitrary mesh objects.

Implemented after the general idea of ‘Finding the Inertia Tensor of a 3D Solid Body, Simply and Quickly’ (2004) by Jonathan Blow (1) with formulas for tetrahedron inertia from ‘Explicit Exact Formulas for the 3-D Tetrahedron Inertia Tensor in Terms of its Vertex Coordinates’ (2004) by F. Tonon. (2)

Links: (1) http://number-none.com/blow/inertia/body_i.html
  1. http://docsdrive.com/pdfs/sciencepublications/jmssp/2005/8-11.pdf
Parameters:
  • data (bpy.types.BlendData) – mesh data of the object
  • mass (float) – mass of the object
Returns:

inertia tensor

Return type:

6

phobos.model.inertia.calculateSphereInertia(mass, r)

Returns upper diagonal of inertia tensor of a sphere as tuple.

Parameters:
  • mass (float) – The spheres mass.
  • r (float) – The spheres radius.
Returns:

tuple(6)

phobos.model.inertia.combine_com_3x3(objects)

Combines center of mass (COM) of a list of bodies given their masses and COMs. This code was adapted from an implementation generously provided by Bertold Bongardt.

Parameters:objects (list containing phobos dicts) – The list of objects you want to combine the COG.

Returns:

phobos.model.inertia.compound_inertia_analysis_3x3(objects)

Computes total mass, common center of mass and inertia matrix at CCOM

Parameters:objects

Returns:

phobos.model.inertia.fuse_inertia_data(inertials)

Computes combined mass, center of mass and inertia given a list of inertial objects. Computation based on Modern Robotics, Lynch & Park, p. 287 .

If no inertials are found (None, None, None) is returned.

If successful, the tuple contains this information:
mass: float com: mathutils.Vector(3) inertia: mathutils.Matrix(3)
Parameters:inertials (list) – the alist of objects relevant for the inertia of a link
Returns:tuple of mass, COM and inertia or None(3) if no inertials are found
Return type:3
phobos.model.inertia.gatherInertialChilds(obj, objectlist)

Gathers recursively all inertial object children from the specified object.

The inertia objects need to be in the specified objectlist to be encluded. Also, links which are not in the objectlist, will be considered, too. This will gather inertial objects which are child of a link not in the list.

Parameters:
  • obj (bpy.types.Object) – object to start the recursion (preferably a link)
  • objectlist (list(bpy.types.Object) – objects to consider for the recursion
Returns:

list(bpy.types.Object) – inertial objects which belong to the specified obj

phobos.model.inertia.inertiaListToMatrix(inertialist)

Transforms a list (upper diagonal of a 3x3 tensor) and returns a full tensor matrix.

Parameters:inertialist (tuple(6) – the upper diagonal of a 3x3 inertia tensor
Returns:mathutils.Matrix – full tensor matrix generated from the list
phobos.model.inertia.inertiaMatrixToList(im)

Takes a full 3x3 inertia tensor as a matrix and returns a tuple representing the upper diagonal.

Parameters:im (mathutil.Matrix) – The inertia tensor matrix.
Returns:tuple(6)
phobos.model.inertia.shift_com_inertia_3x3(mass, com, inertia_com, ref_point=Vector((0.0, 0.0, 0.0)))

Shifts the center of mass of a 3x3 inertia.

This code was adapted from an implementation generously provided by Bertold Bongardt.

TODO cleanup docstring

shift inertia matrix, steiner theorem / parallel axis theorem, private method

  • without changing the orientation -

see SCISIC B.12 or featherstone 2.63, but not Selig (sign swap, not COG)

c = COG - O
I_O = I_COG + m · c× (c× )T

changed the formula to (Wikipedia):
mathbf{J} = mathbf{I} + m left[left(mathbf{R} cdot mathbf{R}right)
mathbf{E}_{3} - mathbf{R} otimes mathbf{R} right],

This was necessary as previous calculations founded on math libraries of cad2sim.

Parameters:
  • mass
  • com
  • inertia_com
  • ref_point – (Default value = mathutils.Vector((0.0)
  • * 3) ()) –

Returns:

phobos.model.inertia.spin_inertia_3x3(inertia_3x3, rotmat, passive=True)

Rotates an inertia matrix.

active and passive interpretation

passive
the object stands still but the inertia is expressed with respect to a rotated reference frame
active
object moves and therefore its inertia

consistent with 6x6 method :

active
consistent with N’ = (H^T)^{-1} * N * H^{-1}
passive
consistent with N’ = (H^T) * N * H

WHERE IS a COMBINED METHOD of shifted and rotated inertia ? does it exist ?

Parameters:
  • inertia_3x3
  • rotmat
  • passive – (Default value = True)

Returns:

phobos.model.joints module

Contains the functions required to model a joint within Blender.

phobos.model.joints.createJoint(joint, linkobj=None, links=None)

Adds joint data to a link object.

If the linkobj is not specified, it is derived from the child entry in the joint (object is searched in the current scene). This only works if the search for the child yields a single object. Alternatively, it is possible to provide the model dictionary of links. In this case, the link object is searched in the dictionary (make sure the object keys of the dictionary are set properly).

These entries are mandatory for the dictionary:

name: name of the joint

These entries are optional:

axis: tuple which specifies the axis of the editbone
limits: limits of the joint movement
lower: lower limit (defaults to 0.)
upper: upper limit (defaults to 0.)
effort: maximum effort for the joint
velocity: maximum velocity for the joint

Furthermore any generic properties, prepended by a $ will be added as custom properties to the joint. E.g. $test/etc would be put to joint/test/etc. However, these properties are extracted only in the first layer of hierarchy.

Parameters:
  • joint (dict) – dictionary containing the joint definition
  • linkobj (bpy.types.Object, optional) – link object receiving joint (Default value = None)
  • links (dict, optional) – model dictionary of links (Default value = None)
Returns:

None

Return type:

None

phobos.model.joints.deriveJointState(joint)

Calculates the state of a joint from the state of the link armature. Note that this is the current state and not the zero state.

Parameters:joint (bpy_types.Object) – The joint(armature) to derive its state from.
Returns:dict
phobos.model.joints.getJointConstraint(joint, ctype)

Returns the constraints of a given joint.

Parameters:
  • joint (bpy_types.Object) – the joint in question
  • ctype – constraint type to retrieve

Returns:

phobos.model.joints.getJointConstraints(joint)

Returns the constraints defined in the joint as tuple of two lists.

Parameters:joint (bpy_types.Object) – The joint you want to get the constraints from
Returns:tuple – lists containing axis and limit data
phobos.model.joints.getJointType(joint)
Parameters:joint

Returns:

phobos.model.joints.setJointConstraints(joint, jointtype, lower=0.0, upper=0.0, spring=0.0, damping=0.0, maxeffort_approximation=None, maxspeed_approximation=None)

Sets the constraints for a given joint and jointtype.

If the joint type is not recognized, the constraints will match a floating joint.

The approximation for maximum effort/speed requires a dictionary with two entries (function coefficients).

Based on the joint type, the respective resource object is applied to the link.

Parameters:
  • joint (bpy_types.Object) – link object containing the joint to be edited
  • jointtype (str) – joint type (revolute, continuous, prismatic, fixed, floating, planar)
  • lower (float, optional) – lower limit of the constraint (defaults to 0.)
  • upper (float, optional) – upper limit of the constraint (defaults to 0.)
  • spring (float, optional) – spring stiffness for the joint (Default value = 0.0)
  • damping (float, optional) – spring damping for the joint (Default value = 0.0)
  • maxeffort_approximation (dict, optional) – function and coefficients for maximum effort (Default value = None)
  • maxspeed_approximation (dict, optional) – function and coefficients for maximum speed (Default value = None)

Returns:

phobos.model.joints.set_continuous(joint)
Parameters:joint

Returns:

phobos.model.joints.set_fixed(joint)
Parameters:joint

Returns:

phobos.model.joints.set_planar(joint)
Parameters:joint

Returns:

phobos.model.joints.set_prismatic(joint, lower, upper)
Parameters:
  • joint
  • lower
  • upper

Returns:

phobos.model.joints.set_revolute(joint, lower, upper)
Parameters:
  • joint
  • lower
  • upper

Returns:

phobos.model.lights module

phobos.model.lights.addLight(light_dict)
Parameters:light_dict

Returns:

phobos.model.materials module

Contains the functions required to model a material in Blender.

phobos.model.materials.assignMaterial(obj, materialname)

Assigns a material by name to an object.

This avoids creating multiple copies and also omits duplicate material slots in the specified object.

Parameters:
  • obj (bpy.types.Object) – The object to assign the material to.
  • materialname (str) – name of the material

Returns:

phobos.model.materials.createPhobosMaterials()

Creates a list of standard materials used in Phobos.

phobos.model.models module

phobos.model.models.buildModelFromDictionary(model)

Creates the Blender representation of the imported model, using a model dictionary.

Parameters:model (dict) – model representation of the imported model

Returns:

phobos.model.models.collectMaterials(objectlist)

Returns a dictionary of materials contained in a list of objects.

Only visual objects are considered and the dict keys represent the material names.

If a material is used by multiple objects, the user count is increased by one.

Parameters:objectlist (list) – list of objects to derive dictionary from
Returns:dict – dictionary of materials
phobos.model.models.createChain(group)
Parameters:group

Returns:

phobos.model.models.createGroup(group)
Parameters:group

Returns:

phobos.model.models.deriveAnnotation(obj)

Derives the annotation info of an object.

Parameters:obj – TODO

Returns:

phobos.model.models.deriveApproxsphere(obj)

This function derives an SRDF approximation sphere from a given blender object

Parameters:obj (bpy_types.Object) – The blender object to derive the approxsphere from.
Returns:tuple
phobos.model.models.deriveChainEntry(obj)

Derives a phobos dict entry for a kinematic chain ending in the provided object.

Parameters:obj – return:

Returns:

phobos.model.models.deriveCollision(obj)

Returns the collision information from the specified object.

Parameters:obj (bpy.types.Object) – object to derive the collision information from
Returns:dict – phobos representation of the collision object
phobos.model.models.deriveDictEntry(obj, names=False, objectlist=[], logging=True, adjust=True)

Derives a phobos dictionary entry from the provided object.

Parameters:
  • obj (bpy_types.Object) – The object to derive the dict entry (phobos data structure) from.
  • names (bool, optional) – use object names as dict entries instead of object links. (Default value = False)
  • logging (bool, optional) – whether to log messages or not (Default value = True)
  • objectlist – (Default value = [])
  • adjust – (Default value = True)
Returns:

dict – phobos representation of the object

phobos.model.models.deriveGroupEntry(group)

Derives a list of phobos link skeletons for a provided group object.

Parameters:group (bpy_types.Group) – The blender group to extract the links from.
Returns:list
phobos.model.models.deriveLight(obj)

This function derives a light from a given blender object

Parameters:obj (bpy_types.Object) – The blender object to derive the light from.
Returns:tuple
phobos.model.models.deriveModelDictionary(root, name='', objectlist=[])

Returns a dictionary representation of a Phobos model.

If name is not specified, it overrides the modelname in the root. If the modelname is not defined at all, ‘unnamed’ will be used instead.

Parameters:
  • root (bpy_types.Object) – root object of the model
  • name (str, optional) – name for the derived model (Default value = ‘’)
  • objectlist(list – bpy_types.Object): objects to derive the model from
  • objectlist – (Default value = [])

Returns:

phobos.model.models.deriveTextData(modelname)

Collect additional data stored for a specific model.

Parameters:modelname – Name of the model for which data should be derived.
Returns:A dictionary containing additional data.
phobos.model.models.filterExportData(data, phobostype=None, exportformart=None)

Collect the information to be exported from a general subdictionary of the model.

Parameters:
  • data (dict) – Subdictionary containing unfiltered information
  • phobostype (str, optional) – Contains the phobostype of the data, should be motors, sensors or controllers (Default value = None)
  • exportformat (str) – Format to filter information for, e.g. sdf or mars
  • exportformart – (Default value = None)
Returns:

Filtered dictionary

Return type:

dict

phobos.model.models.gatherAnnotations(model)

Gathers custom properties annotating elements of the robot across the model. These annotations were created in the model.py module and are marked with a leading ‘$’.

Parameters:
  • model (dict) – The robot model dictionary.
  • ignore_keys (list) – Ignored annotation categories (Default value = [])
Returns:

dict – A dictionary of the gathered annotations.

Returns the full link information including joint and motor data from a blender object.

The link information is derived according to derive_link().

Parameters:linkobj (bpy.types.Object) – blender object to derive the link from
Returns:link representation of the object
Return type:dict
phobos.model.models.initObjectProperties(obj, phobostype=None, ignoretypes=(), includeannotations=True, ignorename=False)

Initializes phobos dictionary of obj, including information stored in custom properties.

Parameters:
  • obj (bpy_types.Object) – object to derive initial properties from.
  • phobostype (str, optional) – limit parsing of data fields to this phobostype (Default value = None)
  • ignoretypes (list, optional) – list of properties ignored while initializing the objects properties. (Default value = ())
  • ignorename (bool, optional) – whether or not to add the object’s name (Default value = False)
  • includeannotations – (Default value = True)
Returns:

dict – phobos properties of the object

phobos.model.models.namespaceJoint(joint, namespace)
Parameters:
  • joint
  • namespace

Returns:

Parameters:
  • link
  • namespace

Returns:

phobos.model.models.namespaceMotor(motor, namespace)
Parameters:
  • motor
  • namespace

Returns:

phobos.model.models.namespaced(name, namespace)
Parameters:
  • name
  • namespace

Returns:

phobos.model.models.recursive_dictionary_cleanup(dictionary)

Recursively enrich the dictionary and replace object links with names etc.

These patterns are replaced:
[phobostype, bpyobj] -> {‘object’: bpyobj, ‘name’: getObjectName(bpyobj, phobostype)}
Parameters:dictionary (dict) – dictionary to enrich
Returns:dict – dictionary with replace/enriched patterns

Replaces object links in a dictionary with object names.

This is required for generic parsed object definitions, as object links are represented by a simple dictionary with name and object.

For most exports, this can be run prior export parsing, to create the respective name linking within the model.

Parameters:dictionary (dict) – model dictionary (or similar) to replace object links in
Returns:dict – model dictionary with name linking instead of object links

phobos.model.motors module

phobos.model.motors.createMotor(motor, parentobj, origin=Matrix(((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0))), addcontrollers=False)

This function creates a new motor specified by its parameters.

If addcontrollers is set, a controller object will be created from the controller definition which is specified in the motor dictionary (key controller).

Parameters:
  • motor (dict) – phobos representation of the new motor.
  • parentobj (bpy_types.Object) – object to parent new motor to
  • origin (mathutils.Matrix, optional) – new motors origin (Default value = mathutils.Matrix())
  • addcontrollers (bool, optional) – whether to add the defined controller as object (Default value = False)
Returns:

new motor object or a list of the new motor_object and the new controller object

Return type:

bpy.types.Object

phobos.model.motors.deriveMotor(obj, jointdict=None)

Derives motor information from an object.

Parameters:
  • obj (bpy_types.Object) – Blender object to derive the motor from
  • jointdict (dict, optional) – phobos representation of the respective joint (Default value = None)
Returns:

dict – phobos representation of a motor

phobos.model.poses module

Contains all functions to model poses in Blender.

phobos.model.poses.bakeModel(objlist, modelname, posename='', decimate_type='COLLAPSE', decimate_parameter=0.1)

This function gets a list of objects and creates a single, simplified mesh from it and exports it to .stl.

Parameters:
  • objlist(list – list): The list of blender objects to join and export as simplified stl file.
  • modelname (str) – The new models name and filename.
  • posename – (Default value = “”)
  • decimate_type – (Default value = ‘COLLAPSE’)
  • decimate_parameter – (Default value = 0.1)
  • objlist

Returns:

phobos.model.poses.getPoses(modelname)

Get the names of the poses that have been stored for a robot.

Parameters:modelname – The model’s name.
Returns:A list containing the poses’ names.
phobos.model.poses.loadPose(modelname, posename)

Load and apply a robot’s stored pose.

Parameters:
  • modelname (str) – the model’s name
  • posename (str) – the name the pose is stored under

Returns:

phobos.model.poses.storePose(root, posename)

Stores the current pose of all of a model’s selected joints.

Existing poses of the same name will be overwritten.

Parameters:
  • root (bpy_types.Object) – root of the model the pose belongs to
  • posename (str) – name the pose will be stored under
Returns:

Nothing.

phobos.model.sensors module

phobos.model.sensors.cameraRotLock(object)

DOCU: PLEASE ADD PYDOC. What should this do exactly?

Parameters:object (bpy_types.Object) – The object to lock the rotation for

Returns:

phobos.model.sensors.createSensor(sensor, reference, origin=Matrix(((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0))))

This function creates a new sensor specified by its parameters.

The sensor dictionary has to contain these keys:
name: name of the new sensor type: type specifier of the sensor shape: a shape specifier for the sensor props: custom properties to be written to the sensor object
Parameters:
  • sensor (dict) – phobos representation of the new sensor
  • reference (bpy_types.Object) – object to add a parent relationship to
  • origin (mathutils.Matrix, optional) – new sensors origin (Default value = mathutils.Matrix())
Returns:

The newly created sensor object

phobos.model.sensors.deriveSensor(obj, names=False, objectlist=[], logging=False)

This function derives a sensor from a given blender object

Parameters:
  • obj (bpy_types.Object) – The blender object to derive the sensor from.
  • names (bool, optional) – return the l object name instead of an object link. (Default value = False)
  • objectlist (list(bpy.types.Object, optional) – objectlist to which possible parents are restricted (Default value = [])
  • logging (bool, optional) – whether to write log messages or not (Default value = False)
Returns:

dict – phobos representation of the sensor

Module contents