No need to be rude, this is the first time I post a thread in a forum. Sorry for not providing enough information.
Here is a short version of my code. It is I believe pretty much the same as the similar thread I referred to. If I'm not doing exactly the same thing, I don't know what's different. Since I removed most of it for briefty, I doubt it will compile, but the main parts are there.
Code:
int main( int argc, char **argv )
{
// Initialize the ROS system
ros::init( argc, argv, "elikos_aiAgent" );
// Establish this program as a ROS node
ros::NodeHandle nh;
ros::Rate r(30); //10 hz
// Create the quad AI Agent
elikos_ai::Agent agent(&nh);
agent.init();
while (ros::ok())
{
// stuff
r.sleep();
}
agent.destroy();
}
class Agent
{
public:
Agent( ros::NodeHandle* nh );
~Agent();
void init();
void destroy();
void run();
void receiveRobotsPosCallback( const elikos_ros::RobotsPos& msg );
private:
ros::NodeHandle& nh_;
void setSubscribers();
std::map<std::string, ros::Publisher> rosPublishers_;
std::map<std::string, ros::Subscriber> rosSubscribers_;
// I've tested with this version too (the subscriber not being in a map)
// ros::Subscriber sub_;
};
Agent::Agent( ros::NodeHandle* nh ) : nh_(*nh)
{}
void Agent::init()
{
setSubscribers();
}
void Agent::setSubscribers()
{
ROS_INFO_STREAM( "Agent::setSubscribers" );
// Subscribe to all robots' positions' topics
std::string robotsPosTopic = TOPICS_NAMES[robotsPos];
ros::Subscriber sub = nh_.subscribe(robotsPosTopic, 1000, &Agent::receiveRobotsPosCallback, this );
rosSubscribers_.insert( std::pair<std::string,ros::Subscriber>(robotsPosTopic, sub) );
ROS_INFO_STREAM( "Agent::setSubscribers, end" );
// I've tested with this version too (the subscriber not being in a map)
// sub_ = nh_.subscribe(robotsPosTopic, 1000, &Agent::receiveRobotsPosCallback, this );
}
void Agent::receiveRobotsPosCallback( const elikos_ros::RobotsPos& msg )
{
std::cout << "AGENT CALLBACK" << std::endl;
ROS_INFO_STREAM( "Agent::callback -- Push RobotsPos message" );
queueRobotsPos_.push( msg );
}
With this code, here are the console logs (with ROS_INFO_STREAM) I get:
The terminal running the ai_agent node (executable):
[ INFO] [1425144919.193049638]: Agent::setSubscribers
[ INFO] [1425144919.198125285]: Agent::setSubscribers, end
In another terminal, I checked if ROS receives any elikos_ros::RobotsPos messages at all, and it does. This means that any node subscribed to the RobotsPos topic should see their callback function called (where my program fails).
I tried several variations but none made it work, though I followed the given tutorials from the library and discussed it with coworkers. The library tutorials :
roscpp/Overview/Publishers and Subscribers - ROS Wiki (see point 2.3.2)
As in the previous thread, it was suggested to look into the ros::NodeHandle::subscribe() function, I tried to find the source but only managed to find the header file and couldn't find anything from this point:
roscpp: node_handle.h Source File
I tried the solution in this post, but it didn't work:
Subscriber callback not being called in C++ - ROS Answers: Open Source Q&A Forum
Thanks for you help