Ask Your Question

Is it necessary to create an entire class for a subscriber? [closed]

asked 2014-08-07 01:34:59 -0500

WarGravy gravatar image

updated 2014-08-07 01:51:11 -0500

gvdhoorn gravatar image

I'm new to ROS and I've been working with joy. I can not seem to get my code working. The main different between my code and the example code from the ROSNodeTutorialC++ is that instead of creating a node class, I just simply have global variables setup that get assigned from a launch file and then on line 30:

ros::Subscriber sub_message = n.subscribe(topic.c_str(), 1000, &NodeExample::messageCallback, node_example);

I have done the following:

ros::Subscriber sub_message = n.subscribe("joy", 10, callbackFunction);

Which is then followed by:

while (n.ok())

Is it possible that because I'm not using a class my code is not operating as I thought it was or is it most likely another issue?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by WarGravy
close date 2014-08-07 23:19:39.322929


Using classes is not a requirement no. But without the actual -- complete -- code, or a minimal working example, we cannot really determine what could be causing your issue. You could be running into issues with variable scopes, fi. Could you update your question with the relevant information?

gvdhoorn gravatar image gvdhoorn  ( 2014-08-07 01:52:46 -0500 )edit

Also: how is it that you reference `NodeExample::messageCallback` when you are not using classes?

gvdhoorn gravatar image gvdhoorn  ( 2014-08-07 01:54:21 -0500 )edit

Thank you gvdhoorn, I eventually found out that my bashrc file was not setup correctly and my node was not showing up in the list so there was some other stuff I had to do to get everything fixed. My code is up and running now.

WarGravy gravatar image WarGravy  ( 2014-08-07 23:01:04 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-07 02:03:59 -0500

BennyRe gravatar image

The first and most basic tutorial about C++ subscribers you should have read does not implement an own class.

So, simple answer: No, it's not necessary.

edit flag offensive delete link more

answered 2014-08-07 05:33:34 -0500


image description

Keep it in mind ;)

edit flag offensive delete link more


Amen to that.

l0g1x gravatar image l0g1x  ( 2014-08-07 08:31:57 -0500 )edit

Question Tools

1 follower


Asked: 2014-08-07 01:34:59 -0500

Seen: 92 times

Last updated: Aug 07 '14