ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It seems that when you call spin
, the challenge is to keep spin
going. Using spinOnce
may solve this.
int main(int argc, char** argv){
// Initialize ROS
ros::init(argc, argv, "simple_navigation_goals");
ros::NodeHandle nh;
// Create a ROS subscriber for the input line segments
ros::Subscriber sub = nh.subscribe("/corners", 10, starting_point);
// Create a ROS publisher for the input point cloud
goal_pub = nh.advertise<geometry_msgs::Point>("goal_points", 10);
//tell the action client that we want to spin a thread by default
MoveBaseClient ac("move_base", true);
ac_ptr = ∾
//wait for the action server to come up
while(!ac.waitForServer(ros::Duration(5.0))){
ROS_INFO("Waiting for the move_base action server to come up");
ros::spinOnce();
}
return 0;
}
Prepare the subscriber before the loop and use spinOnce
in the loop. This will allow you to subscribe during the loop.