Subscriber in Visual Plugin [Solved]
Hey guys,
I have a model with 2 nested models (tried this without nesting, same outcome) resembling tft screens. I have a visual plugin that changes the image in the screen, receiving the commands from a gz topic. The thing is that, since i have two of those tft screens, i have two instances of the plugin, and only one of them receives the messages.
Code where only one receives the data (the one that gets initialized later):
m_node = transport::NodePtr(new transport::Node());
m_visual = _parent;
m_node->Init();
std::string topic_name = "~/tft/"+m_parentName+"/state";
m_stateSub = m_node->Subscribe(topic_name, onStateData);
I noticed when doing gz topic -i, that both plugin shared the same port, so, i tried to get them changed by adding this:
gazebo::transport::init();
gazebo::transport::run();
// rest of the code above
This time, they have separate topic ports, tho, neither of them receives data. I can confirm that data is being published by doing gz topic -e, and i can confirm that both subscribers subscribe to the correct topic.
What am i missing here ? Also, there is any way to get a handle to VisualPtr from a model/link plugin (instead of a visual plugin) ?
Thanks in advance!
@chapulina i really need your knowledge here !!!!
@nkoenig i welcome your help too :D
humm have you tried using a member function as the callback? Something like `m_stateSub = m_node->Subscribe(topic_name, &MyPlugin::onStateData, this);`
No, that might be a solution because i'm referencing the actual receiver of the callback. Will try and get back to you with an answer !
@chapulina that did the trick, although i cannot call the init() and run() functions, that doesn't work properly, but i wasn't supposed to call them inside a plugin anyway. Thanks, you are great as always !