Gazebo | Ignition | Community
Ask Your Question
0

Subscriber in Visual Plugin [Solved]

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

wicked88 gravatar image

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

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!

edit retag flag offensive close merge delete

Comments

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

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

@nkoenig i welcome your help too :D

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

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 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

wicked88 gravatar image

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 234 times

Last updated: Jul 20 '17