Home › Forum › SOFA › Programming with SOFA › [SOLVED] Searching SOFA Nodes plugins inside a scene
- This topic has 4 replies, 2 voices, and was last updated 6 years, 7 months ago by bgarcial.
-
AuthorPosts
-
23 April 2018 at 02:52 #10813bgarcialBlocked
In these moments we are working with two plugins which have been created by our small and humble team.
SerialComunication – Serial Driver provides interfaces for comunication with serial ports in the SOFA Framework
ZeroMQCommunication – which provide Network communication from SOFA to external entities via zeroMQ sockets
The ZeroMQCommunication plugin, with a certain frequency, is consulting SerialComunication if there are data to be sent (this through ZMQ sockets).
From SOFA, when executing, a scene is being called which reference these two plugins:
<RequiredPlugin name="SerialComunication" pluginName="SerialComunication" /> <SerialDriver name="Serial Driver" listening="1" tags="Omni" forceScale="0.5" scale="50" positionBase="0 1 -0.5" permanent="1" /> <!-- Added ZMQ Communication plugin --> <RequiredPlugin name="ZeroMQCommunication" pluginName="ZeroMQCommunication" /> <ZMQClientComponent name="ZMQCC" listening="1" tags="Omni" forceScale="0.5" scale="50" positionBase="0 1 -0.5" permanent="1" /> <!-- Review late above parameters ZMQClientComponent -->
According to it, SerialComunication have the SerialDriver component and
ZeroMQCommunication have the ZMQClientComponent componentIn this way at the moment of execution of SOFA, a tree structure is created having the classes of these components as Nodes.
Since we are interested in calling or consulting the SerialComunication plugin from ZeroMQCommunication, then, in addition to other configurations made, in the
ZMQClientComponent.h
file we are doing the following:We declare an alias to the
SerialDriver
class calledSerialDriverType
and create aSerialDriverType
type vector calledobjectsSerialDriver
it is on this vector of type
SerialDriverType
where the objects or instances SerialDriver found when SOFA is traversed or iterated through the nodes in the tree representing the hierarchy of the called scene, which refers to the two aforementioned plugins …#include <SerialComunication/SerialDriver.h> . . . class ZMQClientComponent : public sofa::core::behavior::BaseController { public: SOFA_CLASS(ZMQClientComponent, sofa::core::behavior::BaseController); ZMQClientComponent(); virtual ~ZMQClientComponent(); /* Conect to ZMQ external Server */ void setupConnection(); /* Send some data to ZMQ external Server */ void instrumentDataSend(instrumentData a); void attachingDataToSend(attachingData b); /* On the initialize method we get the root context- Here just define method */ void init(); virtual void draw(); virtual void draw(const core::visual::VisualParams *) override; /** We declare an alias to SerialDriver attribute, which shuld be a vector * to reference it on ZMQClientComponent.cpp to save inside the SerialDriver objects*/ typedef SerialDriver SerialDriverType; std::vector<SerialDriverType *> objectsSerialDriver; private: // struct timeval t_before, t_after; // string replyMessage; };
So, in the ZeroMQClientComponent.cpp file in the
init()
method developed, we are trying to go through the SOFA hierarchy tree to find the node corresponding toSerialDriver
.in the
init()
method we get therootContext
, this being necessary because according to the documentation:Every Sofa component has a context. By casting this context to a simulation::Node*, you manage to get the node containing your component.
Then we get the context in this way:
sofa::simulation::Node::SPtr rootContext = static_cast<simulation::Node *>(this->getContext()->getRootContext());
And then, already with the context, we obtain all the
SerialDriver
type objects (with their alias ofSerialDriverType
) and assign them to the vectorobjectsSerialDriver
created before, referencing their memory address:getContext()->get<SerialDriverType>(&objectsSerialDriver, core::objectmodel::BaseContext::SearchDown);
Then the
ZeroMQClientComponent.cpp
file has stayed like this:#include <sofa/core/ObjectFactory.h> #include <sofa/simulation/Node.h> #include <zmq.hpp> #include <zmq.h> #include "zhelpers.hpp" #include "ZMQClientComponent.h" using namespace std; namespace sofa { namespace component { namespace controller { // Create a context to use in all sockets creation zmq::context_t context(1); zmq::socket_t subscriber(context, ZMQ_SUB); zmq::socket_t sender(context, ZMQ_PUSH); ZMQClientComponent::ZMQClientComponent() { } void ZMQClientComponent::setupConnection() { // Connecting to ZMQ sockets server ... } void ZMQClientComponent::instrumentDataSend(instrumentData a) { // Send data instrument } void ZMQClientComponent::init() { /* We get the rootContext */ sofa::simulation::Node::SPtr rootContext = static_cast<simulation::Node *>(this->getContext()->getRootContext()); cout << "rootContext: " << rootContext << endl; getContext()->get<SerialDriverType>(&objectsSerialDriver, core::objectmodel::BaseContext::SearchDown); std::cout << "ZeroMQCommunication::init()" << std::endl; ZMQClientComponent z; // Connecting to Nerwork Manager z.setupConnection(); } ZMQClientComponent::~ZMQClientComponent() { } void ZMQClientComponent::draw(const core::visual::VisualParams *vparam) {} void ZMQClientComponent::draw() {} SOFA_DECL_CLASS(ZMQClientComponent) int ZMQClientComponentClass = sofa::core::RegisterObject("This component connect to ZMQ Socket.").add< ZMQClientComponent >(); } // namespace controller } // namespace component } // namespace sofa
When we compile SOFA
(make -j7)
we get the following error:[ 87%] Built target SofaVolumetricData_test [ 88%] Built target SofaMiscTopology_test [ 88%] Built target SofaMiscSolver_test [ 88%] Built target SofaTest_test [ 88%] Built target CImgPlugin_test [ 89%] Built target SofaMiscMapping_test [ 97%] Built target SofaGuiQt CMakeFiles/ZeroMQCommunication.dir/ZMQClientComponent.cpp.o: In function sofa::component::controller::ZMQClientComponent::init()': ZMQClientComponent.cpp:(.text+0x3264): undefined reference to typeinfo for sofa::component::controller::SerialDriver' ZMQClientComponent.cpp:(.text+0x3441): undefined reference to typeinfo for sofa::component::controller::SerialDriver' CMakeFiles/ZeroMQCommunication.dir/ZMQClientComponent.cpp.o: In function sofa::core::objectmodel::TClassInfo<sofa::component::controller::SerialDriver>::dynamicCast(sofa::core::objectmodel::Base*) const': ZMQClientComponent.cpp:(.text._ZNK4sofa4core11objectmodel10TClassInfoINS_9component10controller12SerialDriverEE11dynamicCastEPNS1_4BaseE[_ZNK4sofa4core11objectmodel10TClassInfoINS_9component10controller12SerialDriverEE11dynamicCastEPNS1_4BaseE]+0xb): undefined reference to typeinfo for sofa::component::controller::SerialDriver' CMakeFiles/ZeroMQCommunication.dir/ZMQClientComponent.cpp.o: In function sofa::core::objectmodel::ClassInfo::isInstance(sofa::core::objectmodel::Base*) const': ZMQClientComponent.cpp:(.text._ZNK4sofa4core11objectmodel9ClassInfo10isInstanceEPNS1_4BaseE[_ZNK4sofa4core11objectmodel9ClassInfo10isInstanceEPNS1_4BaseE]+0x1f): undefined reference to typeinfo for sofa::component::controller::SerialDriver' collect2: error: ld returned 1 exit status applications/plugins/ZeroMQCommunication/CMakeFiles/ZeroMQCommunication.dir/build.make:239: recipe for target 'lib/libZeroMQCommunication.so' failed make[2]: *** [lib/libZeroMQCommunication.so] Error 1 CMakeFiles/Makefile2:10160: recipe for target 'applications/plugins/ZeroMQCommunication/CMakeFiles/ZeroMQCommunication.dir/all' failed make[1]: *** [applications/plugins/ZeroMQCommunication/CMakeFiles/ZeroMQCommunication.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 97%] Built target SofaGuiMain Makefile:160: recipe for target 'all' failed make: *** [all] Error 2
If I delete the line where SOFA starts searching in a descending way the
SerialDriver
node, that is:getContext()->get<SerialDriverType>(&objectsSerialDriver, core::objectmodel::BaseContext::SearchDown);
The SOFA build process is O.K. Success
Apparently, the get method used here is defined in this plugin file called
Flexible
sofa/src/applications/plugins/Flexible/types/DeformationGradientTypes.h
And in this method at the line 191:
static void get ( T& x, T& y, T& z, const Deriv& /*c*/ ) { x=y=z=0; /*std::cerr<<"WARNING: DefGradientTypes::get(): a deformation gradient cannot be converted to spatial coordinates.\n"; */ }
As far as can be detailed, this method receives a template-type parameter called
T
, due to part of its nearby code:/** @name Conversions * Convert to/from points in space */ //@{ template<typename T> static void set ( Deriv& /*c*/, T /*x*/, T /*y*/, T /*z*/ ) { } template<typename T> static void get ( T& x, T& y, T& z, const Deriv& /*c*/ ) { x=y=z=0; /*std::cerr<<"WARNING: DefGradientTypes::get(): a deformation gradient cannot be converted to spatial coordinates.\n"; */ } template<typename T> static void add ( Deriv& /*c*/, T /*x*/, T /*y*/, T /*z*/ ) { } //@}
But in this
Flexible
plugin, this method is defined but it is not developed in its respective extension file .cppsofa/src/applications/plugins/Flexible/types/DeformationGradientTypes.cpp
Apparently, when you want to search in a runtime scene for a node in the tree that represents the SOFA hierarchy, you should use specific template data types, but I do not understand how this method works, or how these templates should work. Or what should receive this method? Of course, taking into account that my analysis is adequate and correct.
What can be happening in my search process of the
SerialDriver
node from theZeroMQCommunication
plugin?
Any help will be highly appreciated.2 May 2018 at 22:45 #10905bgarcialBlockedHi @hugo and @guillaumeparan
Receive you a warm greetingsI have taken the audacity to mention them with the aim of as far as possible to review this question.
I haven’t clear what can be happening here in relation to the search to SerialDriver node on the SOFA hierarchy tree.
We are conducting a search of a node that we have created ourselves and it is called
SerialDriver
.Apparently, because of the way in which SOFA is built, the methods to recover the nodes in the tree hierarchy receive a
T
object of type template, but that points towards a reference that I do not know very well how to interpret it or approach its development.What types of data should that
get()
method receive since it seems that theSerialDriverType
vector in which the existing SerialDriver objects should apparently be retrieved is not an ideal parameter and therefore the reference error toSerialDriver
is undefined.undefined reference to
typeinfo for sofa::component::controller::SerialDriver’`My apologies also for the audacity to mention them in this question
Best Regards4 May 2018 at 19:04 #10999bgarcialBlockedMy problem was a linked inconvenient when I call and use one SerialDriver object from ZMQClientComponent init method of ZeroMQCommunication plugin
I’ve been testing calling a new pointer Serial Driver object on the
ZMQClientComponent::init()
method, removing the search SerialDriver node search on the tree and theundefined reference to typeinfo for sofa::component::controller::SerialDriver'
persist.void ZMQClientComponent::init() { /* We get the rootContext */ sofa::simulation::Node::SPtr rootContext = static_cast<simulation::Node *>(this->getContext()->getRootContext()); cout << "rootContext: " << rootContext << endl; //getContext()->get<SerialDriverType>(&objectsSerialDriver, core::objectmodel::BaseContext::SearchDown); // Creating a SerialDriver pointer instance SerialDriver* s = new SerialDriver(); std::cout << "ZeroMQCommunication::init()" << std::endl; ZMQClientComponent z; // Connecting to Nerwork Manager z.setupConnection(); }
According to the previous situation, I think that my problem it’s related with the linked between components through of the calling of SerialComunication from ZeroMQCommunication.
I’ve decided integrate on one unique plugin the
SerialDriver
andZMQClientComponent
components, together are now, under ZeroMQCommunication plugin, and my search SerialDriver node operation on theZMQClientComponent::init()
method its works, my sofa instance has been compiled and run.7 May 2018 at 09:17 #11000HugoKeymasterHi @bgarcial,
That’s great to hear from you and to see you progressing with your ZMQ/SerialCommunication work. My apologies for not being able to help you more. Keep us updated about the integration into one unique plugin.
Best,
Hugo
9 May 2018 at 16:39 #11003 -
AuthorPosts
- You must be logged in to reply to this topic.