def createScene(rootNode): from stlib.scene import MainHeader from stlib.physics.rigid import Floor MainHeader(rootNode, plugins=["SofaPython"], dt=1., gravity=[0., -9810., 0.]) rootNode.VisualStyle.displayFlags = "showVisual showBehavior" floor = Floor(rootNode, name="Plane", color=[1., 0., 1.], isAStaticObject=True, uniformScale=10) addOrientedBoxRoi(floor, name="MyBoxRoi", position=[[50, 0, 0], [15, 15, 0], [60, 70, 25]], scale=[100, 100, 100]) myOrientedBox = getOrientedBoxFromTransform(translation=[400, 100, 100], eulerRotation=[0, 65, 0], scale=[400, 400, 800]) floor.createObject("BoxROI", orientedBox=myOrientedBox, drawBoxes=True)
def createScene(rootNode): MainHeader(rootNode, gravity=[0.0, -981.0, 0.0]) ContactHeader(rootNode, alarmDistance=8, contactDistance=5) ShowGrid(rootNode) Floor(rootNode, translation=[0.0, -160.0, 0.0], uniformScale=5.0, isAStaticObject=True) Floor(rootNode, name="FloorObstacle", translation=[0.0, -80.0, 0.0], color=[0.0, 1.0, 0.0], uniformScale=0.8, isAStaticObject=True) for c in range(7): Cube(rootNode, name="Cube" + str(-210 + c * 70), translation=[-210 + c * 70, 0.0, 0.0], color=[c / 10.0, c * 0.7 / 10.0, 0.9], uniformScale=20.0) return rootNode
def createScene(rootNode): from stlib.scene import MainHeader from stlib.scene import ContactHeader from stlib.physics.rigid import Floor rootNode.createObject('RequiredPlugin', pluginName='SoftRobots'); rootNode.createObject('RequiredPlugin', pluginName='ModelOrderReduction'); rootNode.createObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe'); rootNode.findData('dt').value= 0.01; rootNode.findData('gravity').value= [0, -9810, 0] rootNode.createObject('FreeMotionAnimationLoop'); rootNode.createObject('LCPConstraintSolver', mu=str(1), tolerance="1.0e-15", maxIt="10000"); rootNode.createObject('CollisionPipeline', verbose="0"); rootNode.createObject('BruteForceDetection', name="N2"); rootNode.createObject('CollisionResponse', response="FrictionContact"); rootNode.createObject('LocalMinDistance', name="Proximity", alarmDistance=10, contactDistance=1.5); Floor(rootNode, name = "Plane", translation=[0,-30 ,0], color = [1.0, 0.0, 1.0], isAStaticObject = True, uniformScale = 10) # With reduce legs SofiaSixLegs(attachedTo=rootNode, name='sofia_reduced', reduced=True, rotation=[0,0,0], translation=[-200, 0, -400])
def createScene(rootNode): MainHeader(rootNode, plugins=["SofaPython", "SoftRobots", "ModelOrderReduction"], dt=0.01, gravity=[0, -9810, 0], displayFlags='showVisualModels') rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('LCPConstraintSolver', mu=str(1), tolerance="1.0e-15", maxIt="10000") rootNode.createObject('CollisionPipeline', verbose="0") rootNode.createObject('BruteForceDetection', name="N2") rootNode.createObject('CollisionResponse', response="FrictionContact") rootNode.createObject('LocalMinDistance', name="Proximity", alarmDistance=10, contactDistance=1.5) rootNode.createObject('SparseLDLSolver', name='preconditioner') Floor(rootNode, name="Plane", translation=[0, -30, 0], color=[1.0, 0.0, 1.0], isAStaticObject=True, uniformScale=10) # With reduce legs SofiaSixLegs(attachedTo=rootNode, name='sofia_reduced', reduced=True, rotation=[0, 0, 0], translation=[-200, 0, -400])
def createScene(rootNode): """Setting up a simple scene""" MainHeader(rootNode, gravity=[0.0, -981.0, 0.0]) ContactHeader(rootNode, alarmDistance=5, contactDistance=1) Cube(rootNode, translation=[0.0, 60.0, 10.0], uniformScale=2.0) Floor(rootNode, translation=[0.0, -160.0, 0.0], isAStaticObject=True) Prostate = ElasticMaterialObject( rootNode, name="Prostate", volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.msh", surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl", collisionMesh="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl", withConstrain=True, surfaceColor=[0.0, 0.70, 1.0], scale=[0.9, 0.9, 0.9], poissonRatio=0.49, youngModulus=500, translation=[10.0, 0.0, 0.0]) # Bulbo = ElasticMaterialObject(rootNode, name="Bulbo", # volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_16_16.msh", # surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_16_16.stl", # collisionMesh = "/Users/pedro/Downloads/mac/Data/Prosta_16_16.stl", # withConstrain=True, # surfaceColor=[0.2, 0.9, 0.0], # scale=[0.9, 0.9, 0.9], # poissonRatio=0.49, # youngModulus=90000, # translation=[0.0,60.0,35.0]) fixingBox = [0.0, 0.0, 0.0] BoxROICoordinates = [-5, 0, -5, 5, 1, 5] FixedBox(Prostate, atPositions=[-10.0, -1.0, -20.0, 60.0, 60.0, 5.0], doVisualization=True) # scene = Scene(rootNode, gravity=[0.0, -981.0, 0.0]) # scene.dt = 0.025 # scene.VisualStyle.displayFlags = "showBehavior" # # scene.Config.createObject("MeshSTLLoader", name="loader", filename="/Users/pedro/Downloads/mac/SOFA_v19.06.99_custom_MacOS_v11/plugins/SoftRobots/docs/tutorials/Tripod/details/data/mesh/blueprint.stl") # scene.Config.createObject("OglModel", src="@loader") # body = ElasticBody(scene.Modelling) # fix = FixingBox(scene.Modelling, # body.ElasticMaterialObject, # eulerRotation=[0,0,0], # translation=[0.0, .0, 0.0], # scale=[30., 30., 30.]) # # # Changing the property of the Box ROI so that the constraint area appears on screen. # fix.BoxROI.drawBoxes = True # return rootNode
def createScene(rootNode): MainHeader(rootNode, plugins=['SofaPython', 'SoftRobots', 'SofaOpenglVisual'], gravity=[0.0, -9810, 0.0]) ContactHeader(rootNode, alarmDistance=5, contactDistance=1, frictionCoef=0.7) GripperController(rootNode) Floor(rootNode, **floorParam) Cube(rootNode, **cubeParam) # Put treshold in rigibObject construction param ? rootNode.Cube.Solver.threshold = 1e-6 for i in range(len(fingersParameters)): finger = ElasticMaterialObject( attachedTo=rootNode, volumeMeshFileName=fingersVolumeMesh, name=fingersParameters[i]['name'], rotation=fingersParameters[i]['rotation'], translation=fingersParameters[i]['translation'], surfaceMeshFileName=fingersSurfaceAndCollisionMesh, collisionMesh=fingersSurfaceAndCollisionMesh, withConstrain=True, surfaceColor=fingersColor, poissonRatio=poissonRatioFingers, youngModulus=youngModulusFingers, totalMass=fingersMass) finger.integration.rayleighStiffness = 0.1 finger.integration.rayleighMass = 0.1 finger.createObject('BoxROI', name='boxROI', box=fingersParameters[i]['ROIBox'], drawBoxes=True, doUpdate=False) finger.createObject('RestShapeSpringsForceField', points='@../finger1/boxROI.indices', stiffness=1e12, angularStiffness=1e12) PneumaticCavity(surfaceMeshFileName=fingersCavitySurfaceMesh, attachedAsAChildOf=finger, name='cavity', rotation=fingersParameters[i]['rotation'], translation=fingersParameters[i]['translation'], initialValue=cavitiesInitialValue, valueType='pressure')
def createScene(rootNode): """This is my first scene""" MainHeader(rootNode, gravity=[0.0, -981.0, 0.0]) ContactHeader(rootNode, alarmDistance=15, contactDistance=10) #ShowGrid(rootNode) Floor(rootNode, translation=[0.0, -160.0, 0.0], isAStaticObject=True) Cube(rootNode, translation=[0.0, 0.0, 0.0], uniformScale=20.0) return rootNode
def createScene(rootNode): """Setting up a simple scene""" MainHeader(rootNode, gravity=[0.0, -981.0, 0.0]) ContactHeader(rootNode, alarmDistance=15, contactDistance=5) Cube(rootNode, translation=[0.0, 60.0, 10.0], rotation=[0.0, 60.0, 10.0], uniformScale=20.0) Floor(rootNode, translation=[0.0, -160.0, 0.0], isAStaticObject=True) return rootNode
def createScene(rootNode): from stlib.scene import MainHeader from stlib.physics.rigid import Floor MainHeader(rootNode, plugins=["SofaPython", "SoftRobots", "ModelOrderReduction"], dt=1, gravity=[0.0, -9810, 0.0]) floor = Floor(rootNode, name="Plane", color=[1.0, 0.0, 1.0], isAStaticObject=True, uniformScale=10) addOrientedBoxRoi(floor, name="MyBoxRoi", position=[[50, 0, 0], [15, 15, 0], [60, 70, 25]], scale=[100, 100, 100]) myOrientedBox = getOrientedBoxFromTransform(translation=[400, 100, 100], eulerRotation=[0, 65, 0], scale=[400, 400, 800]) floor.createObject("BoxROI", orientedBox=myOrientedBox, drawBoxes=True)
def createScene(rootNode): """Setting up a simple scene""" MainHeader(rootNode, gravity = [0.0, -981.0, 0.0]) ContactHeader(rootNode, alarmDistance = 5, contactDistance = 1) #cube(rootNode, translation = [10.1,60.0,10.0], uniformScale = 1.0) Floor(rootNode, translation = [0.0,-160.0,0.0], isAStaticObject = True) Prostate = ElasticMaterialObject(rootNode, name="Prostate", volumeMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.msh", surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl", collisionMesh = "/Users/pedro/Downloads/mac/Data/Prosta_2_2.stl", withConstrain=True, surfaceColor=[0.0, 0.70, 1.0], scale=[0.9, 0.9, 0.9], poissonRatio=0.49, youngModulus=500, translation=[10.0,0.0,0.0]) Bulbo = ElasticMaterialObject(rootNode, name="Bulbo", volumeMeshFileName="/Users/pedro/Downloads/mac/Data/needle_s.msh", surfaceMeshFileName="/Users/pedro/Downloads/mac/Data/needle_s.stl", collisionMesh = "/Users/pedro/Downloads/mac/Data/needle_s.stl", withConstrain=True, surfaceColor=[0.2, 0.9, 0.0], scale=[0.9, 0.9, 0.9], poissonRatio=0.33, youngModulus=100000, translation=[0.0,160.0,60.0], rotation=[90.0,0.0,0.0]) fixingBox=[0.0,0.0,0.0] BoxROICoordinates=[-5, 0, -5, 5, 1, 5] FixedBox(Prostate, atPositions=[-10.0,-1.0,-20.0,60.0,60.0,5.0], doVisualization=True) # fixingBox=[0.0,0.0,0.0] # BoxROICoordinates=[-5, 0, -5, 5, 1, 5] # PartiallyFixedBox(attachedTo=Bulbo, fixedAxis=[1, 0,1], box=[-10.0,140.0,-20.0,10.0,170.0,25.0], drawBoxes = True ) return rootNode
def createScene(rootNode): surfaceMeshFileNameDiamond = 'surface.stl' surfaceMeshFileNameStrafish = 'quadriped_collision.stl' surfaceMeshFileNameSofia = 'sofia_leg.stl' MainHeader(rootNode, plugins=["SofaPython", "SoftRobots", "ModelOrderReduction"], dt=1, gravity=[0.0, -9810, 0.0]) ContactHeader(rootNode, alarmDistance=5, contactDistance=1, frictionCoef=0.7) Floor(rootNode, name="Plane", color=[1.0, 0.0, 1.0], isAStaticObject=True, uniformScale=10) Reduced_diamond(rootNode, name="Reduced_diamond_white", rotation=[-90, 0.0, 0.0], translation=[0, 50.0, 0.0], surfaceColor=[0.5, 0.5, 0.5, 0.5], surfaceMeshFileName=surfaceMeshFileNameDiamond) Reduced_starfish(rootNode, name="Reduced_starfish_red", rotation=[0, 90.0, 120.0], translation=[300, 400.0, 100.0], surfaceColor=[1, 0.0, 0.0, 0.5], surfaceMeshFileName=surfaceMeshFileNameStrafish) Reduced_SofiaLeg(rootNode, name="Reduced_sofiaLeg_blue", rotation=[0, 0.0, 0.0], translation=[-400, 60.0, 100.0], surfaceColor=[0.0, 0.0, 1, 0.5], surfaceMeshFileName=surfaceMeshFileNameSofia)
def createScene(rootNode): """This is my first scene""" MainHeader(rootNode, gravity=[0.0, -981.0, 0.0], plugins=["SoftRobots"]) ContactHeader(rootNode, alarmDistance=4, contactDistance=3, frictionCoef=0.08) Gripper(rootNode) Floor(rootNode, color=[1.0, 0.0, 0.0], translation=[0.0, -160.0, 0.0], isAStaticObject=True) Cube(rootNode, uniformScale=20.0, color=[1.0, 1.0, 0.0], totalMass=0.03, volume=20, inertiaMatrix=[1000.0, 0.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 1000.0], translation=[0.0, -130.0, 10.0]) return rootNode
def createScene(rootNode): """ Following the Defrost team of the INRIA Lille Nord Europe's tutorial. """ MainHeader(rootNode, gravity=[0.0, -981.0, 0.0]) # Collision Handling Built-in Function ContactHeader(rootNode, alarmDistance=10, contactDistance=5) cube = rootNode.createChild("Cube") # Mechanical Model totalMass = 5.0 volume = 5.0 inertiaMatrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] # DOF Mechanical Object cube.createObject('MechanicalObject', name="DOF", template="Rigid", translation=[0.0, 0.0, 0.0], rotation = [0.0, 0.0, 0.0]) # Uniform Mass Object cube.createObject('UniformMass', name="Mass", mass=[totalMass, volume, inertiaMatrix[:]]) # Time Integration Scheme cube.createObject('EulerImplicit', name="Odesolver") # Solving Method cube.createObject('CGLinearSolver', name="Solver") # Visual Object of Cube visual = cube.createChild("Cube Visual") # Visual Ogl Model visual.createObject('OglModel', name="Visual", fileMesh="mesh/smCube27.ob", colour=[0.1,0.1,1.0], scale=25.0) # Rigid Mapping Object visual.createObject('RigidMapping') # Collision Model for the Cube collision = cube.createChild("Cube Collision Model") # Creating Collision Objects collision.createObject('MeshObjLoader', name="Loader", filename="mesh/smCube27.obj", triangulate="true", scale=20.0) # Collision Objects: Mesh, Mechanical Object, Triangle, Line, Point, Rigid Mapping collision.createObject('Mesh', src="@loader") collision.createObject('MechanicalObject') collision.createObject('Triangle') collision.createObject('Line') collision.createObject('Point') collision.createObject('RigidMapping') # Floor in the Scene floor = Floor(rootNode, name="Floor", translation=[0.0, -3200.0, 0.0], uniformScale=7.0, isAStaticObject=True) return rootNode
def createScene(rootNode): from stlib.scene import MainHeader, ContactHeader #from stlib.physics.deformable import ElasticMaterialObject MainHeader(rootNode, plugins=["CosseratPlugin"], gravity=[0., 0., 0.]) # rootNode.createObject( # 'VisualStyle', displayFlags='showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields showWireframe') rootNode.createObject( 'VisualStyle', displayFlags='showVisualModels showInteractionForceFields') # rootNode.createObject('FreeMotionAnimationLoop') # rootNode.createObject('GenericConstraintSolver', tolerance="1e-20", maxIterations="5000", printLog="0") ContactHeader(rootNode, alarmDistance=4, contactDistance=3, frictionCoef=0.08) rootNode.gravity = "0 -981 0" rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765') rootNode.createObject('OglSceneFrame', style="Arrows", alignment="TopRight") cableNode = rootNode.createChild('cosseratNode') cableNode.createObject('EulerImplicitSolver', firstOrder="0", rayleighStiffness="1.0", rayleighMass='0.1') cableNode.createObject('SparseLUSolver', name='solver') cableNode.createObject('GenericConstraintCorrection') cosFinger1 = CosseratFinger( rootNode=rootNode, cableNode=cableNode, name="cosseratF1", rotation=[0., 0, -120.], translation=[-5., 70., 0.0], ) #trans = cosFinger1.trans cosFinger2 = CosseratFinger(rootNode=rootNode, cableNode=cableNode, name="cosseratF2", rotation=[180., 0, -60.], translation=[5., 70., 10.0]) cosFinger3 = CosseratFinger(rootNode=rootNode, cableNode=cableNode, name="cosseratF3", rotation=[180., 0, -60.], translation=[5., 70., -10.0]) GripperController(rootNode, fingers=[cosFinger1, cosFinger2, cosFinger3], angles=[[0., 0, -120.], [180., 0, -60.], [180., 0, -60.]]) Floor(rootNode, color=[1.0, 0.0, 0.0], translation=[0.0, -25.0, 0.0], rotation=[0.0, 0.0, 0.0], isAStaticObject=True) Cube( rootNode, uniformScale=20.0, color=[1.0, 1.0, 0.0], totalMass=0.03, volume=20, inertiaMatrix=[1000.0, 0.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 1000.0], rotation=[0.0, 0.0, 0.0], translation=[0.0, 0.0, 0.0], )
def createScene(rootNode): #Its helpful to be able to see the grid ShowGrid(rootNode) #Adding the Soft-Robotics Plugin and the SofaPython plugin rootNode.createObject('RequiredPlugin', name='soft', pluginName='SoftRobots') rootNode.createObject('RequiredPlugin', name='SofaPython', pluginName='SofaPython') rootNode.createObject('RequiredPlugin', name='SofaSparseSolver', pluginName='SofaSparseSolver') #Gravity is automatically defined but we can redefine it rootNode.findData('gravity').value='0 0 -981' #It is nice to have the useful visualizatioin visible upon reloading the scene #you can find the options in the view tab in the GUI rootNode.createObject('VisualStyle', displayFlags='showForceFields showBehaviorModels') #Add BackgroundSetting in order not to have to reset it to white everytime you reload rootNode.createObject('BackgroundSetting', color='1 1 1') #Add the axis in the upper right corner automatically rootNode.createObject('OglSceneFrame', style="Arrows", alignment="TopRight") #The standard Global Bounding Box is very small [-1,-1,-1,1,1,1] #in comparison to our object so we make it bigger rootNode.findData('bbox').value= '-200 -200 -200 200 200 200' #Let's add the Child node for the Mesh cube = rootNode.createChild('cube') #Adding the Mesh file and make sure it finds it in the location directed to cube.createObject('MeshVTKLoader', name='loader', filename= pa 'mesh_cube20.vtk') #Now let's load the Mehs and make it a MechObj, which stores and is set to show the degrees of freedom of our box cube.createObject('Mesh', src='@loader', name='container') cube.createObject('MechanicalObject', name='tetras', template='Vec3d', showObject='true') #Next we want to make the material soft so we add a forcefield #We use TetrahedronFEMForceField in this case because of the nature of our mesh #Here we also determine the Young's Modulus and Poisson's ratio for the material #method is related to either small or large displacements cube.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM', method='large', poissonRatio='0.49', youngModulus='200') #Next we want to add the mass, since we want to uniformly distribute it we can either use #vertexMass which is the mass at each node, stored in the MevhanicalObject #or totalMass which is the total mass, which is then spread over the nodes. #Beware these don't consider the geometry or topology of the system. More details, also on non-uniform masses: #https://www.sofa-framework.org/community/doc/using-sofa/components/masses/uniformmass/ cube.createObject('UniformMass', totalMass='0.01') #For initial try I will add a boundary condition for the bottom of the box #This will fix the box in place if I set the stifness of the springs rather high #As it creates springs between its initial and current position #In this case I placed the box in the xy-plane going from 0-100 and up to 10 along the z-axis #cube.createObject('BoxROI', name='boxROI', box='0 100 0 100 0 10', drawBoxes=True) #cube.createObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness='1e12', angularStiffness='1e12') #Now we add a time integration scene, allowing the system to be computed at each time step #We will use the EulerImplicit solver where the forces are based off of #the information of the next time step. Although being slower than the Explicit solver, #they are more stable and are needed for stiff differential equations cube.createObject('EulerImplicit', name='odesolver') #And following that we add a Matrix solver, this one is a direct solver based off of A=LDL^T #This one can be slow for very large systems but gives exact solutions cube.createObject('SparseLDLSolver', name='directSolver') #At this point it will deform a bit under gravity but not involve other dynamics #Lets add the pneumatic actuators #First let's create the cavity add the mesh and load it cavity = cube.createChild('cavity') cavity.createObject('MeshSTLLoader', name='loader', filename='mesh_cavity20.stl') cavity.createObject('Mesh', src='@loader', name='topo') #Now we must make the MechanicalObject of the surface mesh to store the degrees of freedom #along the surface that will cause deformations cavity.createObject('MechanicalObject', name='cavity') #Now we will add a SurfacePressureConstraint #This adds a constant pressure on a surface #Such that each point of the mesh receives the pressure of the elements it is a part of #You need to specify: #are you using triangles or quads #value #valueIndex (default is {0}) #valueType; pressure or volumeGrowth #For more info: https://project.inria.fr/softrobot/documentation/constraint/surface-pressure-constraint/ cavity.createObject('SurfacePressureConstraint', name='SurfacePressureConstraint', template='Vec3d', value='0.0001', triangles='@topo.triangles', valueType='pressure') #Now we need to use a BarycentricMapping to map the deformation of the cavity onto our 3d Mesh cavity.createObject('BarycentricMapping', name='mapping') #Now as a first test we will use the prewritten controller program which uses +/- to inflate and deflate rootNode.createObject('PythonScriptController', filename='oscillationController.py', classname="controller") #Now we will add an animationloop, the easiest is to add the FreeMotionAnimationLoop rootNode.createObject('FreeMotionAnimationLoop') #Furthermore we will add to solvers to take various constraints into account rootNode.createObject('GenericConstraintSolver', maxIterations='10000', tolerance='1e-3') cube.createObject('LinearSolverConstraintCorrection', solverName='directSolver') #Let's add a visual model for the vube visualCube = cube.createChild('visualCube') visualCube.createObject('MeshSTLLoader', name='loader', filename='mesh_cube20.stl') visualCube.createObject('OglModel', src='@loader', template='ExtVec3d', color='0.4 0.9 0.9') visualCube.createObject('BarycentricMapping') #In order to visualize and export the scene we can use the monitor component #This is added to an indice of the component it is directly monitoring #cube.createObject('Monitor', name="monitor-39", indices="178 228 278 303 253 203", template="Vec3d", # showPositions=True, PositionsColor="1 0 1 1", ExportPositions=False, # showVelocities=True, VelocitiesColor="0.5 0.5 1 1", ExportVelocities=False, # showForces=True, ForcesColor="0.8 0.2 0.2 1", ExportForces=False, # showTrajectories=False, TrajectoriesPrecision="0.1", TrajectoriesColor="0 1 1 1", sizeFactor="0.5") #Now let's add a floor on which the cube will rest. We will use a rigid, preset floor from SOFA for the floor #It is a preset with preset totalMass=1.0 and totalVolume=1.0. We will set it to be static. #Furthermore it already includes its own collisionmodel. #This includes the Mesh of the outer surface of the floor, A mapping between this mesh and that of the volume mesh of the floor #and it tells all triangles, lines and points how to interact upon collision. (By not moving) Floor(rootNode, translation=[0.0, 0.0, 0.0], rotation=[90.0, 0.0, 0.0], isAStaticObject=True, uniformScale=8.0) #Now let's add the collisionmodel to the cube collisionCube = cube.createChild("collisionCube") #First we will load and store the surface mesh of the cube, and turn it into a mechanicalObject #You could think about the translation of this object when wanting to add more cubes but for now it is not necessary collisionCube.createObject('MeshSTLLoader', name='loader', filename='mesh_cube20.stl') collisionCube.createObject('Mesh', src='@loader', name='topo') collisionCube.createObject('MechanicalObject', name='collisMech') #Now we add the behavior for the triangles, lines and points for the collision mesh collisionCube.createObject('Triangle', selfCollision=False) collisionCube.createObject('Line', selfCollision=False) collisionCube.createObject('Point', selfCollision=False) #Finally we add the mapping of this mesh to that of its parant node the cube collisionCube.createObject('BarycentricMapping') #We add the contactmodel and the corresponding friction coefficient ContactHeader(rootNode, alarmDistance=5, contactDistance=1, frictionCoef=0.0)
def createScene(rootNode): MainHeader(rootNode, plugins=["SofaPython", "SoftRobots"], gravity=[0.0, -9810, 0.0]) rootNode.getObject('GenericConstraintSolver').findData( 'maxIterations').value = '100000' rootNode.getObject('GenericConstraintSolver').findData( 'tolerance').value = '1e-12' ContactHeader(rootNode, alarmDistance=5, contactDistance=1, frictionCoef=0.7) GripperController(rootNode) Floor(rootNode, **floorParam) Cube(rootNode, **cubeParam) # Put treshold in rigibObject construction param ? rootNode.getChild('Cube').getObject('Solver').findData( 'threshold').value = '1e-6' for i in range(len(fingersParameters)): finger = ElasticMaterialObject( attachedTo=rootNode, volumeMeshFileName=fingersVolumeMesh, name=fingersParameters[i]['name'], rotation=fingersParameters[i]['rotation'], translation=fingersParameters[i]['translation'], surfaceMeshFileName=fingersSurfaceAndCollisionMesh, collisionMesh=fingersSurfaceAndCollisionMesh, withConstrain=True, surfaceColor=fingersColor, poissonRatio=poissonRatioFingers, youngModulus=youngModulusFingers, totalMass=fingersMass) finger.getObject('EulerImplicit').findData( 'rayleighStiffness').value = 0.1 finger.getObject('EulerImplicit').findData('rayleighMass').value = 0.1 finger.createObject('BoxROI', name='boxROI', box=fingersParameters[i]['ROIBox'], drawBoxes='true', doUpdate='0') finger.createObject('RestShapeSpringsForceField', points='@../finger1/boxROI.indices', stiffness='1e12', angularStiffness='1e12') SubTopology(attachedTo=finger, topologiyContainer='container', subTopologiyContainer=subTopoParameters[i] ['subTopologiyContainer'], atPositions=subTopoParameters[i]['atPositions'], poissonRatio=poissonRatioFingers, youngModulus=youngModulusStiffLayerFingers - youngModulusFingers) PneumaticCavity(surfaceMeshFileName=fingersCavitySurfaceMesh, attachedAsAChildOf=finger, name='cavity', rotation=fingersParameters[i]['rotation'], translation=fingersParameters[i]['translation'], initialValue=cavitiesInitialValue, valueType='pressure')