Home › Forum › SOFA › Programming with SOFA › [SOLVED] How to make a PythonScript controller with SofaPython3
Tagged: 64_bits, Linux_ubuntu, Plugin_other, SOFA_2006, SofaPython3
- This topic has 9 replies, 4 voices, and was last updated 3 years, 6 months ago by nhnhan.
-
AuthorPosts
-
3 December 2020 at 13:06 #17829Pasquale94Blocked
Hello everyone, I recently installed SofaPython3 in my sofa version (20.06 on Ubuntu 20.04), so I am building my first simulation in python3 and i have difficulties into code the Python controller.
I already read this interesting topic on the forum, and I understand that many things changed, like the event commands(and thi is clear) and also the way which the object from the scene are called (this is not so clear to me). In python2.7 I written this simple controller to inflate automatically a pneunet finger, I would like to know what would be the specular code using Python3:def initGraph(self, node): self.node = node self.finger1Node=self.node.getChild('finger') self.pressureConstraint1Node = self.finger1Node.getChild('cavity') self.MecaObject1=self.finger1Node.getObject('tetras') def onBeginAnimationStep(self,dt): self.dt = self.node.findData('dt').value incr = self.dt*1000.0 self.pressureConstraint1 = self.pressureConstraint1Node.getObject('SurfacePressureConstraint') pressureValue = self.pressureConstraint1.findData('value').value[0][0] + 0.01 if pressureValue > 1.29: pressureValue = 1.29 self.pressureConstraint1.findData('value').value = str(pressureValue) print pressureValue return 0 def onEndAnimationStep(self,dt): return 0
So how can I call the objects from the scene in the controller? How I can get access to the data?
Kind regards,
Pasquale6 December 2020 at 17:12 #17958Pasquale94Blockedhello everyone!
I feel stupid but I resolved by myself ahaha.
I will close the topic
16 December 2020 at 06:24 #18033ArthurBlockedDear @Pasquale94 ,
I am having the same issue and I was wondering if you would post your solution?
I used to change the pressures in 2.7 with:
self.pressureConstraint1.findData(‘value’).value = str(pressureValue)but now when I try to do this with SofaPython3, I get an error like this:
terminate called after throwing an instance of ‘pybind11::error_already_set’
what(): RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)My exact code is posted below: see line 145 in the animate function.
Best,
Arthurimport Sofa import SofaRuntime import sys import os #from stlib3.physics.constraints import FixedBox from stlib3.scene import Scene from splib.animation import AnimationManager, addAnimation #from elasticmaterialobject import ElasticMaterialObject #from stlib3.physics.deformable.elasticmaterialobject import ElasticMaterialObject #from softrobots.actuators import PneumaticCavity import time import math import numpy as np import timeit path = os.path.dirname(os.path.abspath(__file__)) + '/' meshpath = path+"mesh/" # scene helper function, defining materials and constraints def createSceneReal(rootNode, dt): # this sets gravity and dt in the simulator rootNode = Scene(rootNode, gravity=[0.0, -0.0, 0], dt=dt) # marks a required plugin and some visual style stuff rootNode.addObject('RequiredPlugin', pluginName='SoftRobots') rootNode.addObject('VisualStyle', displayFlags='showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe') # animation loop used for legrangian constraints rootNode.addObject('FreeMotionAnimationLoop') # linear solver (with parameters from example file) rootNode.addObject('GenericConstraintSolver', name='gencs', maxIterations='500', printLog='0', tolerance='0.0000001') # set color of background, just visual style rootNode.addObject('BackgroundSetting', color='0 0.168627 0.211765') # YM of the material. All in kg / m / s volumeMeshFileName=meshpath+"two_cell_robot_solid.msh" name="two_cell_robot" rotation=[0.0, 0.0, 0.0] translation=[0.0, 0.0, 0.0] scale=[1.0, 1.0, 1.0] surfaceMeshFileName=None collisionMesh=None withConstrain=True surfaceColor=[1.0, 1.0, 1.0] poissonRatio=0.3 youngModulus=1800 totalMass=1.0 solver=None # elestic material from prefab '''two_cell_robot = ElasticMaterialObject(name="two_cell_robot", attachedTo=rootNode, volumeMeshFileName=meshpath+"two_cell_robot_solid.msh", surfaceMeshFileName=None, youngModulus=YoungModulus, withConstrain=True, totalMass=1.0, translation=None, rotaiton=None, scale=[1.,1.0,1.0], collisionMesh=None, surfaceColor=None) ''' two_cell_robot = rootNode.createChild( 'two_cell_robot' ) two_cell_robot.addObject('MeshGmshLoader', name='loader', filename=volumeMeshFileName, rotation=rotation, translation=translation, scale3d=scale) two_cell_robot.addObject( 'EulerImplicitSolver', name='integration') two_cell_robot.addObject( 'SparseLDLSolver', name="solver") two_cell_robot.addObject( 'TetrahedronSetTopologyContainer', src="@loader", name="container") two_cell_robot.addObject( 'MechanicalObject', template='Vec3d', name='dofs') #topology="@container", two_cell_robot.addObject( 'UniformMass', totalMass=totalMass, name='mass') two_cell_robot.addObject( 'TetrahedronFEMForceField', template='Vec3d', method='large', name='forcefield', poissonRatio=poissonRatio, youngModulus=youngModulus) two_cell_robot.addObject( 'LinearSolverConstraintCorrection', template='Vec3d', solverName='solver') #two_cell_robot.addObject( 'FixedConstraint', template='Vec3d', topology="@container" ) #vm = two_cell_robot.createChild( 'VisualModel' ) #vm.addObject( 'MeshSTLLoader', template='') #vm.addObject( 'OglModel', template='Vec3d', topology="@/two_cell_robot/container" ) #vm.addObject( 'BarycentricMapping', template='Vec3d,Vec3d', input="@../" , output="@./" ) # impose the constraints TODO: get these constraints so I can add gravity. #two_cell_robot.addObject("FixedConstraint", indices=fixed_const_str) # create the two actuators cavity1 = two_cell_robot.createChild('cavity1') cavity1.addObject('MeshSTLLoader', name='loader', filename=meshpath + "two_cell_robot_cell1.stl", translation="0 0 0") cavity1.addObject('Mesh', src='@loader', name='topo') cavity1.addObject('MechanicalObject', name='cavity') cavity1.addObject('SurfacePressureConstraint', name="SurfacePressureConstraint", template='Vec3d', value="0.6001", triangles='@topo.triangles', visualization='0', showVisuScale='0.0002', valueType="pressure") cavity1.addObject('BarycentricMapping', name='mapping', mapForces='false', mapMasses='false') cavity2 = two_cell_robot.createChild('cavity2') cavity2.addObject('MeshSTLLoader', name='loader', filename=meshpath + "two_cell_robot_cell2.stl", translation="0 0 0") cavity2.addObject('Mesh', src='@loader', name='topo') cavity2.addObject('MechanicalObject', name='cavity') cavity2.addObject('SurfacePressureConstraint', name="SurfacePressureConstraint", template='Vec3d', value="0.0001", triangles='@topo.triangles', visualization='0', showVisuScale='0.0002', valueType="pressure") cavity2.addObject('BarycentricMapping', name='mapping', mapForces='false', mapMasses='false') # two_cell_robot visualization two_cell_robotVisu = two_cell_robot.createChild('visu') two_cell_robotVisu.addObject('TriangleSetTopologyContainer', name='container') two_cell_robotVisu.addObject('TriangleSetTopologyModifier') #two_cell_robotVisu.addObject('TriangleSetTopologyAlgorithms', template='Vec3d') two_cell_robotVisu.addObject('TriangleSetGeometryAlgorithms', template='Vec3d') two_cell_robotVisu.addObject('Tetra2TriangleTopologicalMapping', name='Mapping', input="@../container", output="@container") two_cell_robotVisu.addObject('OglModel', template='ExtVec3f', color='0.3 0.2 0.2 0.6', translation=translation) two_cell_robotVisu.addObject('IdentityMapping') return two_cell_robot # "Main" function that runSofa uses to build the scene. def createScene(rootNode): dt = 0.001 # set the time step for the simulator # set length scale ''' # information about the output. info_arr = np.array([float(length_scale), 0, dt, num_nodes]) print "info array ", info_arr print "number of nodes", num_nodes, " num end nodes ", len(fixed_const_lst), " num mid nodes ", len(middle_nodes_lst) ''' # simulation timer start = timeit.default_timer() #animation function called at each step def my_animation(target, factor): factor = factor*2*np.pi pressureValue1 = target["two_cell_robot.cavity1.SurfacePressureConstraint.value"].getValueString() print(pressureValue1) pressureValue1 = float(pressureValue1) target.two_cell_robot.cavity1.SurfacePressureConstraint.findData('value').value = str(0.1) print(dir(target.two_cell_robot.cavity1.SurfacePressureConstraint)) print(target.two_cell_robot.cavity1.SurfacePressureConstraint.pressure.value) target.two_cell_robot.cavity1.SurfacePressureConstraint.findData('value').value = str(10.0) print(factor) # the exit func is called when duration of time has elapsed, it marks the simulation time # saves it, and saves the collected data to an array. And exits the simulation with sys exit def ExitFunc(target, factor): # save the various data. runtime = timeit.default_timer() - start print("runtime", runtime) sys.exit(0) def getObject(self, name): return name # this is the Sofa animation function we pass it our animation function # and along with the exit function. createSceneReal(rootNode, dt) AnimationManager(rootNode) addAnimation(my_animation, {"target": rootNode}, duration=2.0, mode="once", onDone=ExitFunc) return rootNode
16 December 2020 at 09:29 #18034jnbrunetModeratorHi @amackeith
Can you post the complete output of the error so that we can see the call stack (history of called functions until the error)?
J-N
16 December 2020 at 18:43 #18043ArthurBlockedHi @jnbrunet,
The full output is posted below, the whole example is posted here in https://github.com/ripl-ttic/SofaFramework-Docker/tree/python3 [Edit: I inadvertently pushed to this branch this afternoon, but for record keeping as well, look at commit 4a975fc53a215f547d353917d990fd01d8f0428b for the example][NB: this is not the master branch].
The full environment is specified in Dockerfile, you can build with ./build.sh and then run the environment with ./launch.sh, or x-docker_launch.sh, once you are in run the example with “runSofa block_test.py –start”.
sofauser@carbon:~/workdir/simple_control_policy$ runSofa block_test.py --start [INFO] [runSofa] PluginRepository paths = /builds/build/master/lib:/builds/build/master/plugins [INFO] [runSofa] DataRepository paths = /builds/src/share:/builds/src/examples [INFO] [runSofa] GuiDataRepository paths = /builds/src/applications/projects/runSofa/resources:/builds/src/modules/SofaGuiQt/src/sofa/gui/qt/resources [INFO] [runSofa] Loading automatically plugin list in /builds/build/master/lib/plugin_list.conf [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralVisual.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGraphComponent.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralMeshCollision.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaBoundaryCondition.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralAnimationLoop.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralDeformable.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralEngine.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralExplicitOdeSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralImplicitOdeSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralLinearSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralRigid.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralObjectInteraction.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralSimpleFem.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralTopology.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaTopologyMapping.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaUserInteraction.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaConstraint.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaGeneralLoader.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaSparseSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaPreconditioner.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaHaptics.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaValidation.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaDenseSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaNonUniformFem.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaOpenglVisual.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscTopology.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscExtra.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscForceField.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscEngine.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscSolver.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscFem.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscMapping.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaExporter.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libCImgPlugin.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaMiscCollision.so [INFO] [SofaPython3] Initializing with python version 3.7.5 (default, Nov 7 2019, 10:50:52) [GCC 8.3.0] [INFO] [SofaPython3] Registering a scene loader for [.py, .py3, .pyscn, .py3scn] files. [INFO] [SofaPython3] Shared library name is 'libpython3.7m.so' [INFO] [SofaPython3] Intializing python [INFO] [SofaPython3] Added '/builds/build/master/python3/site-packages' to sys.path [INFO] [SofaPython3] Added '/builds/src/applications/plugins/SofaTest/python' to sys.path [INFO] [SofaPython3] Added '/builds/build/master/lib/python3/site-packages' to sys.path [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSofaPython3.so libGL error: failed to open /dev/dri/card0: Permission denied libGL error: failed to load driver: nouveau Warning: Setting a new default format with a different version or profile after the global shared context is created may cause issues with context sharing. The constructor with a QGLFormat is deprecated, use the regular contructor instead. [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSTLIB.so [INFO] [PluginManager] Loaded plugin: /builds/build/master/lib/libSoftRobots.so [DEPRECATED] [DAGNode(root)] The Node.createChild method is deprecated since sofa 19.06.To remove this warning message, use 'addChild'. [DEPRECATED] [DAGNode(two_cell_robot)] The Node.createChild method is deprecated since sofa 19.06.To remove this warning message, use 'addChild'. [DEPRECATED] [DAGNode(two_cell_robot)] The Node.createChild method is deprecated since sofa 19.06.To remove this warning message, use 'addChild'. [DEPRECATED] [DAGNode(two_cell_robot)] The Node.createChild method is deprecated since sofa 19.06.To remove this warning message, use 'addChild'. [WARNING] [OglModel(OglModel)] Template ExtVec3f incorrect, used Vec3d [INFO] [SceneCheckerVisitor] Validating node "root" with checks: [SceneCheckDuplicatedName, SceneCheckMissingRequiredPlugin, SceneCheckUsingAlias] [WARNING] [SceneCheckMissingRequiredPlugin] This scene is using component defined in plugins but is not importing the required plugins. Your scene may not work on a sofa environment with different pre-loaded plugins. To fix your scene and remove this warning you just need to cut & paste the following lines at the begining of your scene (if it is a .scn): <RequiredPlugin pluginName='SofaConstraint'/> <!-- Needed to use components [FreeMotionAnimationLoop, GenericConstraintSolver, LinearSolverConstraintCorrection, ]--> <RequiredPlugin pluginName='SofaOpenglVisual'/> <!-- Needed to use components [OglModel, ]--> <RequiredPlugin pluginName='SofaSparseSolver'/> <!-- Needed to use components [SparseLDLSolver, ]--> <RequiredPlugin pluginName='SofaTopologyMapping'/> <!-- Needed to use components [Tetra2TriangleTopologicalMapping, ]--> [WARNING] [SceneCheckUsingAlias] This scene is using hard coded aliases. Aliases can be very confusing, use with caution. - MeshTopology: 2 created with alias "Mesh" [INFO] [SceneCheckerVisitor] Finished validating node "root". [WARNING] [SurfacePressureConstraint(SurfacePressureConstraint)] The field named 'visualization' is now deprecated. To remove this warning message, the field 'visualization' should be replaced by the field 'drawPressure'. [WARNING] [SurfacePressureConstraint(SurfacePressureConstraint)] The field named 'showVisuScale' is now deprecated. To remove this warning message, the field 'showVisuScale' should be replaced by the field 'drawScale'. [WARNING] [SurfacePressureConstraint(SurfacePressureConstraint)] The field named 'visualization' is now deprecated. To remove this warning message, the field 'visualization' should be replaced by the field 'drawPressure'. [WARNING] [SurfacePressureConstraint(SurfacePressureConstraint)] The field named 'showVisuScale' is now deprecated. To remove this warning message, the field 'showVisuScale' should be replaced by the field 'drawScale'. 0.6001 terminate called after throwing an instance of 'pybind11::error_already_set' what(): RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details) At: block_test.py(145): my_animation /builds/build/master/lib/python3/site-packages/splib/animation/animate.py(88): update /builds/build/master/lib/python3/site-packages/splib/animation/animate.py(133): computeAnimations /builds/build/master/lib/python3/site-packages/splib/animation/animate.py(126): onAnimateBeginEvent ########## SIG 6 - SIGABRT: usually caused by an abort() or assert() ########## -> /builds/build/master/lib/libSofaHelper.so.20.06.99(sofa::helper::BackTrace::dump()+0x20) [0x7feab0516a70] -> /builds/build/master/lib/libSofaHelper.so.20.06.99(sofa::helper::BackTrace::sig(int)+0x358) [0x7feab0517008] -> /lib/x86_64-linux-gnu/libc.so.6(+0x3f040) [0x7feaad853040] -> /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7) [0x7feaad852fb7] -> /lib/x86_64-linux-gnu/libc.so.6(abort+0x141) [0x7feaad854921] -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8c957) [0x7feaae466957] -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92ae6) [0x7feaae46cae6] -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92b21) [0x7feaae46cb21] -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92d54) [0x7feaae46cd54] -> /builds/build/master/lib/python3/site-packages/Sofa/Core.cpython-37m-x86_64-linux-gnu.so(+0x9bf75) [0x7fea6adddf75] -> /builds/build/master/lib/python3/site-packages/Sofa/Core.cpython-37m-x86_64-linux-gnu.so(+0x9b1ff) [0x7fea6addd1ff] -> /builds/build/master/lib/python3/site-packages/Sofa/Core.cpython-37m-x86_64-linux-gnu.so(+0x9b5ab) [0x7fea6addd5ab] -> /builds/build/master/lib/libSofaSimulationCore.so.20.06.99(void sofa::simulation::Visitor::for_each<sofa::simulation::PropagateEventVisitor, sofa::simulation::Node, sofa::simulation::Node::Sequence<sofa::core::objectmodel::BaseObject, true>, sofa::core::objectmodel::BaseObject>(sofa::simulation::PropagateEventVisitor*, sofa::simulation::Node*, sofa::simulation::Node::Sequence<sofa::core::objectmodel::BaseObject, true> const&, void (sofa::simulation::PropagateEventVisitor::*)(sofa::simulation::Node*, sofa::core::objectmodel::BaseObject*))+0xf9) [0x7feab1aa5519] -> /builds/build/master/lib/libSofaSimulationCore.so.20.06.99(sofa::simulation::PropagateEventVisitor::processNodeTopDown(sofa::simulation::Node*)+0x20) [0x7feab1aa53d0] -> /builds/build/master/lib/libSofaSimulationGraph.so.20.06.99(sofa::simulation::graph::DAGNode::executeVisitorTopDown(sofa::simulation::Visitor*, std::__cxx11::list<sofa::simulation::graph::DAGNode*, std::allocator<sofa::simulation::graph::DAGNode*> >&, std::map<sofa::simulation::graph::DAGNode*, sofa::simulation::graph::DAGNode::StatusStruct, std::less<sofa::simulation::graph::DAGNode*>, std::allocator<std::pair<sofa::simulation::graph::DAGNode* const, sofa::simulation::graph::DAGNode::StatusStruct> > >&, sofa::simulation::graph::DAGNode*)+0x392) [0x7feac3038122] -> /builds/build/master/lib/libSofaSimulationGraph.so.20.06.99(sofa::simulation::graph::DAGNode::doExecuteVisitor(sofa::simulation::Visitor*, bool)+0x19d) [0x7feac303761d] -> /builds/build/master/lib/libSofaConstraint.so(sofa::component::animationloop::FreeMotionAnimationLoop::step(sofa::core::ExecParams const*, double)+0xb97) [0x7feaa2bd91b7] -> /builds/build/master/lib/libSofaSimulationCore.so.20.06.99(sofa::simulation::Simulation::animate(sofa::simulation::Node*, double)+0x58) [0x7feab1aa71d8] -> /builds/build/master/lib/libSofaGuiQt.so.20.06.99(sofa::gui::qt::RealGUI::step()+0xca) [0x7feac26f16da] -> /opt/qt512/lib/libQt5Core.so.5(QMetaObject::activate(QObject*, int, int, void**)+0x865) [0x7feab57523f5] -> /opt/qt512/lib/libQt5Core.so.5(QTimer::timeout(QTimer::QPrivateSignal)+0x37) [0x7feab575f2d7] -> /opt/qt512/lib/libQt5Core.so.5(QTimer::timerEvent(QTimerEvent*)+0x28) [0x7feab575f638] -> /opt/qt512/lib/libQt5Core.so.5(QObject::event(QEvent*)+0x9b) [0x7feab5752f1b] -> /opt/qt512/lib/libQt5Widgets.so.5(QApplicationPrivate::notify_helper(QObject*, QEvent*)+0x9c) [0x7feab61cee4c] -> /opt/qt512/lib/libQt5Widgets.so.5(QApplication::notify(QObject*, QEvent*)+0x2f0) [0x7feab61d6430] -> /opt/qt512/lib/libQt5Core.so.5(QCoreApplication::notifyInternal2(QObject*, QEvent*)+0x118) [0x7feab57227f8] -> /opt/qt512/lib/libQt5Core.so.5(QTimerInfoList::activateTimers()+0x409) [0x7feab577ed99] -> /opt/qt512/lib/libQt5Core.so.5(+0x2ef561) [0x7feab577f561] -> /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x2e7) [0x7feaa92b5417] -> /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x4c650) [0x7feaa92b5650] -> /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7feaa92b56dc] -> /opt/qt512/lib/libQt5Core.so.5(QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)+0x5f) [0x7feab577f92f] -> /opt/qt512/lib/libQt5Core.so.5(QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)+0x13a) [0x7feab5720a4a] -> /opt/qt512/lib/libQt5Core.so.5(QCoreApplication::exec()+0x90) [0x7feab5729c50] -> /builds/build/master/lib/libSofaGuiQt.so.20.06.99(sofa::gui::qt::RealGUI::mainLoop()+0x162) [0x7feac26e7bd2] -> /builds/build/master/lib/libSofaGuiCommon.so.20.06.99(sofa::gui::GUIManager::MainLoop(boost::intrusive_ptr<sofa::simulation::Node>, char const*)+0x60) [0x7feac221ed20] -> runSofa() [0x413740] -> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7feaad835bf7] -> runSofa() [0x40ea2a] Aborted (core dumped)
17 December 2020 at 12:40 #18048jnbrunetModeratorHi @amackeith,
Can you try to change the following line:
target.two_cell_robot.cavity1.SurfacePressureConstraint.findData('value').value = str(0.1)
To
with target.two_cell_robot.cavity1.SurfacePressureConstraint.value.writeableArray() as wa: wa[0] = 0.1
J-N
17 December 2020 at 19:12 #18050ArthurBlockedThanks @jnbrunet,
that has done it!
On a side note, I was wondering if there is an established way to reset a sofa simulation in SofaPython3, I would want it to have the same effect as, the “Reset Scene” button does in the gui – all the objects go back to their original locations, the clock is set to zero, and the python controllers are reloaded and run again.
Thank you again!
Arthur
18 December 2020 at 10:24 #18051jnbrunetModeratorHi @amackeith ,
You could try the following:
import Sofa.Simulation # (...) # At some point in your script, reset the scene Sofa.Simulation.reset(root)
This will launch a reset visitor on the scene graph starting from the root node, which should be the same as hitting the reset button in the GUI.
J-N
22 December 2020 at 13:51 #18077Pasquale94BlockedHello guys,
Sorry for the late reply @amackeith but I started my Christmas holydays some days ago, I hope that the problem is resolved.Merry Christmas everyone.
Pasquale4 May 2021 at 05:15 #19355nhnhanBlockedDear @jnbrunet,
I just wonder that could I able to execute the “reset scene” function using sofapython 2.7?? otherwise, I want to recover the shape of a deformed object back to the original one after the end of the interaction. Is there any other solution for this purpose?
Appreciate for any help
Nhan -
AuthorPosts
- You must be logged in to reply to this topic.