freecad_utils#

Attributes#

Functions#

vecFromFreeCAD(→ shim_types.np.ndarray)

poseFromPlacement(→ shim_types.SimpleHomTran)

combineInertiaProperties(→ tuple[float, ...)

Compute total mass, COM, and inertia about the body origin in a single pass.

inertiaMatrixFromFreeCAD(→ shim_types.np.ndarray)

Convert FreeCAD inertia matrix to numpy

shapeToMesh(→ shim_types.MeshData)

getRefBody(→ shim_types.Optional[FreeCAD.DocumentObject])

shouldParsePart(→ bool)

Check if an object should be parsed into a kdFlex sim.

parseBodies(→ tuple[dict[str, shim_types.BasicBody], ...)

parseJoints(→ tuple[list[str], dict[str, ...)

loadFreecadDoc(→ shim_types.BasicModelData)

loadFreecadFile(→ shim_types.BasicModelData)

main()

Module Contents#

freecad_utils.M_TO_MM = 1000.0#
freecad_utils.MM_TO_M = 0.001#
freecad_utils.DENSITY = 1000.0#
freecad_utils.vecFromFreeCAD(v: FreeCAD.Vector) shim_types.np.ndarray#
freecad_utils.poseFromPlacement(p: FreeCAD.Placement) shim_types.SimpleHomTran#
freecad_utils.combineInertiaProperties(body_frame_global: shim_types.SimpleHomTran, masses: list[float], centers_of_mass_global: list[shim_types.np.ndarray], inertia_matrices: list[shim_types.np.ndarray]) tuple[float, shim_types.np.ndarray, shim_types.np.ndarray]#

Compute total mass, COM, and inertia about the body origin in a single pass.

Parameters:
  • masses (list of float) – Masses of individual parts.

  • centers_of_mass_global (list of SimpleVec3) – COM positions of individual parts (relative to global origin).

  • inertia_matrices (list of np.ndarray) – 3x3 inertia matrices of each part about its own COM.

Returns:

  • total_mass (float)

  • total_com (SimpleVec3)

  • inertia_origin (np.ndarray) – 3x3 inertia matrix relative to body origin.

freecad_utils.inertiaMatrixFromFreeCAD(matrix) shim_types.np.ndarray#

Convert FreeCAD inertia matrix to numpy

freecad_utils.shapeToMesh(shape, body_to_origin: shim_types.SimpleHomTran) shim_types.MeshData#
freecad_utils.getRefBody(doc: FreeCAD.Document, reference) shim_types.Optional[FreeCAD.DocumentObject]#
freecad_utils.shouldParsePart(obj) bool#

Check if an object should be parsed into a kdFlex sim. This is nontrivial because an object can either be a reference for a true valid part, or a valid part itself.

We want to look for objects that are: 1. Inside an assembly and is an App::Link to a raw geometry. 2. Inside an assembly, is a Part::Feature, and isn’t linked to within the same assembly.

There are probably more cases that could arise in more complex situations, but this covers the basics.

Parameters:

obj – Description

freecad_utils.parseBodies(doc: FreeCAD.Document) tuple[dict[str, shim_types.BasicBody], dict[str, shim_types.Any]]#
freecad_utils.parseJoints(doc: FreeCAD.Document, bodies: dict[str, shim_types.BasicBody]) tuple[list[str], dict[str, shim_types.BasicJoint]]#
freecad_utils.loadFreecadDoc(doc: FreeCAD.Document) shim_types.BasicModelData#
freecad_utils.loadFreecadFile(filename: str) shim_types.BasicModelData#
freecad_utils.main()#