diff --git a/examples/python3/actuators/cable.py b/examples/python3/actuators/cable.py index 7b242dd..028e21f 100644 --- a/examples/python3/actuators/cable.py +++ b/examples/python3/actuators/cable.py @@ -45,7 +45,7 @@ def PullingCable(attachedTo=None, # This add a MechanicalObject, a component holding the degree of freedom of our # mechanical modelling. In the case of a cable it is a set of positions specifying # the points where the cable is passing by. - cable.addObject('MechanicalObject', position=cableGeometry, + cable.addObject('MechanicalObject', position=cableGeometry, showIndices="1", rotation=rotation, translation=translation, scale=uniformScale) # Add a CableConstraint object with a name. @@ -70,7 +70,8 @@ def PullingCable(attachedTo=None, # This add a BarycentricMapping. A BarycentricMapping is a key element as it will add a bi-directional link # between the cable's DoFs and the parents's ones so that movements of the cable's DoFs will be mapped # to the finger and vice-versa; - cable.addObject('BarycentricMapping', name="Mapping", mapForces=False, mapMasses=False) + # cable.addObject('BarycentricMapping', name="Mapping", mapForces=False, mapMasses=False) + cable.addObject('RigidMapping', name="Mapping") return cable diff --git a/examples/python3/actuators/step3.py b/examples/python3/actuators/step3.py index 8f54188..5e3206e 100644 --- a/examples/python3/actuators/step3.py +++ b/examples/python3/actuators/step3.py @@ -16,10 +16,6 @@ from splib3.loaders import loadPointListFromFile import os -import numpy - -from numpy import ndarray - from splib3.numerics.quat import Quat path = f'{os.path.dirname(os.path.abspath(__file__))}/mesh/' @@ -52,14 +48,14 @@ # @todo geoParams = BeamGeometryParameters(init_pos=[0., 0., 0.], beamLength=65.5, showFramesObject=1, - nbSection=5, nbFrames=26, buildCollisionModel=0) -physicsParams = BeamPhysicsParameters(beamMass=5., youngModulus= 1.0e8, poissonRatio=0.38, beamRadius=6.2e-1/2., + nbSection=5, nbFrames=26, buildCollisionModel=0) +physicsParams = BeamPhysicsParameters(beamMass=5., youngModulus=1.0e8, poissonRatio=0.38, beamRadius=6.2e-1 / 2., beamLength=65.5) simuParams = SimulationParameters(rayleighStiffness=1.e-3) Params = Parameters(beamGeoParams=geoParams, beamPhysicsParams=physicsParams, simuParams=simuParams) -def createIntermediateNode(parent, rigidCentral=None, baseName="rigidState",rigidIndex=2): +def createIntermediateNode(parent, rigidCentral=None, baseName="rigidState", rigidIndex=2): """ The intermediateRigid construction """ if rigidCentral is None: rigidCentral = [0, 0., 0, 0, 0, 0, 1] @@ -72,7 +68,7 @@ def createIntermediateNode(parent, rigidCentral=None, baseName="rigidState",rigi [0., 0., -2., q2[0], q2[1], q2[2], q2[3]]] intermediateRigid = parent.addChild('intermediateRigid') intermediateRigid.addObject('MechanicalObject', name=baseName, template='Rigid3d', - position=rigidCentral, showObject=True, showObjectScale=0.4) + position=rigidCentral, showObject=True, showObjectScale=0.4) # @TODO add the mass of the disk intermediateRigid.addObject('RigidMapping', name="interRigidMap", index=rigidIndex) @@ -87,6 +83,7 @@ def createIntermediateNode(parent, rigidCentral=None, baseName="rigidState",rigi return intermediateRigid + def loadDisk(parentNode): #### MAPPING of the disks (here some torus) #### ########### diskMapping = parentNode.addChild("diskMapping") @@ -95,39 +92,95 @@ def loadDisk(parentNode): diskMapping.addObject('RigidMapping', name="diskMap") -def createRigidDisk(parentNode): # @todo add a parameter for the number of disk +def create_cable_points(): + """ + This function creates cable points based on the given parameters. + + Returns: + cable_base_state (list): A list of base states for the cable. + cable_3d_state (list): A list of 3D positions for the cable. + """ + num_segments = 14 + norm_length = geoParams.beamLength / num_segments + + cable_base_state = [] + cable_3d_state = [] + + for z in [1.7, -1.7, -2]: + base_state = [] + pos_3d = [] + + for i in range(num_segments + 1): + x = i * norm_length + if z == -2: + base_state.append([x, 0., z, 0., 0., 0., 1.]) + # pos_3d.append([x, 0., z]) + pos_3d.append([x, 0., 0]) + else: + base_state.append([x, z, 1., 0., 0., 0., 1.]) + # pos_3d.append([x, z, 1.]) + pos_3d.append([x, 0, 0]) + + cable_base_state.append(base_state) + cable_3d_state.append(pos_3d) + + return cable_base_state, cable_3d_state + + +def createRigidDisk(parentNode): # @todo add a parameter for the number of disk """ Create the rigid disk nodes """ for i in range(1, 14): """ Create the rigid disk nodes """ createIntermediateNode(parentNode, rigidCentral=[0, 0., 0, 0, 0, 0, 1], - baseName=f"rigidState{i}", rigidIndex=i*2) + baseName=f"rigidState{i}", rigidIndex=i * 2) + + +rotation = [0.0, 0.0, 0.0] +translation = [0.0, 0.0, 0.0] +pullPointLocation = [0.0, 0.0, 0.0] +youngModulus = 18000 +valueType = 'position' + -rotation=[0.0, 0.0, 0.0] -translation=[0.0, 0.0, 0.0] -pullPointLocation=[0.0, 0.0, 0.0] -youngModulus=18000 -valueType='position' def createScene(rootNode): addHeader(rootNode) rootNode.gravity = [0., -9.81, 0.] stemNode = addSolverNode(rootNode, name="stemNode") cosserat = stemNode.addChild(CosseratBase(parent=stemNode, params=Params)) - # create the rigid disk node createRigidDisk(cosserat.cosseratFrame) - PullingCable(stemNode, - "PullingCable", + cableBaseState, cable3DState = create_cable_points() + + cable1Node = stemNode.addChild("cable1Node") + cable1Node.addObject('MechanicalObject', name="cable1Pos", template='Rigid3d', position=cableBaseState[0], + showObject=True, showObjectScale=2) + PullingCable(cable1Node, "PullingCable", pullPointLocation=pullPointLocation, rotation=rotation, translation=translation, - cableGeometry=loadPointListFromFile(os.path.join(path, "../cable.json")), + cableGeometry=cable3DState[0], valueType=valueType) - return - - - + cable2Node = stemNode.addChild("cable2Node") + cable2Node.addObject('MechanicalObject', name="cable2Pos", template='Rigid3d', position=cableBaseState[1], + showObject=True, showObjectScale=2) + PullingCable(cable2Node, "PullingCable", + pullPointLocation=pullPointLocation, + rotation=rotation, + translation=translation, + cableGeometry=cable3DState[1], + valueType=valueType) + cable3Node = stemNode.addChild("cable3Node") + cable3Node.addObject('MechanicalObject', name="cable3Pos", template='Rigid3d', position=cableBaseState[2], + showObject=True, showObjectScale=2) + PullingCable(cable3Node, "PullingCable", + pullPointLocation=pullPointLocation, + rotation=rotation, + translation=translation, + cableGeometry=cable3DState[2], + valueType=valueType) + return diff --git a/examples/python3/cosserat/cosserat-tuto.html b/examples/python3/cosserat/cosserat-tuto.html index 4144662..f55ed12 100644 --- a/examples/python3/cosserat/cosserat-tuto.html +++ b/examples/python3/cosserat/cosserat-tuto.html @@ -1,115 +1,115 @@ - - - - - - - tripod-tuto - - - - - -

- - - - - - - \ No newline at end of file + @media print { + code.sourceCode { white-space: pre-wrap; } + a.sourceLine { text-indent: -1em; padding-left: 1em; } + } + pre.numberSource a.sourceLine + { position: relative; left: -4em; } + pre.numberSource a.sourceLine::before + { content: attr(title); + position: relative; left: -1em; text-align: right; vertical-align: baseline; + border: none; pointer-events: all; display: inline-block; + -webkit-touch-callout: none; -webkit-user-select: none; + -khtml-user-select: none; -moz-user-select: none; + -ms-user-select: none; user-select: none; + padding: 0 4px; width: 4em; + color: #aaaaaa; + } + pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } + div.sourceCode + { } + @media screen { + a.sourceLine::before { text-decoration: underline; } + } + code span.al { color: #ff0000; font-weight: bold; } /* Alert */ + code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ + code span.at { color: #7d9029; } /* Attribute */ + code span.bn { color: #40a070; } /* BaseN */ + code span.bu { } /* BuiltIn */ + code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ + code span.ch { color: #4070a0; } /* Char */ + code span.cn { color: #880000; } /* Constant */ + code span.co { color: #60a0b0; font-style: italic; } /* Comment */ + code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ + code span.do { color: #ba2121; font-style: italic; } /* Documentation */ + code span.dt { color: #902000; } /* DataType */ + code span.dv { color: #40a070; } /* DecVal */ + code span.er { color: #ff0000; font-weight: bold; } /* Error */ + code span.ex { } /* Extension */ + code span.fl { color: #40a070; } /* Float */ + code span.fu { color: #06287e; } /* Function */ + code span.im { } /* Import */ + code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ + code span.kw { color: #007020; font-weight: bold; } /* Keyword */ + code span.op { color: #666666; } /* Operator */ + code span.ot { color: #007020; } /* Other */ + code span.pp { color: #bc7a00; } /* Preprocessor */ + code span.sc { color: #4070a0; } /* SpecialChar */ + code span.ss { color: #bb6688; } /* SpecialString */ + code span.st { color: #4070a0; } /* String */ + code span.va { color: #19177c; } /* Variable */ + code span.vs { color: #4070a0; } /* VerbatimString */ + code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ + + + + +

+ + + + + + + \ No newline at end of file diff --git a/examples/python3/useful/header.py b/examples/python3/useful/header.py index 8fe2d21..258a8bc 100644 --- a/examples/python3/useful/header.py +++ b/examples/python3/useful/header.py @@ -15,7 +15,6 @@ from stlib3.physics.deformable import ElasticMaterialObject from stlib3.physics.constraints import FixedBox -import numpy as np import os