Home › Forum › SOFA › Programming with SOFA › Cannot animate Geomagic
Tagged: 64_bits, Plugin_Geomagic, SOFA_2006, Windows_10
- This topic has 3 replies, 2 voices, and was last updated 3 years, 10 months ago by Hugo.
-
AuthorPosts
-
7 December 2020 at 06:52 #17959pontasBlocked
Hello everyone.
I’m writing code in C++ to move objects using Geomagic.
I was able to synchronize the object and Geomagic, but the object doesn’t move when I press animate.This is my source code. What is missing…?
Thank you very much.
pontas
Node *LeftSide(Node *root) { const Deriv3 translation1(0, 1, 0); const Deriv3 rotation1(90, -90, 0); sofa::helper::system::PluginManager::getInstance().loadPlugin(“SofaOpenglVisual”); sofa::helper::system::PluginManager::getInstance().init(); sofa::component::collision::DefaultPipeline::SPtr pipeline = sofa::core::objectmodel::New<sofa::component::collision::defaultpipeline>(); pipeline->setName(“DefaultCollisionPipeline”); pipeline->d_depth.setValue(1); root->addObject(pipeline); sofa::component::odesolver::EulerImplicitSolver::SPtr solver = sofa::core::objectmodel::New<sofa::component::odesolver::eulerimplicitsolver>(); solver->setName(“Implicit Euler SolverN”); solver->f_rayleighStiffness.setValue(0.1); solver->f_rayleighMass.setValue(0.1); root->addObject(solver); CGLinearSolver::SPtr linear = sofa::core::objectmodel::New<cglinearsolver>(); linear->setName(“Conjugate gradientN”); linear->templateName(“GraphScattered”); linear->f_maxIter.setValue(25); //iterations linear->f_smallDenominatorThreshold.setValue(1e-05); linear->f_tolerance.setValue(1e-05); root->addObject(linear); GeomagicDriver::SPtr driver1 = sofa::core::objectmodel::New<geomagicdriver>(); driver1->setName(“GeomagicDevice1”); driver1->d_deviceName.setValue(“LeftSidePhantom”); driver1->d_scale.setValue(1); root->addObject(driver1); Node::SPtr blade1 = root->createChild(“Blade1”); { MechanicalObjectRigid3::SPtr Particles1 = sofa::core::objectmodel::New<mechanicalobjectrigid3>(); Particles1->setName(“Left1”); Particles1->x.setParent(driver1->d_posDevice.getData()); //position coordinates of the degrees of freedom blade1->addObject(Particles1); MechanicalStateControllerRigid3::SPtr controller = sofa::core::objectmodel::New<mechanicalstatecontrollerrigid3>(); controller->f_listening.setValue(true); controller->setMainDirection(sofa::defaulttype::Vector3(-1, 0, 0)); blade1->addObject(controller); MeshObjLoader::SPtr meshLoader1 = sofa::core::objectmodel::New<meshobjloader>(); meshLoader1->setFilename(sofa::helper::system::DataRepository.getFile(“obj/blade_D8L15.obj”)); meshLoader1->load(); meshLoader1->setName(“meshLoader1”); blade1->addObject(meshLoader1); { Node::SPtr CollisionNode1 = sofa::modeling::createEulerSolverNode(blade1, “CollisionNode1”); MeshObjLoader::SPtr meshLoader1 = sofa::core::objectmodel::New</meshobjloader><meshobjloader>(); meshLoader1->setFilename(sofa::helper::system::DataRepository.getFile(“obj/blade_D8L15.obj”)); meshLoader1->load(); meshLoader1->setName(“meshLoader1”); CollisionNode1->addObject(meshLoader1); blade1->addObject(meshLoader1); MeshTopology::SPtr Mesh1 = sofa::core::objectmodel::New<meshtopology>(); Mesh1->setName(“Mesh1”); Mesh1->setSrc(“@” + meshLoader1->getName(), meshLoader1.get()); CollisionNode1->addObject(Mesh1); blade1->addObject(Mesh1); } { Node::SPtr VisualNode1 = sofa::modeling::createEulerSolverNode(blade1, “VisualNode1”); MeshObjLoader::SPtr meshLoader1 = sofa::core::objectmodel::New<meshobjloader>(); meshLoader1->setName(“meshLoader1”); meshLoader1->setFilename(sofa::helper::system::DataRepository.getFile(“obj/blade_D8L15.obj”)); meshLoader1->d_translation.setValue({-5, 0, 0}); meshLoader1->d_rotation.setValue({0, -90, 0}); blade1->addObject(meshLoader1); OglModel::SPtr Objective1 = sofa::core::objectmodel::New<oglmodel>(); Objective1->setName(“Objective1”); Objective1->templateName(“Vec3dTypes”); Objective1->setSrc(“@” + meshLoader1->getName(), meshLoader1.get()); Objective1->setColor(“red”); blade1->addObject(Objective1); RigidMapping3::SPtr visualmapping1 = sofa::core::objectmodel::New<rigidmapping3>(); visualmapping1->setName(“Visual Mapping1”); visualmapping1->setModels(Particles1.get(), Objective1.get()); blade1->addObject(visualmapping1); } } return root; } int main(int argc, char** argv) { sofa::simulation::tree::init(); ArgumentParser argParser(argc, argv); sofa::gui::GUIManager::RegisterParameters(&argParser); argParser.parse(); sofa::gui::initMain(); sofa::gui::GUIManager::Init(argv[0]); sofa::simulation::setSimulation(new sofa::simulation::tree::TreeSimulation()); sofa::simulation::Node::SPtr root = sofa::simulation::tree::getSimulation()->createNewGraph(“root”); root->setGravity(sofa::defaulttype::Vector3(0, 0, 0)); FreeMotionAnimationLoop::SPtr animationloop = sofa::core::objectmodel::New<freemotionanimationloop>(root.get()); root->addObject(animationloop); //Add the objects LeftSide(root.get()); root->setAnimate(false); //init the simulate sofa::simulation::tree::getSimulation()->init(root.get()); //run the main roop sofa::gui::GUIManager::MainLoop(root); sofa::simulation::tree::cleanup(); return 0; }
18 December 2020 at 22:52 #18059HugoKeymasterHi @mckysd5
At the first look, I would bet on the fact that you are using a FreeMotionAnimationLoop without defining any ConstraintCorrection in the scene. See for example the scene: examples/Components/animationloop/FreeMotionAnimationLoop.scn
(note that the PrecomputedConstraintCorrection requires some precomputation that might take time at first step, but several correction method exist)
Best
Hugo
22 December 2020 at 17:01 #18078pontasBlockedHi @Hugo
Thank you for your reply.
I found out that the following line was the cause.
`Particles1->x.setParent(driver1->d_posDevice.getData());It syncs with the initial position, but doesn’t work when animate.
I think because it is not updating the geomagic position.
What do I need to write to get the position of the geomagic after animate and adapt it to the coordinates of the object…?I read soure codes in Geomagic folder including geomagic.cpp, but I couldn’t find the answer…
Thank you very much.
pontas
14 January 2021 at 08:28 #18201HugoKeymasterDear @mckysd5
You are attempting to link the two data. This is indeed done using the setParent function:
mydata1.setParent(&mydata2)
But you have to make sure that the data type (here the Coord, type of DOFs) are the same on both sides. Did you also checked that the value of position is also changing in the GeomagicDriver?
Keep us updated.
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.