Is it necessary to create an entire class for a subscriber? [closed]
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?
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?
Also: how is it that you reference `NodeExample::messageCallback` when you are not using classes?
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.