ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

program hangs when calling ros::topic::waitForMessage

asked 2015-10-08 01:14:47 -0600

zenifed gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-08 02:15:25 -0600

zenifed gravatar image

I have found the issues. Silly me forgot to create a node handler. Creating a node handler before the while loop fixes the problem

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-10-08 01:14:47 -0600

Seen: 473 times

Last updated: Oct 08 '15