Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <actionlib/client/simple_action_client.h>
00003 #include <ompl/util/RandomNumbers.h>
00004 #include <arm_navigation_msgs/MoveArmAction.h>
00005 #include <arm_navigation_msgs/utils.h>
00006 #include <geometry_msgs/Pose.h>
00007 #include <tf/transform_broadcaster.h>
00008 #include <tf/transform_datatypes.h>
00009 int counter;
00010 int success_counter;
00011
00012 void move_to_pose(geometry_msgs::Pose & desired_pose,
00013 actionlib::SimpleActionClient<arm_navigation_msgs::MoveArmAction> & move_arm)
00014 {
00015
00016 counter++;
00017
00018 arm_navigation_msgs::SimplePoseConstraint simple_pose_constraint;
00019
00020 simple_pose_constraint.header.frame_id = "katana_base_link";
00021
00022 simple_pose_constraint.link_name = "katana_gripper_tool_frame";
00023
00024 simple_pose_constraint.pose = desired_pose;
00025
00026 simple_pose_constraint.absolute_position_tolerance.x = 0.03;
00027 simple_pose_constraint.absolute_position_tolerance.y = 0.03;
00028 simple_pose_constraint.absolute_position_tolerance.z = 0.03;
00029 simple_pose_constraint.absolute_roll_tolerance = 3.14;
00030 simple_pose_constraint.absolute_pitch_tolerance = 3.14;
00031 simple_pose_constraint.absolute_yaw_tolerance = 3.14;
00032
00033
00034
00035
00036
00037
00038 simple_pose_constraint.orientation_constraint_type = 0;
00039
00040
00041
00042 arm_navigation_msgs::MoveArmGoal goal;
00043
00044 goal.motion_plan_request.group_name = "arm";
00045 goal.motion_plan_request.num_planning_attempts = 1;
00046 goal.motion_plan_request.planner_id = std::string("");
00047 goal.planner_service_name = std::string("ompl_planning/plan_kinematic_path");
00048 goal.motion_plan_request.allowed_planning_time = ros::Duration(15.0);
00049
00050 arm_navigation_msgs::addGoalConstraintToMoveArmGoal(simple_pose_constraint, goal);
00051
00052 bool finished_within_time = false;
00053
00054 move_arm.sendGoal(goal);
00055
00056 finished_within_time = move_arm.waitForResult(ros::Duration(15.5));
00057
00058 if (!finished_within_time)
00059 {
00060 move_arm.cancelGoal();
00061 ROS_INFO("Timed out achieving goal!");
00062 }
00063 else
00064 {
00065 actionlib::SimpleClientGoalState state = move_arm.getState();
00066 bool success = (state == actionlib::SimpleClientGoalState::SUCCEEDED);
00067 if (success)
00068 {
00069
00070 success_counter++;
00071 btScalar roll, pitch, yaw;
00072 btQuaternion q = btQuaternion(simple_pose_constraint.pose.orientation.x,
00073 simple_pose_constraint.pose.orientation.y,
00074 simple_pose_constraint.pose.orientation.z,
00075 simple_pose_constraint.pose.orientation.w);
00076
00077 btMatrix3x3(q).getRPY(roll, pitch, yaw);
00078
00079 ROS_INFO("Action finished: %s",state.toString().c_str());
00080 ROS_INFO("xyz: %f / %f / %f ",
00081 simple_pose_constraint.pose.position.x,
00082 simple_pose_constraint.pose.position.y,
00083 simple_pose_constraint.pose.position.z);
00084 ROS_INFO("quad: %f / %f / %f / %f",
00085 simple_pose_constraint.pose.orientation.x,
00086 simple_pose_constraint.pose.orientation.y,
00087 simple_pose_constraint.pose.orientation.z,
00088 simple_pose_constraint.pose.orientation.w);
00089 ROS_INFO("rpy: %f / %f / %f",roll, pitch, yaw);
00090
00091 ROS_INFO("Trial #%d - succeeded: %f", counter, (double) success_counter/counter);
00092
00093 tf::TransformBroadcaster br;
00094 tf::Transform transform;
00095 transform.setOrigin(tf::Vector3(simple_pose_constraint.pose.position.x, simple_pose_constraint.pose.position.y,
00096 simple_pose_constraint.pose.position.z));
00097
00098 transform.setRotation(tf::Quaternion(simple_pose_constraint.pose.orientation.x,
00099 simple_pose_constraint.pose.orientation.y,
00100 simple_pose_constraint.pose.orientation.z,
00101 simple_pose_constraint.pose.orientation.w));
00102
00103 ros::Rate loop_rate1(100);
00104 ros::Time end_time = ros::Time::now() + ros::Duration(1.0);
00105
00106 while (ros::ok() && ros::Time::now() < end_time)
00107 {
00108 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "katana_base_link", "katana_goal_pose"));
00109 loop_rate1.sleep();
00110 }
00111 }
00112 else
00113 {
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 ROS_DEBUG_THROTTLE(1.0, "Action failed: %s (this is expected to happen a lot)",state.toString().c_str());
00138 }
00139 }
00140 }
00141
00142 int main(int argc, char **argv)
00143 {
00144 ros::init(argc, argv, "move_arm_pose_goal_test");
00145 ros::NodeHandle nh;
00146
00147 actionlib::SimpleActionClient<arm_navigation_msgs::MoveArmAction> move_arm("move_arm", true);
00148 move_arm.waitForServer();
00149 ROS_INFO("Connected to server");
00150
00151 counter = 0;
00152
00153 while (nh.ok())
00154 {
00155
00159
00160 geometry_msgs::Pose pose1;
00161
00162 ompl::RNG rng = ompl::RNG();
00163
00164
00165 pose1.position.x = rng.uniformReal(0.1, 0.15);
00166 pose1.position.y = rng.uniformReal(0.1, 0.15);
00167 pose1.position.z = rng.uniformReal(0.05, 0.45);
00168
00169 double value2[4];
00170
00171 rng.quaternion(value2);
00172
00173 pose1.orientation.x = value2[0];
00174 pose1.orientation.y = value2[1];
00175 pose1.orientation.z = value2[2];
00176 pose1.orientation.w = value2[3];
00177 ROS_INFO("Sending move_arm goal for pose 1 (new)");
00178
00179 move_to_pose(pose1, move_arm);
00180
00181 geometry_msgs::Pose pose2;
00182 pose2.position.x = rng.uniformReal(-0.15, 0.15);
00183 pose2.position.y = rng.uniformReal(-0.15, 0.15);
00184 pose2.position.z = rng.uniformReal(0.05, 0.45);
00185
00186 double value[4];
00187
00188 rng.quaternion(value);
00189
00190 pose2.orientation.x = value2[0];
00191 pose2.orientation.y = value2[1];
00192 pose2.orientation.z = value2[2];
00193 pose2.orientation.w = value2[3];
00194
00195
00196
00197
00198
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 }
00340 }