void SofaHAPIHapticsDevice::bwdInit() { sofa::core::objectmodel::BaseContext* context = this->getContext(); vector<ForceFeedback*> ffs; context->get<ForceFeedback>(&ffs, sofa::core::objectmodel::BaseContext::SearchRoot); sout << ffs.size()<<" ForceFeedback objects found:"; for ( size_t i= 0; i < ffs.size(); ++i ) { sout << " " << ffs[i]->getContext()->getName()<<"/"<<ffs[i]->getName(); } sout << sendl; setDataValue(); setForceFeedbacks(ffs); if(!device.get() && !initDevice()) { serr<<"NO DEVICE"<<sendl; releaseDevice(); } else { if (isToolControlled) setToolFeedback(toolIndex.getValue()); } }
void OmniDriverEmu::bwdInit() { sout<<"OmniDriverEmu::bwdInit() is called"<<sendl; simulation::Node *context = dynamic_cast<simulation::Node *>(this->getContext()); // access to current node // depending on toolCount, search either the first force feedback, or the feedback with indice "0" simulation::Node *groot = dynamic_cast<simulation::Node *>(context->getRootContext()); // access to current node vector<ForceFeedback*> ffs; groot->getTreeObjects<ForceFeedback>(&ffs); std::cout << "OmniDriver: "<<ffs.size()<<" ForceFeedback objects found"<<std::endl; setForceFeedbacks(ffs); setDataValue(); copyDeviceDataCallback(&data); if (omniSimThreadCreated) { sout << "Emulating thread already running" << sendl; int err = pthread_cancel(hapSimuThread); // no error: thread cancel if(err==0) { std::cout << "OmniDriverEmu: thread haptic cancel" << endl; } // error else { std::cout << "thread not cancel = " << err << endl; } } //sout << "Not initializing phantom, starting emulating thread..." << sendl; //pthread_t hapSimuThread; if (thTimer == NULL) thTimer = new(CTime); if ( pthread_create( &hapSimuThread, NULL, hapticSimuExecute, (void*)this) == 0 ) { cout << "OmniDriver : Thread created for Omni simulation" << endl; omniSimThreadCreated=true; } /* } else sout << "Emulating thread already running" << sendl; */ }