00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <ros/ros.h>
00031 #include <actionlib/client/simple_action_client.h>
00032 #include <actionlib/client/terminal_state.h>
00033 #include <ias_drawer_executive/OperateHandleAction.h>
00034 #include <ias_drawer_executive/OpenContainerAction.h>
00035 #include <ias_drawer_executive/CloseContainerAction.h>
00036
00037 #include <signal.h>
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 actionlib::SimpleActionClient<ias_drawer_executive::OpenContainerAction> *ac_ = 0;
00074
00075 actionlib::SimpleActionClient<ias_drawer_executive::CloseContainerAction> *ac_close_ = 0;
00076
00077 void test_open(int arm_, double x, double y, double z, double ox, double oy, double oz, double ow)
00078 {
00079 if (!ac_)
00080 ac_ = new actionlib::SimpleActionClient<ias_drawer_executive::OpenContainerAction>("open_container_action", true);
00081
00082 ROS_INFO("Waiting for action server to start.");
00083
00084 ac_->waitForServer();
00085
00086 ROS_INFO("Action server started, sending goal.");
00087
00088
00089 ias_drawer_executive::OpenContainerGoal goal;
00090 goal.arm = arm_;
00091 goal.position.header.frame_id = "map";
00092 goal.position.pose.position.x = x;
00093 goal.position.pose.position.y = y;
00094 goal.position.pose.position.z = z;
00095 goal.position.pose.orientation.x = ox;
00096 goal.position.pose.orientation.y = oy;
00097 goal.position.pose.orientation.z = oz;
00098 goal.position.pose.orientation.w = ow;
00099
00100 ac_->sendGoal(goal);
00101
00102
00103 bool finished_before_timeout = ac_->waitForResult(ros::Duration(1000.0));
00104
00105 if (finished_before_timeout)
00106 {
00107 actionlib::SimpleClientGoalState state = ac_->getState();
00108 ROS_INFO("Action finished: %s",state.toString().c_str());
00109 boost::shared_ptr<const ias_drawer_executive::OpenContainerResult> result = ac_->getResult();
00110
00111 ROS_INFO("sucess %i", result->success);
00112 ROS_INFO("Trajectory: %i Poses", (unsigned int) result->trajectory.poses.size() );
00113 for (size_t j=0; j < result->trajectory.poses.size(); ++j)
00114 {
00115 ROS_INFO(" Pos %f %f %f, %f %f %f %f", result->trajectory.poses[j].position.x,result->trajectory.poses[j].position.y,result->trajectory.poses[j].position.z,
00116 result->trajectory.poses[j].orientation.x,result->trajectory.poses[j].orientation.y,result->trajectory.poses[j].orientation.z,result->trajectory.poses[j].orientation.w);
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 ROS_INFO("TRYING NOW TO CLOSE");
00137
00138 if (!ac_close_)
00139 ac_close_ = new actionlib::SimpleActionClient<ias_drawer_executive::CloseContainerAction>("close_container_action", true);
00140
00141 ROS_INFO("Waiting for action server to start.");
00142
00143 ac_close_->waitForServer();
00144
00145 ROS_INFO("Action server started, sending goal.");
00146
00147 ias_drawer_executive::CloseContainerGoal closeGoal;
00148 closeGoal.arm = arm_;
00149 closeGoal.opening_trajectory = result->trajectory;
00150
00151 ac_close_->sendGoal(closeGoal);
00152
00153 bool finished_before_timeout = ac_close_->waitForResult(ros::Duration(1000.0));
00154
00155 if (finished_before_timeout)
00156 {
00157 actionlib::SimpleClientGoalState state = ac_close_->getState();
00158 ROS_INFO("Action finished: %s",state.toString().c_str());
00159 }
00160 }
00161 else
00162 ROS_INFO("Action did not finish before the time out.");
00163 }
00164
00165 geometry_msgs::Pose *getPose(double x, double y, double z, double ox, double oy, double oz, double ow)
00166 {
00167 geometry_msgs::Pose *act = new geometry_msgs::Pose();
00168 act->position.x = x;
00169 act->position.y = y;
00170 act->position.z = z;
00171 act->orientation.x = ox;
00172 act->orientation.y = oy;
00173 act->orientation.z = oz;
00174 act->orientation.w = ow;
00175 return act;
00176 }
00177
00178
00179
00180
00181 void closeonly() {
00182 if (!ac_close_)
00183 ac_close_ = new actionlib::SimpleActionClient<ias_drawer_executive::CloseContainerAction>("close_container_action", true);
00184
00185 ROS_INFO("Waiting for action server to start.");
00186
00187 ac_close_->waitForServer();
00188
00189 ROS_INFO("Action server started, sending goal.");
00190
00191 ias_drawer_executive::CloseContainerGoal closeGoal;
00192 closeGoal.arm = 0;
00193
00194 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.346634, 1.118203, 0.763804, -0.708801, -0.055698, 0.039966, 0.702069));
00195 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.509877, 1.121905, 0.761193, -0.705817, -0.039952, 0.034062, 0.706447));
00196 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.710390, 1.128074, 0.761932, -0.705345, -0.038818, 0.035855, 0.706892));
00197
00198 ac_close_->sendGoal(closeGoal);
00199
00200 bool finished_before_timeout = ac_close_->waitForResult(ros::Duration(1000.0));
00201
00202 if (finished_before_timeout)
00203 {
00204 actionlib::SimpleClientGoalState state = ac_close_->getState();
00205 ROS_INFO("Action finished: %s",state.toString().c_str());
00206 }
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 void quit(int sig)
00223 {
00224 if (ac_)
00225 ac_->cancelAllGoals();
00226 if (ac_close_)
00227 ac_close_->cancelAllGoals();
00228 exit(0);
00229 }
00230
00231
00232 int main (int argc, char **argv)
00233 {
00234 ros::init(argc, argv, "test_fibonacci");
00235
00236 signal(SIGINT,quit);
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 return 0;
00247 }