program hangs when calling ros::topic::waitForMessage
I will like to grab the data form a ros topic once and was using ros::topic::waitForMessage. However after calling the function, the program seem to freeze at that point.
Following is the code
int main(int argc, char **argv)
{
ros::init(argc, argv, "edgar_action");
while(ros::ok())
{
boost::shared_ptr<control_msgs::FollowJointTrajectoryFeedback const> feedback;
feedback = ros::topic::waitForMessage<control_msgs::FollowJointTrajectoryFeedback>("/right_arm_controller/state",ros::Duration(5.0));
if(feedback.use_count()==0)
{
ROS_WARN("Timeout getting '/right_arm_controller/state' message ");
return 0;
}
else
{
ROS_INFO("Received '/right_arm_controller/state' message ");
}
ros::spin();
}
return 0;
}
What might be causing this problem? Thanks