Home › Forum › SofaPython3 › Programming with SofaPython3 › [SOLVED] StiffSpringForceField with Rigid3d
Tagged: SOFA_2012, SofaPython3, StiffSpringForceField, Windows_10
- This topic has 4 replies, 2 voices, and was last updated 3 years, 4 months ago by chiarasapo.
-
AuthorPosts
-
15 June 2021 at 14:56 #19702chiarasapoBlocked
Hi! I am trying to link two objects with springs via StiffSpringForceField. Until I try to link Vec3d MechanicalObjects I have no problems. However, I wanted to use one Vec3d MO and one Rigid3d MO, but it looks like I cannot do that (I receive [ERROR] keyError). Is it true or am I doing something wrong?
This is part of my code (object1 has a Vec3d MO, object2 has a Rigid3d MO):spring_force_field = root.addObject(“StiffSpringForceField”, object1=root.SkinLeft.SkinMechObj.getLinkPath(), object2=root.SutureNeedle.InstrumentMechObj.getLinkPath())
springs = [Sofa.SofaDeformable.LinearSpring(index1=i, index2=i, springStiffness=10, dampingFactor=5, restLength=1) for i in range(8)]
spring_force_field.addSprings(springs)Thank you very much in advance!
25 June 2021 at 14:45 #19867HugoKeymasterCiao @chiarasapo
Indeed it is not possible to use a physical spring between two objects which do not have the same degrees of freedom, which is quite logical. The simulation has no clue how to relate different DOFs.
How to solve this? All you need is to map a Vec3d object on your Rigid object (using a RigidMapping) and then define the spring between the two Vec3d MechanicalObjects.
Do you see my point?
Hugo
1 July 2021 at 15:54 #19909chiarasapoBlockedYes, I understand, I’ll do that! Thank you very much for your answer @hugo
8 July 2021 at 12:26 #19994chiarasapoBlockedHowever I was also wondering: I attached such springs between the objects that I wanted to move together (needle and skin as in the picture at https://github.com/ChiaraSapo/Haptic-surgery-simulation/blob/main/Images/springs.png) but, when I move the needle, the springs just stretch without deforming the skin. Did I do something wrong or is it the normal behavior @Hugo?
I did it from a sofa controller by setting
self.spring_force_field = rootNode.addObject("StiffSpringForceField", name="FF", object1 = models.Skin.MO, object2=models.SutureNeedle.MO)
And then by passing the skin indices I wanted to link to the needle:
springs = [Sofa.SofaDeformable.LinearSpring(index1=i, index2=0, springStiffness=50, dampingFactor=5, restLength=1) for i in indicesBox] self.spring_force_field.addSprings(springs)
19 July 2021 at 09:22 #20040chiarasapoBlockedI decided to open a new topic about this last comment at https://www.sofa-framework.org/community/forum/topic/springs-not-working/ since my main question here was already answered. Thank you again!
Chiara -
AuthorPosts
- You must be logged in to reply to this topic.