Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SoftRobotics/StepByStep-introduction/0-basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ def createScene(rootNode):
rootNode.dt = 0.01 # Time step
rootNode.gravity = [ 0., 0. ,0.] # Gravitational acceleration applied on the entire scene

rootNode.addObject("DefaultAnimationLoop", name="animation loop")
rootNode.addObject("DefaultAnimationLoop", name="animation_loop")

rootNode.addChild("MyObject", bbox=[0,0,0,1,1,1]) # bbox is only needed here to define a non-zero simulation space since the scene is empty
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ def generateRadius(self):
def generatXPos(self):
return self.iteration%11 * 10 -170

def updateCollisionPipeline(self):
self.rootNode.removeObject(self.rootNode.collision_pipeline)
self.rootNode.addObject("CollisionPipeline", name="collision_pipeline")
self.rootNode.collision_pipeline.init()

def addFallingParticle(self, node):
iteration_loc = self.iteration
newParticle = node.addChild("ParticleToCollideWith-"+str(iteration_loc))
newParticle.addObject("EulerImplicitSolver")
newParticle.addObject("CGLinearSolver", iterations=200, tolerance=1e-09, threshold=1e-09)
newParticle.addObject("SparseLDLSolver", name="linear_solver", template="CompressedRowSparseMatrixMat3x3d")
newParticle.addObject("MechanicalObject", template="Rigid3", name="myParticle", position=[self.generatXPos(), 80, 0, 0,0,0,1], showObject=True)
newParticle.addObject("UniformMass", totalMass=1)
newParticle.addObject("ConstantForceField", totalForce=[0,-50,0,0,0,0], indices=0)
newParticle.addObject("SphereCollisionModel", radius=self.generateRadius(), contactStiffness=100)
newParticle.init()
self.iteration = iteration_loc +1
self.updateCollisionPipeline()

def removeFallingParticle(self, node):
iteration_loc = self.iteration - 1
Expand All @@ -41,6 +47,7 @@ def removeFallingParticle(self, node):

myParticleNode = self.rootNode.removeChild(str(name))
self.iteration = iteration_loc
self.updateCollisionPipeline()

def onKeypressedEvent(self, event):
key = event["key"]
Expand Down
37 changes: 37 additions & 0 deletions SoftRobotics/StepByStep-introduction/6-elastic-finger-units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def createScene(rootNode):

from Sofa.Units.Definitions import s, m, mm, N, g, kg, Pa
from Sofa.Units.UnitSystem import MechanicalUnitSystem

scene_unit = MechanicalUnitSystem(s, m, kg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure about these units ? The mesh is in m ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point I forgot to check .. :)


rootNode.name = "RootNode"
rootNode.dt = scene_unit(0.01, s)
rootNode.gravity = [0, scene_unit(-9.81, N/kg), 0] # Defining gravity along -Y

rootNode.addObject("DefaultAnimationLoop", name="animation_loop", computeBoundingBox=False)

rootNode.addObject("RequiredPlugin", pluginName=["Sofa.Component.StateContainer","Sofa.Component.Mass","Sofa.Component.MechanicalLoad",
"Sofa.Component.LinearSolver.Direct","Sofa.Component.ODESolver.Backward",
"Sofa.Component.IO.Mesh","Sofa.Component.Topology.Container.Dynamic",
"Sofa.Component.SolidMechanics.FEM.Elastic","Sofa.Component.Topology.Container.Constant",
"Sofa.Component.Visual"])
rootNode.addObject("VisualStyle", name="visual_options", displayFlags="showForceFields")

rootNode.addObject("MeshVTKLoader", name="mesh_loader_coarse", filename="../PneuNets_remeshed.vtk") # Using a VTK file format, thus using MeshVTKLoader

################################################
# Mechanical representation of the finger object
mechanicalModel = rootNode.addChild("Finger")

mechanicalModel.addObject("EulerImplicitSolver", name="integration_scheme")
mechanicalModel.addObject("SparseLDLSolver", name="linear_solver", template="CompressedRowSparseMatrixMat3x3d")

# MeshTopology is a static topology container, i.e. it does not support topology changes (unlike TetrahedronSetTopologyContainer)
mechanicalModel.addObject("MeshTopology", name="topology_container", src="@../mesh_loader_coarse" )

mechanicalModel.addObject("MechanicalObject", template="Vec3", name="state_container", showObject=True) # Define the template as Vec3 for 3D deformable bodies

mechanicalModel.addObject("TetrahedronFEMForceField", name="elastic_material_law", template="Vec3", poissonRatio=0.3, youngModulus=scene_unit(100, Pa)) # Define an elastic constitutive law
mechanicalModel.addObject("MeshMatrixMass", name="mass", template="Vec3,Vec3", totalMass=scene_unit(500, g)) # Use a mass integrated over the volume
################################################