averaging_client.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <actionlib/client/simple_action_client.h>
00003 #include <actionlib/client/terminal_state.h>
00004 #include <actionlib_tutorials/AveragingAction.h>
00005 #include <boost/thread.hpp>
00006 
00007 void spinThread()
00008 {
00009   ros::spin();
00010 }
00011 
00012 int main (int argc, char **argv)
00013 {
00014   ros::init(argc, argv, "test_averaging");
00015 
00016   // create the action client
00017   actionlib::SimpleActionClient<actionlib_tutorials::AveragingAction> ac("averaging");
00018   boost::thread spin_thread(&spinThread);
00019 
00020   ROS_INFO("Waiting for action server to start.");
00021   ac.waitForServer();
00022 
00023   ROS_INFO("Action server started, sending goal.");
00024   // send a goal to the action
00025   actionlib_tutorials::AveragingGoal goal;
00026   goal.samples = 100;
00027   ac.sendGoal(goal);
00028 
00029   //wait for the action to return
00030   bool finished_before_timeout = ac.waitForResult(ros::Duration(30.0));
00031 
00032   if (finished_before_timeout)
00033   {
00034     actionlib::SimpleClientGoalState state = ac.getState();
00035     ROS_INFO("Action finished: %s",state.toString().c_str());
00036   }
00037   else
00038     ROS_INFO("Action did not finish before the time out.");
00039 
00040   // shutdown the node and join the thread back before exiting
00041   ros::shutdown();
00042   spin_thread.join();
00043 
00044   //exit
00045   return 0;
00046 }


actionlib_tutorials
Author(s): Melonee Wise
autogenerated on Sat Dec 10 2016 03:28:45