Home › Forum › SOFA › Programming with SOFA › SofaPython Monitor error with MechanicalObject
Tagged: 64_bits, Monitor, Plugin_other, SOFA, SOFA_2006, SofaPython, Windows_10
- This topic has 1 reply, 2 voices, and was last updated 4 years, 2 months ago by Hugo.
-
AuthorPosts
-
5 September 2020 at 12:34 #17086AnonymousInactive
Hi guys, nice to meet you all.
I’m working a little with Sofa, in particular with SofaPython, to model an interaction between a needle and a phantom (actually just the first layer, the fat). I was able to model the interaction with also an insertion of the needle, and now I need to create a graph showing the forces during this interaction. To do so, I’m trying to use the Monitor component. This works if added to the Fat node but, if i try to add it at the needle node, Sofa keeps crashing with an error
[Monitor] error : no MechanicalObject found
even if the MechanicalObject is actually present. This is the needle node creation code:
# ========================== # NEEDLE NODE # ========================== meshFile_needle = 'data/syrette2.obj' scale = 10 needleNode = self.rootNode.createChild('Needle') needleNode.createObject('EulerImplicitSolver', name='ODE solver', rayleighStiffness=0.01, rayleighMass=1.0) needleNode.createObject('CGLinearSolver', name='linear solver', iterations=25, tolerance=1e-7, threshold=1e-7) needleNode.createObject('MechanicalObject', name='mechObject', template='Rigid3d', dx=20, dy=150, dz=-50, rx=0, ry=0, rz=-90.0, scale3d=[scale, scale, scale]) needleNode.createObject('UniformMass', name='mass', totalMass=1) needleNode.createObject('UncoupledConstraintCorrection') ### MONITOR ### needleNode.createObject( 'Monitor', name='monitor-displacement-faceNode', indices=45, template='Vec3d', listening=1, showPositions=False, PositionsColor='1 0 1 1', ExportPositions=True, showVelocities=False, VelocitiesColor='0.5 0.5 1 1', ExportVelocities=False,showForces=True, ForcesColor='0.8 0.2 0.2 1', ExportForces=True, showTrajectories=False, TrajectoriesPrecision=0.1, TrajectoriesColor='0 1 1 1', sizeFactor=0.1) # Visual node needleVisNode = needleNode.createChild('VisualModel') needleVisNode.createObject('MeshObjLoader', name='instrumentMeshLoader', filename=meshFile_needle) needleVisNode.createObject('OglModel', name='InstrumentVisualModel', src='@instrumentMeshLoader', dy=-2*scale, scale3d=[scale, scale, scale]) needleVisNode.createObject('RigidMapping', name='MM-VM mapping', input='@../mechObject', output='@InstrumentVisualModel') # Collision node needleColNode = needleNode.createChild('CollisionModel') needleColNode.createObject('MeshObjLoader', filename=meshFile_needle, name='loader') needleColNode.createObject('MeshTopology', src='@loader', name='InstrumentCollisionModel') needleColNode.createObject('MechanicalObject', src='@InstrumentCollisionModel', name='instrumentCollisionState', dy=-2*scale, scale3d=[scale, scale, scale]) needleColNode.createObject('TriangleCollisionModel', name='instrumentTriangle', contactStiffness=0.1, contactFriction=0.1) needleColNode.createObject('LineCollisionModel', name='instrumentLine', contactStiffness=0.1, contactFriction=0.1) needleColNode.createObject('PointCollisionModel', name='instrumentPoint', contactStiffness=0.1, contactFriction=0.1) needleColNode.createObject('RigidMapping', name='MM-CM mapping', input='@../mechObject', output='@instrumentCollisionState') # Trajectory needleNode.createObject('LinearMovementConstraint', template='Rigid3d', indices=0, keyTimes=[0, 0.8, 1.6, 1.7], movements=[[0, 0, 0, 0, 0, 0], [0, -75, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0]])
Thanks everyone who can help me,
Cheers,
Luca11 September 2020 at 15:43 #17118HugoKeymasterHi @mallow
You are not showing which AnimationLoop you are using but I guess it is the FreeMotionAnimationLoop, is this correct?
A topic recently described how to extract the forces in such a Lagrange-multiplier-based approach.I hope this helps.
Best wishes,Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.