Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[constraint] adds JointConstraint #274

Merged
merged 10 commits into from
Jun 4, 2024
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ set(HEADER_FILES
${SOFTROBOTS_SOURCE_DIR}/component/constraint/SurfacePressureConstraint.inl
${SOFTROBOTS_SOURCE_DIR}/component/constraint/UnilateralPlaneConstraint.h
${SOFTROBOTS_SOURCE_DIR}/component/constraint/UnilateralPlaneConstraint.inl
${SOFTROBOTS_SOURCE_DIR}/component/constraint/JointConstraint.h
${SOFTROBOTS_SOURCE_DIR}/component/constraint/JointConstraint.inl
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/AffineFunctionModel.h
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/AffineFunctionModel.inl
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/CableModel.h
Expand All @@ -51,6 +53,7 @@ set(HEADER_FILES
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/PositionModel.inl
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/SurfacePressureModel.h
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/SurfacePressureModel.inl


${SOFTROBOTS_SOURCE_DIR}/component/controller/AnimationEditor.h
${SOFTROBOTS_SOURCE_DIR}/component/controller/AnimationEditor.inl
Expand Down Expand Up @@ -84,6 +87,7 @@ set(SOURCE_FILES
${SOFTROBOTS_SOURCE_DIR}/component/constraint/PositionConstraint.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/SurfacePressureConstraint.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/UnilateralPlaneConstraint.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/JointConstraint.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/AffineFunctionModel.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/CableModel.cpp
${SOFTROBOTS_SOURCE_DIR}/component/constraint/model/PositionModel.cpp
Expand Down
71 changes: 71 additions & 0 deletions examples/component/constraint/JointConstraint/JointConstraint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os
from math import pi

dirPath = os.path.dirname(os.path.abspath(__file__)) + '/'


def createScene(rootNode):
rootNode.addObject('RequiredPlugin', name='SoftRobots')
rootNode.addObject('RequiredPlugin', name='SoftRobots.Inverse')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EulalieCoevoet Could you make sure that this plugin is not required? Thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups sorry. Not needed indeed.

rootNode.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct') # Needed to use components [SparseLDLSolver]
rootNode.addObject('RequiredPlugin', name='ArticulatedSystemPlugin') # Needed to use components [ArticulatedHierarchyContainer,ArticulatedSystemMapping,Articulation,ArticulationCenter]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.AnimationLoop') # Needed to use components [FreeMotionAnimationLoop]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Constraint.Lagrangian.Correction') # Needed to use components [UncoupledConstraintCorrection]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Constraint.Lagrangian.Solver') # Needed to use components [GenericConstraintSolver]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Constraint.Projective') # Needed to use components [FixedProjectiveConstraint]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Engine.Generate') # Needed to use components [GenerateRigidMass]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.IO.Mesh') # Needed to use components [MeshSTLLoader]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mapping.NonLinear') # Needed to use components [RigidMapping]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mass') # Needed to use components [UniformMass]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward') # Needed to use components [EulerImplicitSolver]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Setting') # Needed to use components [BackgroundSetting]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.SolidMechanics.FEM.Elastic') # Needed to use components [BeamFEMForceField]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.StateContainer') # Needed to use components [MechanicalObject]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Topology.Container.Constant') # Needed to use components [MeshTopology]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Visual') # Needed to use components [VisualStyle]
rootNode.addObject('RequiredPlugin', name='Sofa.GL.Component.Rendering3D') # Needed to use components [OglModel]

rootNode.dt = 0.01
rootNode.gravity = [0., -9810., 0.]
rootNode.addObject('VisualStyle', displayFlags='showBehaviorModels')
rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('GenericConstraintSolver', maxIterations=500, tolerance=1e-4)

# Simulation node
simulation = rootNode.addChild('Simulation')
simulation.addObject('EulerImplicitSolver')
simulation.addObject('SparseLDLSolver', template="CompressedRowSparseMatrixd")
simulation.addObject('GenericConstraintCorrection')

object = simulation.addChild('Object')
object.addObject('MechanicalObject', template='Vec1', position=0.)
object.addObject("RestShapeSpringsForceField", points=[0], stiffness=1e1)
# Try to change the data field "value" from the GUI
object.addObject('JointConstraint', template='Vec1', index=0, value=0, valueType="displacement",
minDisplacement=-pi, maxDisplacement=pi)

rigid = object.addChild('Rigid')
rigid.addObject('MechanicalObject', template='Rigid3', position=[[0., 0., 0., 0., 0., 0., 1.]]*2)
rigid.addObject('UniformMass', totalMass=0.003)
rigid.addObject('ArticulatedSystemMapping',
input1=object.getMechanicalState().linkpath,
output=rigid.getMechanicalState().linkpath)

visual = rigid.addChild('VisualModel')
visual.addObject('MeshSTLLoader', name='loader', filename=dirPath + 'mesh/arm.stl', translation=[-45, 0., 0.])
visual.addObject('MeshTopology', src='@loader')
visual.addObject('OglModel', color=[0.9, 0.9, 0.9, 1.])
visual.addObject('RigidMapping', index=1)

articulationCenters = object.addChild('Articulation')
articulationCenter = articulationCenters.addChild('ArticulationCenter')
articulationCenter.addObject('ArticulationCenter', parentIndex=0, childIndex=1,
posOnParent=[0., 0., 0.],
posOnChild=[-45, 0., 0.], articulationProcess=1)
articulation = articulationCenter.addChild('Articulations')
articulation.addObject('Articulation', translation=False, rotation=True, rotationAxis=[0, 0, 1],
articulationIndex=0)

object.addObject('ArticulatedHierarchyContainer')

return rootNode
Loading
Loading