Gazebo | Ignition | Community
Ask Your Question

Subscriber in Visual Plugin [Solved]

asked 2017-07-14 09:46:53 -0600

wicked88 gravatar image

updated 2017-07-20 16:19:45 -0600

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;
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:


// 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!

edit retag flag offensive close merge delete


@chapulina i really need your knowledge here !!!!

wicked88 gravatar imagewicked88 ( 2017-07-15 07:14:06 -0600 )edit

@nkoenig i welcome your help too :D

wicked88 gravatar imagewicked88 ( 2017-07-15 08:42:03 -0600 )edit

humm have you tried using a member function as the callback? Something like `m_stateSub = m_node->Subscribe(topic_name, &MyPlugin::onStateData, this);`

chapulina gravatar imagechapulina ( 2017-07-17 19:36:34 -0600 )edit

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 !

wicked88 gravatar imagewicked88 ( 2017-07-20 13:29:28 -0600 )edit

@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 !

wicked88 gravatar imagewicked88 ( 2017-07-20 15:57:22 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-20 16:12:53 -0600

wicked88 gravatar image

As glorious @chapulina said, referencing the object's callback solves the issue.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-07-14 09:46:53 -0600

Seen: 200 times

Last updated: Jul 20 '17