Home › Forum › SOFA › Using SOFA › [SOLVED] Constraining a spring
Tagged: 64_bits, SOFA_2006, Windows_10
- This topic has 14 replies, 2 voices, and was last updated 3 years, 8 months ago by Scheikl.
-
AuthorPosts
-
9 December 2020 at 20:14 #17989AndrijaBlocked
Hi everyone,
Is there a way to somehow constrain a spring element so that it has very low stiffness in only axical direction, and infinity stiffness in all other directions? For example to set stiffens in axial (X) direction to “free” but stiff in all other directions?
I am try to simulate a spring that would contract only in one direction when I apply force to it i.e. to the rigid body that is attached to it. I have explored StiffSpringForceField and RestShapeSpringsForceField, attached between two rigid bodies but still spring can move in different directions. I also used JointSpringForceField, but again nothing happens even when I used high values of stiffness. Maybe I am making a mistake somewhere?
Hope you can help me out.
Thanks!
– Andrija
10 December 2020 at 19:44 #17996ScheiklBlockedHi @andrija987,
would it be possible for your case to first constrain the motion of the two bodies with aLinearMovementConstraint
and then introduce a spring? That would basically do the same thing that you are describing, right?There es an example scene you could use as a starting point:
https://github.com/sofa-framework/sofa/blob/4a493466d6be376d325a19bff97b5e4abf571370/examples/Components/constraint/LinearMovementConstraint.scnCheers,
Paul10 December 2020 at 21:24 #18000AndrijaBlockedHi @scheikl – Paul
Many thanks for the suggestion and your great help! Really appreciate it.
It is a great suggestion, and believe it will work and solve it. But please sorry I didn’t explained the full scene and what I am trying to do. So actually the two rigid bodies that would be connected with a spring, would be lying on top of other bigger cube where this cube would carry them and I will move the cube in different directions by applying input force. To my experience applying the
LinearMovementConstraint
would then limit the motion of two rigid bodes globally and then they cannot realize motion together with the cube that would carry them. But maybe I am wrong? What do you think? I am writing this as I actually tried usingPartialLinearMovementConstraint
and then the motion of the two rigid bodies was globally constrained.I don’t know if there is some way to maybe constrain motion but just relatively to cube where my system would be attached to?
It is a funny thing what I am trying out, but for my project I need somehow to simulate spring like actuator that would attract two rigid bodies i.e. move them in only axical direction of actuator, but in the same time this system would be attach to a larger rigid body that would carry them.
Any thoughts on these?
Many thanks for your help!
By the way, SOFA is really just amazing tool!
Best,
Andrija11 December 2020 at 07:27 #18002AndrijaBlockedHi @scheikl,
Many thanks for your help! The
ArticulatedSystemMapping
will solve it! I just need a bit of time to get a hang on it, but it seems like exactly what I was looking for.I was struggling with this for nearly a month, and tried so many different things.
Many thanks for your support and help! Really applicate it.
Best,
– Andrija11 December 2020 at 10:23 #18004ScheiklBlockedHi @andrija987,
you are very welcome! 🙂The topic seems quite fun, let me know how it works out.
Cheers,
Paul11 December 2020 at 11:20 #18007AndrijaBlockedHi @scheikl,
Thanks once again. I am working on it now. When I make it work, I will share a code, maybe it would ne useful to others as well.
Thanks!
Best,
Andrija5 January 2021 at 13:41 #18108AndrijaBlockedHi @scheikl,
Thanks again for your help back then. Sorry for not been updating sooner with my progress. I tried many things with using the
ArticulatedSystemMapping
but still I cannot make it work as I wanted. I guess I cannot get my head around it and understand it fully. I don’t know how to create Articulations between two indices of my input ports? In the examples of SOFA documents they are using Beams as an example, but don’t know if I need to use it as well.I will share my code as soon as I make it a bit more neat, then maybe you or others can help a bit.
Many thanks!
Best,
Andrija5 January 2021 at 13:49 #18109ScheiklBlockedHi @andrija987,
no worries. 🙂The beam part should not be necessary.
As long as you have someRigid3
objects it should work fine.
I can highly recommend the Tutorials in the SoftRobots Plugin.
ForArticulatedSystemMapping
this one should be quite helpful:
https://github.com/SofaDefrost/SoftRobots/blob/master/docs/tutorials/Tripod/details/s90servo.pySure! I would be happy to have a look at the code.
Cheers,
Paul5 January 2021 at 19:04 #18110AndrijaBlockedHi @scheikl,
Many thanks for your help and for providing me more information about this. I am trying to figure this out, but still no luck. I think the problem is that I don’t understand in detail the
ArticulatedSystemMapping
, and what different components mean. I am really sorry my knowledge is limited.Below is the code and what i have so far.
# Simulating contracting actuator import Sofa import os from stlib.scene import MainHeader, ContactHeader # Defining a scene def createScene(rootNode): # Inicilaize disply rootNode.createObject('VisualStyle', displayFlags='showForceFields showBehaviorModels showBehavior') # Required plugins rootNode.createObject('RequiredPlugin', name='soft', pluginName='SoftRobots') rootNode.createObject('RequiredPlugin', name='SofaPython', pluginName='SofaPython') rootNode.createObject('RequiredPlugin', name='OpenVis', pluginName='SofaOpenglVisual') # Animation loops # rootNode.createObject('FreeMotionAnimationLoop') # Constrain solver rootNode.createObject('GenericConstraintSolver', tolerance="1e-12", maxIterations="100000") # Input port 1 Input_port1 = rootNode.createChild('Input_port1') Input_port1.createObject('EulerImplicit', name='odesolver') Input_port1.createObject('SparseLDLSolver', name='directSolver') Input_port1.createObject('MeshGmshLoader', name='loader', filename='mesh\CubeBlock.msh') Input_port1.createObject('Mesh', src='@loader', name='container') Input_port1.createObject('MechanicalObject', name='tetras', template='Vec3d', showObject='true', showObjectScale='1') Input_port1.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM', method='large', poissonRatio='0.4', youngModulus='8000', drawAsEdges="true") Input_port1.createObject('UniformMass', totalMass='0.1') # Adding supports Input_port1.createObject('BoxROI', name='boxROI', box='10 5 4 16 22 -3', drawBoxes='true') Input_port1.createObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness='1e12', angularStiffness='1e12') # Visualization modelVisu1 = Input_port1.createChild('visu1') modelVisu1.createObject('MeshSTLLoader', name="loader", filename="mesh\CubeBlock.stl") modelVisu1.createObject('OglModel', src="@loader", template='ExtVec3f', color='0.7 0.7 0.7 0.6') modelVisu1.createObject('BarycentricMapping') #Input_port1.createObject('LinearSolverConstraintCorrection', solverName='directSolver') Input_port1.createObject('UncoupledConstraintCorrection') # Input port 2 Input_port2 = Input_port1.createChild('Input_port2') Input_port2.createObject('EulerImplicit', name='odesolver') Input_port2.createObject('SparseLDLSolver', name='directSolver') Input_port2.createObject('MeshGmshLoader', name='loader2', filename='mesh\CubeBlock.msh', translation=[0.0, 0.0, 20.0]) Input_port2.createObject('Mesh', src='@loader2', name='container2') Input_port2.createObject('MechanicalObject', name='tetras2', template='Vec3d', showObject='true', showObjectScale='1') Input_port2.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM', method='large', poissonRatio='0.4', youngModulus='8000', drawAsEdges="true") Input_port2.createObject('UniformMass', totalMass='0.1') # Adding supports Input_port2.createObject('BoxROI', name='boxROI2', box='10 5 25 16 22 18', drawBoxes='true') Input_port2.createObject('RestShapeSpringsForceField', points='@boxROI2.indices', stiffness='1e12', angularStiffness='1e12') # Visualization modelVisu2 = Input_port2.createChild('visu2') modelVisu2.createObject('MeshSTLLoader', name="loader", filename="mesh\CubeBlock.stl", translation=[0.0, 0.0, 20.0]) modelVisu2.createObject('OglModel', src="@loader", template='ExtVec3f', color='0.7 0.7 0.7 0.6') modelVisu2.createObject('BarycentricMapping') #Input_port1.createObject('LinearSolverConstraintCorrection', solverName='directSolver') Input_port2.createObject('UncoupledConstraintCorrection') # Creating connecting point for Input port 1 - Rigid body pointCon1 = Input_port1.createChild('pointCon1') pointCon1.createObject('MechanicalObject', name="DOFpoint1", template="Rigid3d", position="19 16 5 0 0 0 0") pointCon1.createObject('BarycentricMapping') # Creating connecting point for Input port 2 - Rigid body pointCon2 = Input_port2.createChild('pointCon2') pointCon2.createObject('MechanicalObject', name="DOFpoint2", template="Rigid3d", position="19 16 17 0 0 0 0") pointCon2.createObject('BarycentricMapping')
You can download the meshes at this link:
https://drive.google.com/drive/folders/1rCwFsuc9sYQZy3WmxnlZRbrnRGopb3mT?usp=sharing
What I basically setup above are two prismatic objects that represent my two input ports. I don’t know if I mentioned but they need to be modeled as deformable objects, this is why they are modeled as deformable mechanical objects in the code. In general these two input ports will belong to one overall body/system, but this is not important for the current thing I am trying to solve i.e. am asking help. Temproraly I fix the two input ports, but this is just so that they don’t fly away before setting the
ArticulatedSystemMapping
. I added to points that represent Rigid body and they are connected to my input ports withBarycentricMapping
.How I should now define or add
ArticulatedSystemMapping
between my two input ports (or corresponding points that represent rigid body) so that I have the same behavior like in the SOFA doc example forArticulatedSystemMapping
? Or in general sense how I can realize the thing I asked before, i.e. that there is a spring like element between these two input ports, where the spring can realize only axial motion, and motion in all other directions is constraint?I will continue to try to figure this out but I hope you can help me.
Many thanks!
Best,
Andrija6 January 2021 at 20:18 #18115ScheiklBlockedHi @andrija987,
I actually don’t know how I would approach that with two deformable bodies…Maybe you could try to adapt the code in the actuated arm of the SoftRobots Plugin.
https://github.com/SofaDefrost/SoftRobots/blob/master/docs/tutorials/Tripod/details/actuatedarm.pyPersonally I would try to take that code and add the deformable objects under the Rigid3 objects in
ServoArm
andServoBody
and map them to the Rigid3 objects.
So basically for your scene try to makeInput_port1
a child ofpointCon1
and not the other way around.
But I am not sure how to properly map the “soft” part to the “rigid” part…
Even if that does not work in the way you want it, the scene might give you a good understanding of how the components in theArticulatedSystemMapping
work.
Exploring a bit in the Scene Tree of the GUI helps a lot.Let me know if that worked. 🙂
Cheers,
Paul9 January 2021 at 10:04 #18165AndrijaBlockedHi @scheikl,
Many thanks for your help and suggestions! I will try out the things you proposed and see how it goes.
I know how to map or connected deformable body with a rigid one. There are several ways how it is possible to connect them. One is to use
BilateralInteractionConstraint
. In my case to connect thepointCon1
with a new Rigid3 object. This in generaly would work, but forBilateralInteractionConstraint
to work one need to useFreeMotionAnimationLoop
, which when it comes toArticulatedSystemMapping
simply does not work. In other word theArticulatedSystemMapping
does not work when I useFreeMotionAnimationLoop
, but this I don’t know why. Other way to connect them would be to useRestShapeSpringsForceField
between my deformable body and Rigid3 object that would be articulation. In general I have done this in the past and connect them like this, and it work, but when it comes to usingArticulatedSystemMapping
I don’t know if it will work, I will try this one next and see.In general the other thing I am trying is to model simple linear actuator, that I could then attach and use in my robot system, where robot would carry this linear actuator on its top. But I don’t know how to model such actuator, so that it can realize only linear motion in axial direction relative to the robot body, but it can move globally with the robot in different directions. This is why I started to play around with springs, as I thought maybe it is possible to have a spring that has small stiffness in axial direction but very large ones in all other directions, thus it would produce similar behaviour like I am aming at. I wrote this as maybe you will have some other ideas for doing this, beside using
ArticulatedSystemMapping
. You can have a look at this pdf that illustrates what I want to do:
https://drive.google.com/file/d/1DnT40U2oJecc5ph3IwjWj1-986yFUS-_/view?usp=sharingMany thanks! In the mean time I will update you how my progress goes.
Best,
Andrija11 January 2021 at 22:21 #18193AndrijaBlockedHi @scheikl,
Thanks again for trying out to help me. I think this is to much complicated for my understanding and current level of knowledge. I really appreciate your help. I still cannot solve it. But I will try to close this issue and maybe open a new one with question how to simulate linear actuator. Somehow I feel that there is a simple solution, but it could be that I also didn’t know how to explain fully what I am aiming at at the end. If I manage to do it with
ArticulatedSystemMapping
in the mean time I will write it here.Thanks for helping!
Best,
Andrija13 January 2021 at 11:42 #18198ScheiklBlockedHi @andrija987,
sorry for the late reply, and that I could not help you solve the problem. 🙁I am looking forward to the new issue, maybe we can approach that from another angle.
Cheers,
Paul14 January 2021 at 12:54 #18219AndrijaBlockedHi @scheikl,
No need to say sorry. I am grateful that you help me and all the links, thoughts and ideas you suggested.
I think it is more my fault for not explaining in general what I was aiming at. I posted a similar issue or general thing what I was aiming at to simulate at the end in the another topic, but since up till recently there were no replies, I posted a new topic here. Hugo replied to my previous question and is trying to help out, and I will move this issue there with tagging you and mentioning what you were proposing. Maybe based on your ideas Hugo will have some further toughs on this issue.
The link to a topic:
Thanks again and hope we will find solution 🙂 .
Best,
Andrija18 March 2021 at 08:03 #18001ScheiklBlockedHi @andrija987,
no worries :).Ok now I get it!
I thinkArticulatedSystemMapping
should do the trick!
An example can be found here:
https://github.com/sofa-framework/sofa/blob/master/examples/Components/mapping/ArticulatedSystemMapping.scnAnd there is also a very nice explanation in the documentation:
https://www.sofa-framework.org/community/doc/components/mapping/articulatedsystemmapping/So basically what you would do is creating a linear joint, that is attached to your big “carrier” cube.
Hope that helps!
Cheers,
Paul -
AuthorPosts
- You must be logged in to reply to this topic.