Ask Your Question
0

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

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

WarGravy gravatar image

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

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())
{
    ros::spinOnce();
    r.sleep();
}

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

Comments

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 imagegvdhoorn ( 2014-08-07 01:52:46 -0600 )edit

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

gvdhoorn gravatar imagegvdhoorn ( 2014-08-07 01:54:21 -0600 )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 imageWarGravy ( 2014-08-07 23:01:04 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
3

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

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
2

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

Also...

image description

Keep it in mind ;)

edit flag offensive delete link more

Comments

Amen to that.

l0g1x gravatar imagel0g1x ( 2014-08-07 08:31:57 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 74 times

Last updated: Aug 07 '14