def ElasticBody(parent): """Create an object with an elastic deformation law""" body = parent.createChild("ElasticBody") # Prefab ElasticMaterialObject implementing the whole mechanical model of the silicone piece e = ElasticMaterialObject(body, volumeMeshFileName="data/mesh/tripod_mid.gidmsh", poissonRatio=0.45, youngModulus=800, totalMass=0.032, rotation=[90, 0, 0]) # Visual model visual = e.createChild("Visual") visual.createObject("MeshSTLLoader", name="loader", filename="data/mesh/tripod_mid.stl", rotation=[90, 0, 0]) visual.createObject("OglModel", name="renderer", src="@loader", color=[1.0, 1.0, 1.0, 0.5]) visual.createObject("BarycentricMapping", input=e.dofs.getLinkPath(), output=visual.renderer.getLinkPath()) return body
def createScene(rootNode): from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject MainHeader(rootNode) target = ElasticMaterialObject( volumeMeshFileName="mesh/liver.msh", totalMass=0.5, attachedTo=rootNode) target.createObject('BoxROI', name='boxROI', box=[-20,-20,-20,20,20,20], drawBoxes='true') SubTopology(attachedTo= target, containerLink= '@../container.position', boxRoiLink='@../boxROI.tetrahedraInROI', name='Default-tetrahedron') SubTopology(attachedTo= target, containerLink= '@../container.position', linkType= 'triangle', boxRoiLink='@../boxROI.trianglesInROI', name='Triangles') SubTopology(attachedTo= target, containerLink= '@../container.position', linkType= 'hexahedron', boxRoiLink='@../boxROI.hexahedraInROI', name='Hexahedron')
def createBunny(Node, Translation=[0, 0, 0], ControlType='PressureConstraint', Name='Bunny', InitialValue=0.0001, YoungModulus=18000): #Bunny #BoxROICoordinates=[-5, -6, -5, 5, -4.5, 5] + [Translation,Translation] BoxROICoordinates = [ -5 + Translation[0], -6 + Translation[1], -5 + Translation[2], 5 + Translation[0], -4.5 + Translation[1], 5 + Translation[2] ] Bunny = ElasticMaterialObject( name=Name, attachedTo=Node, volumeMeshFileName=meshpath + 'Hollow_Stanford_Bunny.vtu', surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', youngModulus=YoungModulus, withConstrain=True, totalMass=0.5, translation=Translation) FixedBox(Bunny, doVisualization=True, atPositions=BoxROICoordinates) if ControlType == 'PressureConstraint': cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', valueType='pressureGrowth', initialValue=InitialValue, translation=Translation) elif ControlType == 'VolumeConstraint': cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', valueType='volumeGrowth', initialValue=InitialValue, translation=Translation) BunnyVisu = Bunny.createChild('visu') BunnyVisu.createObject('TriangleSetTopologyContainer', name='container') BunnyVisu.createObject('TriangleSetTopologyModifier') BunnyVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d') BunnyVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d') BunnyVisu.createObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") BunnyVisu.createObject('OglModel', template='ExtVec3f', color='0.3 0.2 0.2 0.6', translation=Translation) BunnyVisu.createObject('IdentityMapping') return Bunny
def createSceneReal(rootNode, dt): length_scale = "0.500" disk_msh = 'disk_'+length_scale+'.msh' disk_inside_stl = 'disk_inside'+length_scale+'.stl' rootNode = Scene(rootNode, gravity=[0.0, -0.0, 9.8], dt=dt) rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject('VisualStyle', displayFlags='showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe') rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', name='gencs', maxIterations='500', printLog='0', tolerance='0.0000001') rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765') YoungModulus = 1800 InitialValue = 1000.0 Translation="0 0 0" Bunny = ElasticMaterialObject(name="disk", attachedTo=rootNode, volumeMeshFileName=meshpath+disk_msh, surfaceMeshFileName=meshpath+disk_inside_stl, youngModulus=YoungModulus, withConstrain=True, totalMass=1.0, translation="0 0 0") fixed_const_str = "" fixed_const_lst = [274, 309, 344, 345, 770, 783, 807] for i in fixed_const_lst: fixed_const_str = fixed_const_str + " " + str(i) print "Fixed stuff", fixed_const_lst, fixed_const_str Bunny.createObject("FixedConstraint", indices=fixed_const_str) cavity = PneumaticCavity(name='cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + disk_inside_stl, valueType='volumeGrowth', initialValue=InitialValue, translation=Translation) BunnyVisu = Bunny.createChild('visu') BunnyVisu.createObject('TriangleSetTopologyContainer', name='container') BunnyVisu.createObject('TriangleSetTopologyModifier') BunnyVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d') BunnyVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d') BunnyVisu.createObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") BunnyVisu.createObject('OglModel', template='ExtVec3f', color='0.3 0.2 0.2 0.6', translation=Translation) BunnyVisu.createObject('IdentityMapping') return Bunny
def createScene(rootNode): rootNode.createObject('VisualStyle', displayFlags='showVisualModels showForceFields') rootNode.findData('gravity').value=[0.0,0.0,-9810]; rootNode.findData('dt').value=1 plugins=["SofaPython","SoftRobots","ModelOrderReduction"] for name in plugins: rootNode.createObject('RequiredPlugin', name=name, printLog=False) rootNode.createObject('OglSceneFrame', style="Arrows", alignment="TopRight") rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', tolerance="1e-6", maxIterations="1000") modelNode = ElasticMaterialObject( attachedTo=rootNode, volumeMeshFileName=meshPath+'cylinder_real_sparse.vtu', # volumeMeshFileName=meshPath+'siliconeV0.vtu', name='modelNode', # rotation=[90, 0.0, 0.0], # translation=[0.0, 0.0, 35], rotation=[0.0, 0.0, 0.0], translation=[0.0, 0.0, 0], totalMass=0.5, withConstrain=False, surfaceMeshFileName=meshPath+'cylinder.STL', surfaceColor=[0.7, 0.7, 0.7, 0.7], poissonRatio=0.45, youngModulus=450) modelNode.createObject('GenericConstraintCorrection', solverName='solver') FixedBox( atPositions=[-15, -5, -20, 15, 25, 10], applyTo=modelNode, name="box1", doVisualization=True) FixedBox( atPositions=[-15, -5, -615, 15, 25, -585], applyTo=modelNode, name="box2", doVisualization=True) for i in range(len(actuatorsParam)): cable = PullingCable( attachedTo=modelNode, name=actuatorsParam[i]['withName'], cableGeometry=actuatorsParam[i]['withCableGeometry'], pullPointLocation=actuatorsParam[i]['withAPullPointLocation'], valueType="displacement") return rootNode
def Bunny(Node, translation=[0, 0, 0], controlType='PressureConstraint', name='Bunny', initialValue=0.0001, youngModulus=18000): #Bunny #boxROICoordinates=[-5, -6, -5, 5, -4.5, 5] + [translation,translation] boxROICoordinates = [ -5 + translation[0], -6 + translation[1], -5 + translation[2], 5 + translation[0], -4.5 + translation[1], 5 + translation[2] ] Bunny = ElasticMaterialObject( name=name, attachedTo=Node, volumeMeshFileName=meshpath + 'Hollow_Stanford_Bunny.vtu', surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', youngModulus=youngModulus, withConstrain=True, totalMass=0.5, translation=translation) FixedBox(Bunny, doVisualization=True, atPositions=boxROICoordinates) if controlType == 'PressureConstraint': cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', valueType='pressureGrowth', initialValue=initialValue, translation=translation) elif controlType == 'VolumeConstraint': cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + 'Hollow_Bunny_Body_Cavity.obj', valueType='volumeGrowth', initialValue=initialValue, translation=translation) BunnyVisu = Bunny.addChild('visu') BunnyVisu.addObject('TriangleSetTopologyContainer', name='container') BunnyVisu.addObject('TriangleSetTopologyModifier') BunnyVisu.addObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") BunnyVisu.addObject('OglModel', color=[0.3, 0.2, 0.2, 0.6], translation=translation) BunnyVisu.addObject('IdentityMapping') return Bunny
def Finger(parentNode=None, name="Finger", rotation=[0.0, 0.0, 0.0], translation=[0.0, 0.0, 0.0]): # trans = translation finger = ElasticMaterialObject(parentNode,name=name, volumeMeshFileName=path+"transFinger.vtk", # volumeMeshFileName=path+"finger.vtk", poissonRatio=0.45, youngModulus=600, totalMass=0.5, surfaceColor=[0.0, 0.7, 0.7], surfaceMeshFileName=path+"transFinger.stl", # surfaceMeshFileName=path+"finger.stl", rotation=rotation, translation=translation) finger.node.createObject('RestShapeSpringsForceField', points='16 17 18 19 20 21 48 51 52 54 63 103 104 105 106 107 113 116 128 135 143 150', stiffness='1e12') # FixedBox(finger.node, atPositions=fixingBox, doVisualization=True) CollisionMesh(finger.node, name="CollisionMesh", surfaceMeshFileName=path+"transFinger.stl", rotation=rotation, translation=translation, collisionGroup=[1, 2]) # CollisionMesh(finger.node, name="CollisionMeshAuto1", # surfaceMeshFileName=path+"fingerCollision_part1.stl", # rotation=rotation, translation=translation, # collisionGroup=[1]) # # CollisionMesh(finger.node, name="CollisionMeshAuto2", # surfaceMeshFileName=path+"fingerCollision_part2.stl", # rotation=rotation, translation=translation, # collisionGroup=[2]) return finger
def ElasticBody(parent): body = parent.createChild('ElasticBody') e = ElasticMaterialObject( body, volumeMeshFileName='../data/mesh/tripod_mid.gidmsh', translation=[0.0, 30, 0.0], rotation=[90, 0, 0], youngModulus=600, poissonRatio=0.45, totalMass=0.4) visual = body.createChild('Visual') visual.createObject('MeshSTLLoader', name='loader', filename='../data/mesh/tripod_mid.stl') visual.createObject('OglModel', name='renderer', src='@loader', color=[1.0, 1.0, 1.0, 0.5], rotation=[90, 0, 0], translation=[0, 30, 0]) visual.createObject('BarycentricMapping', input=e.dofs.getLinkPath(), output=visual.renderer.getLinkPath()) return body
def ElasticBody(parent): body = parent.createChild("ElasticBody") e = ElasticMaterialObject( body, volumeMeshFileName="../data/mesh/tripod_mid.gidmsh", translation=[0.0, 30, 0.0], rotation=[90, 0, 0], youngModulus=800, poissonRatio=0.45, totalMass=0.032) visual = body.createChild("Visual") visual.createObject("MeshSTLLoader", name="loader", filename="../data/mesh/tripod_mid.stl") visual.createObject("OglModel", name="renderer", src="@loader", color=[1.0, 1.0, 1.0, 0.5], rotation=[90, 0, 0], translation=[0, 30, 0]) visual.createObject("BarycentricMapping", input=e.dofs.getLinkPath(), output=visual.renderer.getLinkPath()) CollisionMesh(e, surfaceMeshFileName="../data/mesh/tripod_low.stl", name="silicone", translation=[0.0, 30, 0.0], rotation=[90, 0, 0], collisionGroup=1) return body
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): """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(node): from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject MainHeader(node, plugins=["SoftRobots"]) target = ElasticMaterialObject(volumeMeshFileName="mesh/liver.msh", totalMass=0.5, attachedTo=node) PullingCable(target)
def Finger(parentNode=None, name="Finger", rotation=[0.0, 0.0, 0.0], translation=[0.0, 0.0, 0.0], fixingBox=[-5.0, 0.0, 0.0, 10.0, 15.0, 20.0], pullPointLocation=[0.0, 0.0, 0.0]): finger = Node(parentNode, name) eobject = ElasticMaterialObject(finger, volumeMeshFileName="data/mesh/finger.vtk", poissonRatio=0.3, youngModulus=18000, totalMass=0.5, surfaceColor=[0.0, 0.8, 0.7], surfaceMeshFileName="data/mesh/finger.stl", rotation=rotation, translation=translation) FixedBox(eobject.node, atPositions=fixingBox, doVisualization=True) cable = PullingCable( eobject.node, "PullingCable", pullPointLocation=pullPointLocation, rotation=rotation, translation=translation, cableGeometry=loadPointListFromFile("data/mesh/cable.json")) FingerController(eobject.node, cable) CollisionMesh(eobject.node, name="CollisionMesh", surfaceMeshFileName="data/mesh/finger.stl", rotation=rotation, translation=translation, collisionGroup=[1, 2]) CollisionMesh(eobject.node, name="CollisionMeshAuto1", surfaceMeshFileName="data/mesh/fingerCollision_part1.stl", rotation=rotation, translation=translation, collisionGroup=[1]) CollisionMesh(eobject.node, name="CollisionMeshAuto2", surfaceMeshFileName="data/mesh/fingerCollision_part2.stl", rotation=rotation, translation=translation, collisionGroup=[2]) return finger
def createScene(rootNode): from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject from stlib.physics.constraints import FixedBox MainHeader(rootNode) target = ElasticMaterialObject(fromVolumeMesh="mesh/liver.msh", withTotalMass=0.5, attachedTo=rootNode) FixedBox(atPositions=[-4, 0, 0, 5, 5, 4], applyTo=target, withVisualization=True)
def createScene(rootNode): from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject from stlib.physics.constraints import FixedBox MainHeader(rootNode) target = ElasticMaterialObject(volumeMeshFileName="mesh/liver.msh", totalMass=0.5, attachedTo=rootNode) FixedBox(atPositions=[-4, 0, 0, 5, 5, 4], applyTo=target, doVisualization=True) CollisionMesh(surfaceMeshFileName="mesh/liver.obj", attachedTo=target)
def createScene(rootNode): rootNode = MainHeader( rootNode, plugins=["SofaPython","SoftRobots","ModelOrderReduction"], dt=1, gravity=[0.0,0.0,-9810]) modelNode = ElasticMaterialObject( attachedTo=rootNode, volumeMeshFileName=meshPath+'siliconeV0.vtu', name='modelNode', rotation=[90, 0.0, 0.0], translation=[0.0, 0.0, 35], totalMass=0.5, withConstrain=False, # surfaceMeshFileName=meshPath+'surface.stl', # surfaceColor=[0.7, 0.7, 0.7, 0.7], poissonRatio=0.45, youngModulus=450) modelNode.createObject('GenericConstraintCorrection', solverName='Solver') # modelNode.createObject('WriteState', filename="init_myDiamondQuiteFine.vtu.state", period='0.1',writeX="0", writeX0="1", writeV="0") FixedBox( atPositions=[-15, -15, -40, 15, 15, 10], applyTo=modelNode, doVisualization=True) for i in range(len(actuatorsParam)): cable = PullingCable( attachedTo=modelNode, name=actuatorsParam[i]['withName'], cableGeometry=actuatorsParam[i]['withCableGeometry'], pullPointLocation=actuatorsParam[i]['withAPullPointLocation'], valueType="displacement") 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): """ """ from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject from stlib.physics.mixedmaterial import Rigidify from splib.objectmodel import setData MainHeader(rootNode, plugins=["SofaSparseSolver"]) rootNode.VisualStyle.displayFlags = "showBehavior" modelNode = rootNode.createChild("Modeling") elasticobject = ElasticMaterialObject(modelNode, "mesh/liver.msh", "ElasticMaterialObject") # Rigidification of the elasticobject for given indices with given frameOrientations. o = Rigidify(modelNode, elasticobject, name="RigidifiedStructure", frames=[[0., 0., 0], [0., 0., 0]], groupIndices=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [48, 49, 50, 51]]) # Activate some rendering on the rigidified object. setData(o.RigidParts.dofs, showObject=True, showObjectScale=1, drawMode=2) setData(o.RigidParts.RigidifiedParticules.dofs, showObject=True, showObjectScale=0.1, drawMode=1, showColor=[1., 1., 0., 1.]) setData(o.DeformableParts.dofs, showObject=True, showObjectScale=0.1, drawMode=2) o.RigidParts.createObject("FixedConstraint", indices=0) simulationNode = rootNode.createChild("Simulation") simulationNode.createObject("EulerImplicitSolver") simulationNode.createObject("CGLinearSolver") simulationNode.addChild(o) return rootNode
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')
def Finger(parentNode=None, name="Finger", rotation=[0.0, 0.0, 0.0], translation=[0.0, 0.0, 0.0], fixingBox=[0.0, 0.0, 0.0], pullPointLocation=[0.0, 0.0, 0.0], youngModulus=18000, valueType='position'): finger = Node(parentNode, name) eobject = ElasticMaterialObject( finger, volumeMeshFileName=os.path.join( templatepath, "mesh/finger.vtk"), #MISK need to change the relative file poissonRatio=0.3, youngModulus=youngModulus, totalMass=0.5, surfaceColor=[0.0, 0.8, 0.65], surfaceMeshFileName=os.path.join(templatepath, "mesh/finger.stl"), rotation=rotation, translation=translation) FixedBox(eobject, atPositions=fixingBox, doVisualization=True) cable = PullingCable(eobject, "PullingCable", pullPointLocation=pullPointLocation, rotation=rotation, translation=translation, cableGeometry=loadPointListFromFile( os.path.join(templatepath, "mesh/cable.json")), valueType=valueType) #Eulalie.C (21/09/18): this feature does not work, either fix it or remove this comment before SoftRobots v19 #FingerController(eobject, cable, valueType) #MISK may change to vary variation based on value type CollisionMesh(eobject, name="CollisionMesh", surfaceMeshFileName=os.path.join(templatepath, "mesh/finger.stl"), rotation=rotation, translation=translation, collisionGroup=[1, 2]) CollisionMesh(eobject, name="CollisionMeshAuto1", surfaceMeshFileName=os.path.join( templatepath, "mesh/fingerCollision_part1.stl"), rotation=rotation, translation=translation, collisionGroup=[1]) CollisionMesh(eobject, name="CollisionMeshAuto2", surfaceMeshFileName=os.path.join( templatepath, "mesh/fingerCollision_part2.stl"), rotation=rotation, translation=translation, collisionGroup=[2]) return finger
def createSceneReal(rootNode, dt, fixed_const_lst, moving_const_lst): length_scale = sys.argv[1] block_msh = 'block_' + length_scale + '.msh' rootNode = Scene(rootNode, gravity=[0.0, -0.0, 1000.0], dt=dt) rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject( 'VisualStyle', displayFlags= 'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe' ) rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject( 'VisualStyle', displayFlags= 'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe' ) rootNode.dt = dt rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', name='gencs', maxIterations='500', printLog='0', tolerance='0.0000001') rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765') YoungModulus = 1800 InitialValue = 0.01 Translation = None Block = ElasticMaterialObject(name="block", attachedTo=rootNode, volumeMeshFileName=meshpath + block_msh, surfaceMeshFileName=None, youngModulus=YoungModulus, withConstrain=True, totalMass=1.0, translation=None) fixed_const_str = "" for i in fixed_const_lst: fixed_const_str = fixed_const_str + " " + str(i) moving_const_str = "" for i in moving_const_lst: moving_const_str = moving_const_str + " " + str(i) print 'moving', moving_const_str print 'fixed ', fixed_const_str Block.createObject("FixedConstraint", indices=fixed_const_str) inds = "7 63 62 60 5 254 240 206 236 47 68 69 253" Block.createObject('PartialLinearMovementConstraint', indices=moving_const_str, keyTimes='0 ' + str(dt) + " 10", template='Vec3d', movements='0. 0. 0. 0. -1 0. 0. -1 0.') #cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Block, # surfaceMeshFileName=meshpath + block_inside_stl, valueType='pressureGrowth', # initialValue=InitialValue, translation=Translation) BlockVisu = Block.createChild('visu') BlockVisu.createObject('TriangleSetTopologyContainer', name='container') BlockVisu.createObject('TriangleSetTopologyModifier') BlockVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d') BlockVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d') BlockVisu.createObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") BlockVisu.createObject('OglModel', template='ExtVec3f', color='0.3 0.2 0.2 0.6', translation=Translation) BlockVisu.createObject('IdentityMapping') return Block
def createSceneReal(rootNode, dt, L): length_scale = L disk_msh = 'disk_' + length_scale + '.msh' disk_inside_stl = 'disk_inside' + length_scale + '.stl' ''' # find point closest to zero (with positive z valu) vector, mid_ind = point_finder.nth_smallest_point(disk_msh, 0) i = 0 while vector[-1] < 1.0: i += 1 vector, mid_ind = point_finder.nth_smallest_point(disk_msh, i) print(vector, mid_ind)''' rootNode = Scene(rootNode, gravity=[0.0, -0.0, 9.8], dt=dt) rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject( 'VisualStyle', displayFlags= 'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe' ) rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject( 'VisualStyle', displayFlags= 'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe' ) rootNode.dt = 0.001 rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', name='gencs', maxIterations='500', printLog='0', tolerance='0.0000001') #disksolver = rootNode.add('SparseLDLSolver', name="solver") rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765') YoungModulus = 1800 InitialValue = 0.01 Translation = None Bunny = ElasticMaterialObject(name="disk", attachedTo=rootNode, volumeMeshFileName=meshpath + disk_msh, surfaceMeshFileName=meshpath + disk_inside_stl, youngModulus=YoungModulus, withConstrain=True, totalMass=1.0, translation=None) fixed_const_str = "" fixed_const_lst = point_finder.all_nodes_within_and_below_zero( disk_msh, 2.0) for i in fixed_const_lst: fixed_const_str = fixed_const_str + " " + str(i) print "hell", fixed_const_lst, fixed_const_str Bunny.createObject("FixedConstraint", indices=fixed_const_str) cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Bunny, surfaceMeshFileName=meshpath + disk_inside_stl, valueType='pressureGrowth', initialValue=InitialValue, translation=Translation) BunnyVisu = Bunny.createChild('visu') BunnyVisu.createObject('TriangleSetTopologyContainer', name='container') BunnyVisu.createObject('TriangleSetTopologyModifier') BunnyVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d') BunnyVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d') BunnyVisu.createObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") BunnyVisu.createObject('OglModel', template='ExtVec3f', color='0.3 0.2 0.2 0.6', translation=Translation) BunnyVisu.createObject('IdentityMapping') return Bunny