Home › Forum › SOFA › Programming with SOFA › [SOLVED] A Problem About How to Move A Fixed Rigid Object in C++ Project?
Tagged: 32_bits, SOFA_1509, Windows_10
- This topic has 3 replies, 2 voices, and was last updated 7 years, 4 months ago by Hugo.
-
AuthorPosts
-
22 June 2017 at 08:37 #9343wq57fanBlocked
Hello,
I’m using SOFA in my simulation project.
I create a scene including some fixed rigid objects which use .obj files and collision models like TPOINTMODELS, TLINEMODELS, TTRIANGLEMODELS. And my tool could have collision with the objects using haptic device.
Now, I wish these rigid bodies could fall down with gravity so that my tool could move them. By referencing tutorials in MODELER, I tried using RIGIDMAPPING, but something goes wrong.
My question is: is there any other examples that could make a fixed rigid body falling down with gravity or make my haptic tool could move an object in C++?
Thank you!23 June 2017 at 17:59 #9349HugoKeymasterHi wq57fan,
The Modeler is considered as deprecated. Moreover, be careful, you write that you want to make a fixed rigid body fall under gravity, this won’t obviously happen if your object is fixed !
To make a rigid body fall, you can write :
<Node name="RigidBody"> <EulerImplicit /> <CGLinearSolver iterations="50" tolerance="1e-09" threshold="1e-09" /> <MeshGmshLoader name="meshLoader" filename="mesh/liver.msh" /> <MechanicalObject template="Rigid" src="@ meshLoader" /> <UniformMass totalMass="1" /> </Node>
About making your haptic tool move, I would advise you to have a look to the example scene associated to the Geomagic plugin : applications/plugins/Geomagic/scenes/Geomagic-FEMLiver.scn.
Let us know if this helps.
Hugo
26 June 2017 at 13:01 #9366wq57fanBlockedHi Hugo,
I tried your way, and it works in Modeler.However, in my C++ project, there are two main problems existing:
1.The rigid body cannot detect the collision.
2.The rigid body cannot fall down with gravity.
Here is a part of my code:
nodeFixed = chain->createChild("Fixed"); sofa::component::odesolver::EulerImplicitSolver::SPtr solver = sofa::core::objectmodel::New<sofa::component::odesolver::EulerImplicitSolver>(); solver->setName("Euler Implicit"); solver->f_rayleighStiffness.setValue(0.1); solver->f_rayleighMass.setValue(0.1); nodeFixed->addObject(solver); typedef sofa::component::linearsolver::CGLinearSolver< sofa::component::linearsolver::GraphScatteredMatrix, sofa::component::linearsolver::GraphScatteredVector> CGLinearSolverGraph; CGLinearSolverGraph::SPtr linear = sofa::core::objectmodel::New<CGLinearSolverGraph>(); linear->setName("Conjugate Gradient"); //solver->setName("Conjugate Gradient"); linear->f_maxIter.setValue(25); //iteration maxi for the CG linear->f_smallDenominatorThreshold.setValue(1e-05); linear->f_tolerance.setValue(1e-05); nodeFixed->addObject(linear); sofa::component::loader::MeshGmshLoader::SPtr loaderRigid = sofa::core::objectmodel::New<sofa::component::loader::MeshGmshLoader>(); loaderRigid->setName("Msh Loader"); loaderRigid->setFilename(sofa::helper::system::DataRepository.getFile("mesh/liver.msh")); loaderRigid->load(); nodeFixed->addObject(loaderRigid); dofRigid = sofa::core::objectmodel::New<MechanicalObjectRigid3>(); dofRigid->setName("Fixed Object"); dofRigid->setSrc("@"+loaderRigid->getName(), loaderRigid.get()); dofRigid->setTranslation(0,0,0); dofRigid->setRotation(0,0,0); nodeFixed->addObject(dofRigid); UniformMassRigid3::SPtr uniMassFixed = sofa::core::objectmodel::New<UniformMassRigid3>(); uniMassFixed->setName("Uni Mass"); uniMassFixed->setMass(1); uniMassFixed->setTotalMass(1); nodeFixed->addObject(uniMassFixed); sofa::component::container::Node* nodeFixedVisual = nodeFixed->createChild("Visual"); visualFixed = sofa::core::objectmodel::New<sofa::component::visualmodel::OglModel>(); visualFixed->setName("visual"); visualFixed->setFilename(sofa::helper::system::DataRepository.getFile(visualModelName1)); visualFixed->setColor("gray"); visualFixed->setTranslation(0,0,0); visualFixed->setRotation(0,0,0); nodeFixedVisual->addObject(visualFixed); visualModel[0] = visualFixed.get(); const std::string refVisual3 = "@" + visualFixed->getName(); //output const std::string refDof3 = "@../" + dofRigid->getName(); //input RigidMappingRigid3d_to_Ext3f::SPtr mapping5 = sofa::core::objectmodel::New<RigidMappingRigid3d_to_Ext3f>(); mapping5->setModels(dofRigid.get(), visualFixed.get()); mapping5->setName("Mapping Visual"); mapping5->setPathInputObject(refDof3); mapping5->setPathOutputObject(refVisual3); nodeFixedVisual->addObject(mapping5);
I don’t know that if it is because some of my parameters are wrong.
Thanks for your help.
10 July 2017 at 13:33 #9777HugoKeymasterHi wq57fan,
the C++ code you share does not include any MechanicalObject. Is that normal ?
To make your object fall under gravity, I see two issues: the MechanicalObject is missing and the gravity needs to be specified (you can set the gravity in the rootNode as a parameter).For collision detection, you need to specify the collision topology. You can have a look at the scene examples/Components/collisionTriangleModel.scn which illustrate this well.
Let me know if this helps.
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.