From 62cdc04106705c076163850d25c1571d053c6fb4 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Tue, 10 Dec 2024 16:55:52 +0100 Subject: [PATCH 1/2] Apply data name change --- GmshTutorial/SurfacePressureConstraint_Accordion.py | 2 +- Models/CabledTrunk/CabledTrunk.py | 2 +- Models/SensorFinger/SensorFinger.py | 4 ++-- Models/SensorFinger4Cavities/SensorFinger4Cavities.py | 2 +- Models/TripodFinger/Components/fixing_box.py | 2 +- Models/TripodFinger/Components/s90_servo.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/GmshTutorial/SurfacePressureConstraint_Accordion.py b/GmshTutorial/SurfacePressureConstraint_Accordion.py index 31a3e0dc..596d0f85 100644 --- a/GmshTutorial/SurfacePressureConstraint_Accordion.py +++ b/GmshTutorial/SurfacePressureConstraint_Accordion.py @@ -25,7 +25,7 @@ def createScene(rootNode): bunny.addObject('TetrahedronFEMForceField', template='Vec3', name='FEM', method='large', poissonRatio=0.3, youngModulus=18000) bunny.addObject('BoxROI', name='boxROI', box=[-15, -7, -15, 15, -3, 15], drawBoxes=True, position="@tetras.rest_position", tetrahedra="@container.tetrahedra") - bunny.addObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness=1e12) + bunny.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e12) bunny.addObject('SparseLDLSolver', name='preconditioner') bunny.addObject('LinearSolverConstraintCorrection', solverName='preconditioner') diff --git a/Models/CabledTrunk/CabledTrunk.py b/Models/CabledTrunk/CabledTrunk.py index 12f27a89..eea9f42c 100644 --- a/Models/CabledTrunk/CabledTrunk.py +++ b/Models/CabledTrunk/CabledTrunk.py @@ -169,7 +169,7 @@ def createScene(rootNode, config): # Fix base of the Trunk trunk.addObject('BoxROI', name='boxROI', box=[[-20*config.mm, -20*config.mm, -config.d_ext-(config.d_in/2)], [20*config.mm, 20*config.mm, 0]], drawBoxes=True) #trunk.addObject('PartialFixedConstraint', fixedDirections=[1, 1, 1], indices='@boxROI.indices') - trunk.addObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness=1e10) + trunk.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) ################## diff --git a/Models/SensorFinger/SensorFinger.py b/Models/SensorFinger/SensorFinger.py index f9cd3917..b6ee21e1 100644 --- a/Models/SensorFinger/SensorFinger.py +++ b/Models/SensorFinger/SensorFinger.py @@ -134,7 +134,7 @@ def createScene(rootNode, config): model = rootNode.addChild('model') model.addObject('EulerImplicitSolver', name='odesolver', firstOrder=0, rayleighMass=0.1, rayleighStiffness=0.1) model.addObject('SparseLDLSolver', name='precond', template = "CompressedRowSparseMatrixd") - model.addObject('GenericConstraintCorrection') + model.addObject('GenericConstraintCorrection', solverName="precond") ################## ### Load model ### @@ -159,7 +159,7 @@ def createScene(rootNode, config): BoxMargin = 3 BoxCoords = [-(config.Thickness/2+BoxMargin), -BoxMargin, BoxMargin, config.Thickness/2+BoxMargin,config.Height+2*BoxMargin, -BoxMargin] model.addObject('BoxROI', name='boxROI', box=BoxCoords, drawBoxes=True) - model.addObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness=1e10) + model.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) FollowingMONode = model.addChild('FollowingMONode') FollowingMONode.addObject("MechanicalObject", name="FollowingMO", template="Vec3d", position=[0.0, 0, -3.0*config.Length], showObject=True, showObjectScale=20, showColor="0 0 1") diff --git a/Models/SensorFinger4Cavities/SensorFinger4Cavities.py b/Models/SensorFinger4Cavities/SensorFinger4Cavities.py index f7e385f0..cf9e1c77 100644 --- a/Models/SensorFinger4Cavities/SensorFinger4Cavities.py +++ b/Models/SensorFinger4Cavities/SensorFinger4Cavities.py @@ -193,7 +193,7 @@ def createScene(rootNode, config): BoxMargin = 3 BoxCoords = [-(config.Thickness/2+BoxMargin), -BoxMargin, BoxMargin, config.Thickness/2+BoxMargin,config.Height+2*BoxMargin, -BoxMargin] model.addObject('BoxROI', name='boxROI', box=BoxCoords, drawBoxes=True) - model.addObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness=1e10) + model.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) FollowingMONode = model.addChild('FollowingMONode') FollowingMONode.addObject("MechanicalObject", name="FollowingMO", template="Vec3d", position=[0.0, 0, -3.0*config.Length], showObject=True, showObjectScale=20, showColor="0 0 1") diff --git a/Models/TripodFinger/Components/fixing_box.py b/Models/TripodFinger/Components/fixing_box.py index b6ab7005..2afb8c1f 100644 --- a/Models/TripodFinger/Components/fixing_box.py +++ b/Models/TripodFinger/Components/fixing_box.py @@ -27,5 +27,5 @@ def __init__(self, parent, target, name='FixingBox', target.addChild(c) c.addObject('RestShapeSpringsForceField', - points=self.node.BoxROI.getData('indices').getLinkPath(), + indices=self.node.BoxROI.getData('indices').getLinkPath(), stiffness=1e12) diff --git a/Models/TripodFinger/Components/s90_servo.py b/Models/TripodFinger/Components/s90_servo.py index ad940291..709ef0f9 100644 --- a/Models/TripodFinger/Components/s90_servo.py +++ b/Models/TripodFinger/Components/s90_servo.py @@ -75,7 +75,7 @@ def init(self): angle = self.addChild('Articulation') angle.addObject('MechanicalObject', name='dofs', template='Vec1', position=[[self.getData('angleIn')]], rest_position=self.getData('angleIn').getLinkPath()) - angle.addObject('RestShapeSpringsForceField', points=0, stiffness=1e9) + angle.addObject('RestShapeSpringsForceField', indices=0, stiffness=1e9) angle.addObject('UniformMass', totalMass=0.01) servoWheel = angle.addChild('ServoWheel') From 9a1d456bd2a0b9f96a1e009534ef9ac875c8f935 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Tue, 4 Mar 2025 17:32:42 +0100 Subject: [PATCH 2/2] Use FixedWeakConstraint when possible --- GmshTutorial/SurfacePressureConstraint_Accordion.py | 2 +- Models/CabledTrunk/CabledTrunk.py | 4 ++-- Models/SensorFinger/SensorFinger.py | 2 +- Models/SensorFinger4Cavities/SensorFinger4Cavities.py | 2 +- Models/TripodFinger/Components/fixing_box.py | 2 +- Models/TripodFinger/Components/s90_servo.py | 2 +- Models/TripodFinger/TripodFinger.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GmshTutorial/SurfacePressureConstraint_Accordion.py b/GmshTutorial/SurfacePressureConstraint_Accordion.py index 596d0f85..cbbbd345 100644 --- a/GmshTutorial/SurfacePressureConstraint_Accordion.py +++ b/GmshTutorial/SurfacePressureConstraint_Accordion.py @@ -25,7 +25,7 @@ def createScene(rootNode): bunny.addObject('TetrahedronFEMForceField', template='Vec3', name='FEM', method='large', poissonRatio=0.3, youngModulus=18000) bunny.addObject('BoxROI', name='boxROI', box=[-15, -7, -15, 15, -3, 15], drawBoxes=True, position="@tetras.rest_position", tetrahedra="@container.tetrahedra") - bunny.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e12) + bunny.addObject('FixedWeakConstraint', indices='@boxROI.indices', stiffness=1e12) bunny.addObject('SparseLDLSolver', name='preconditioner') bunny.addObject('LinearSolverConstraintCorrection', solverName='preconditioner') diff --git a/Models/CabledTrunk/CabledTrunk.py b/Models/CabledTrunk/CabledTrunk.py index eea9f42c..583e69c1 100644 --- a/Models/CabledTrunk/CabledTrunk.py +++ b/Models/CabledTrunk/CabledTrunk.py @@ -169,7 +169,7 @@ def createScene(rootNode, config): # Fix base of the Trunk trunk.addObject('BoxROI', name='boxROI', box=[[-20*config.mm, -20*config.mm, -config.d_ext-(config.d_in/2)], [20*config.mm, 20*config.mm, 0]], drawBoxes=True) #trunk.addObject('PartialFixedConstraint', fixedDirections=[1, 1, 1], indices='@boxROI.indices') - trunk.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) + trunk.addObject('FixedWeakConstraint', indices='@boxROI.indices', stiffness=1e10) ################## @@ -334,7 +334,7 @@ def createScene(rootNode, config): corridor = simulation.addChild("Corridor_" + str(i)) corridor.addObject('MechanicalObject', template="Rigid3", scale="0.001", dx="0.0", dy="0.0", dz="0.0") #corridor.addObject("UniformMass", totalMass = 100.0) - corridor.addObject('RestShapeSpringsForceField', stiffness=1e10) + corridor.addObject('FixedWeakConstraint', stiffness=1e10, fixAll=True) contacts_corridor = corridor.addChild("CollisionModel") diff --git a/Models/SensorFinger/SensorFinger.py b/Models/SensorFinger/SensorFinger.py index b6ee21e1..08833c7b 100644 --- a/Models/SensorFinger/SensorFinger.py +++ b/Models/SensorFinger/SensorFinger.py @@ -159,7 +159,7 @@ def createScene(rootNode, config): BoxMargin = 3 BoxCoords = [-(config.Thickness/2+BoxMargin), -BoxMargin, BoxMargin, config.Thickness/2+BoxMargin,config.Height+2*BoxMargin, -BoxMargin] model.addObject('BoxROI', name='boxROI', box=BoxCoords, drawBoxes=True) - model.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) + model.addObject('FixedWeakConstraint', indices='@boxROI.indices', stiffness=1e10) FollowingMONode = model.addChild('FollowingMONode') FollowingMONode.addObject("MechanicalObject", name="FollowingMO", template="Vec3d", position=[0.0, 0, -3.0*config.Length], showObject=True, showObjectScale=20, showColor="0 0 1") diff --git a/Models/SensorFinger4Cavities/SensorFinger4Cavities.py b/Models/SensorFinger4Cavities/SensorFinger4Cavities.py index cf9e1c77..23a8e3ef 100644 --- a/Models/SensorFinger4Cavities/SensorFinger4Cavities.py +++ b/Models/SensorFinger4Cavities/SensorFinger4Cavities.py @@ -193,7 +193,7 @@ def createScene(rootNode, config): BoxMargin = 3 BoxCoords = [-(config.Thickness/2+BoxMargin), -BoxMargin, BoxMargin, config.Thickness/2+BoxMargin,config.Height+2*BoxMargin, -BoxMargin] model.addObject('BoxROI', name='boxROI', box=BoxCoords, drawBoxes=True) - model.addObject('RestShapeSpringsForceField', indices='@boxROI.indices', stiffness=1e10) + model.addObject('FixedWeakConstraint', indices='@boxROI.indices', stiffness=1e10) FollowingMONode = model.addChild('FollowingMONode') FollowingMONode.addObject("MechanicalObject", name="FollowingMO", template="Vec3d", position=[0.0, 0, -3.0*config.Length], showObject=True, showObjectScale=20, showColor="0 0 1") diff --git a/Models/TripodFinger/Components/fixing_box.py b/Models/TripodFinger/Components/fixing_box.py index 2afb8c1f..6ea1f6e9 100644 --- a/Models/TripodFinger/Components/fixing_box.py +++ b/Models/TripodFinger/Components/fixing_box.py @@ -26,6 +26,6 @@ def __init__(self, parent, target, name='FixingBox', c = self.node.addChild('Constraint') target.addChild(c) - c.addObject('RestShapeSpringsForceField', + c.addObject('FixedWeakConstraint', indices=self.node.BoxROI.getData('indices').getLinkPath(), stiffness=1e12) diff --git a/Models/TripodFinger/Components/s90_servo.py b/Models/TripodFinger/Components/s90_servo.py index 709ef0f9..4527e965 100644 --- a/Models/TripodFinger/Components/s90_servo.py +++ b/Models/TripodFinger/Components/s90_servo.py @@ -75,7 +75,7 @@ def init(self): angle = self.addChild('Articulation') angle.addObject('MechanicalObject', name='dofs', template='Vec1', position=[[self.getData('angleIn')]], rest_position=self.getData('angleIn').getLinkPath()) - angle.addObject('RestShapeSpringsForceField', indices=0, stiffness=1e9) + angle.addObject('FixedWeakConstraint', indices=0, stiffness=1e9) angle.addObject('UniformMass', totalMass=0.01) servoWheel = angle.addChild('ServoWheel') diff --git a/Models/TripodFinger/TripodFinger.py b/Models/TripodFinger/TripodFinger.py index fe08f40b..140bd2cd 100644 --- a/Models/TripodFinger/TripodFinger.py +++ b/Models/TripodFinger/TripodFinger.py @@ -419,7 +419,7 @@ def onAnimateBeginEvent(self, dt): def evaluate_torque(self): # As the torque is modeled as a Spring, we compute the torque as k * (theta - theta_0) - k = self.actuator.ServoMotor.Articulation.RestShapeSpringsForceField.stiffness.value + k = self.actuator.ServoMotor.Articulation.FixedWeakConstraint.stiffness.value theta_0 = self.actuator.ServoMotor.Articulation.dofs.rest_position.value theta = self.actuator.ServoMotor.Articulation.dofs.position.value return k * (theta - theta_0)