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!
Asked by wicked88 on 2017-07-14 09:46:53 UTC
Answers
As glorious @chapulina said, referencing the object's callback solves the issue.
Asked by wicked88 on 2017-07-20 16:12:53 UTC
Comments
@chapulina i really need your knowledge here !!!!
Asked by wicked88 on 2017-07-15 07:14:06 UTC
@nkoenig i welcome your help too :D
Asked by wicked88 on 2017-07-15 08:42:03 UTC
humm have you tried using a member function as the callback? Something like
m_stateSub = m_node->Subscribe(topic_name, &MyPlugin::onStateData, this);
Asked by chapulina on 2017-07-17 19:36:34 UTC
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 !
Asked by wicked88 on 2017-07-20 13:29:28 UTC
@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 !
Asked by wicked88 on 2017-07-20 15:57:22 UTC