00001 #include <ros/ros.h> 00002 #include <iri_wam_common_msgs/LWPRTrajectoryReturningForceEstimationAction.h> 00003 #include <actionlib/client/simple_action_client.h> 00004 00005 typedef actionlib::SimpleActionClient< iri_wam_common_msgs::LWPRTrajectoryReturningForceEstimationAction > TrajClient; 00006 00007 class RobotArm 00008 { 00009 private: 00010 TrajClient* traj_client_; 00011 const std::string model_filename_; 00012 const std::string points_filename_; 00013 00014 public: 00016 RobotArm(const std::string model_filename, const std::string points_filename) : 00017 model_filename_(model_filename), 00018 points_filename_(points_filename) 00019 { 00020 // tell the action client that we want to spin a thread by default 00021 traj_client_ = new TrajClient("/wam_wrapper/lwpr_trajectory", true); 00022 00023 // wait for action server to come up 00024 while(!traj_client_->waitForServer(ros::Duration(5.0))){ 00025 ROS_INFO("Waiting for the lwpr_trajectory_action server"); 00026 } 00027 } 00028 00030 ~RobotArm() 00031 { 00032 delete traj_client_; 00033 } 00034 00036 void startTrajectory() 00037 { 00038 iri_wam_common_msgs::LWPRTrajectoryReturningForceEstimationGoal goal; 00039 goal.model_filename = model_filename_; 00040 goal.points_filename = points_filename_; 00041 00042 traj_client_->sendGoal(goal); 00043 } 00044 00046 actionlib::SimpleClientGoalState getState() 00047 { 00048 return traj_client_->getState(); 00049 } 00050 00051 double get_result() 00052 { 00053 return traj_client_->getResult()->force; 00054 } 00055 }; 00056 00057 int main(int argc, char** argv) 00058 { 00059 if (argc != 3) 00060 { 00061 std::cerr << "Usage: " << argv[0] << "<server_model_file_path> <server_point_file_path>" << std::endl; 00062 return 0; 00063 } 00064 00065 // Init the ROS node 00066 ros::init(argc, argv, "robot_driver"); 00067 00068 RobotArm arm(argv[1], argv[2]); 00069 // Start the trajectory 00070 arm.startTrajectory(); 00071 // Wait for trajectory completion 00072 while(!arm.getState().isDone() && ros::ok()) 00073 { 00074 usleep(50000); 00075 } 00076 00077 std::cout << "Estimated force result: " << arm.get_result() << std::endl; 00078 }