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/OpenContainerAction.h>
00034 #include <ias_drawer_executive/CloseContainerAction.h>
00035 #include <ias_drawer_executive/OperateHandleController.h>
00036 #include <ias_drawer_executive/RobotDriver.h>
00037 #include <ias_drawer_executive/RobotArm.h>
00038 #include <ias_drawer_executive/Torso.h>
00039 #include <ias_drawer_executive/Perception3d.h>
00040
00041
00042 #include <visualization_msgs/MarkerArray.h>
00043
00044 bool getParam(std::string param_name)
00045 {
00046 ros::NodeHandle nh;
00047 bool segment;
00048 nh.getParam(param_name, segment);
00049 return segment;
00050 }
00051
00052 void setParam(std::string param_name, bool segment)
00053 {
00054 ros::NodeHandle nh;
00055 nh.setParam(param_name, segment);
00056 }
00057
00058
00059 void test_open(int arm_, double x, double y, double z, double ox, double oy, double oz, double ow)
00060 {
00061
00062 ros::Publisher trajectory_marker_array_publisher, trajectory_marker_publisher;
00063 ros::NodeHandle nh;
00064
00065 trajectory_marker_publisher=nh.advertise<visualization_msgs::Marker>("trajectory_marker", 100, true);
00066 trajectory_marker_array_publisher = nh.advertise<visualization_msgs::MarkerArray>("trajectory_marker_array", 100, true);
00067
00068 OperateHandleController::plateTuckPose();
00069
00070
00071
00072
00073
00074
00075 RobotDriver::getInstance()->moveBaseP(x -0.5,y + (arm_ ? -.2 : .2),0,1);
00076
00077
00078
00079
00080
00081
00082
00083
00084 RobotDriver::getInstance()->moveBaseP(x -.6,y + (arm_ ? -.2 : .2),0,1);
00085
00086
00087
00088 actionlib::SimpleActionClient<ias_drawer_executive::OpenContainerAction> ac("open_container_action", true);
00089
00090 ROS_INFO("Waiting for action server to start.");
00091
00092 std::cerr << "before action" << std::endl;
00093 ac.waitForServer();
00094 std::cerr << "after action" << std::endl;
00095
00096 ROS_INFO("Action server started, sending goal.");
00097
00098
00099 tf::Stamped<tf::Pose> handleHint;
00100 handleHint.setOrigin(btVector3( x, y, z));
00101 handleHint.frame_id_ = "/map";
00102 tf::Stamped<tf::Pose> handlePos = Perception3d::getHandlePoseFromLaser(handleHint);
00103
00104 handlePos.setRotation(btQuaternion(ox, oy, oz, ow));
00105
00106
00107 ias_drawer_executive::OpenContainerGoal goal;
00108 goal.arm = arm_;
00109 goal.position.header.frame_id = "map";
00110 goal.position.pose.position.x = handlePos.getOrigin().x();
00111 goal.position.pose.position.y = handlePos.getOrigin().y();
00112 goal.position.pose.position.z = handlePos.getOrigin().z();
00113 goal.position.pose.orientation.x = handlePos.getRotation().x();
00114 goal.position.pose.orientation.y = handlePos.getRotation().y();
00115 goal.position.pose.orientation.z = handlePos.getRotation().z();
00116 goal.position.pose.orientation.w = handlePos.getRotation().w();
00117
00118 ac.sendGoal(goal);
00119
00120
00121 ROS_INFO("waiting for openning of drawer");
00122 bool finished_before_timeout = ac.waitForResult(ros::Duration(1000.0));
00123
00124
00125
00126 ROS_INFO("moving base backward");
00127 double target[4];
00128 target[0] = -0.1;
00129 target[1] = -0.1;
00130 target[2] = 0;
00131 target[3] = 1;
00132 ROS_INFO("POSE IN BASE %f %f %f", target[0], target[1], target[2]);
00133 RobotDriver::getInstance()->driveInOdom(target, 1);
00134
00135
00136 tf::Stamped<tf::Pose> p0 = RobotArm::getInstance(1)->getToolPose("base_link");
00137
00138
00139 ROS_INFO("parking the arm");
00140 OperateHandleController::plateTuckPose();
00141
00142
00143 RobotDriver::getInstance()->moveBaseP(x -1.0,y + (arm_ ? -.2 : .2),0,1);
00144
00145
00146
00147 ROS_INFO("calling the segment-difference service");
00148 setParam("/segment_difference_interactive/segment", true);
00149
00150
00151
00152
00153
00154
00155 visualization_msgs::MarkerArray marker;
00156 boost::shared_ptr<const ias_drawer_executive::OpenContainerResult> result = ac.getResult();
00157 ROS_INFO("Trajectory: %i Poses", (unsigned int) result->trajectory.poses.size() );
00158 marker.markers.resize(result->trajectory.poses.size());
00159 for (size_t j=0; j < result->trajectory.poses.size(); ++j)
00160 {
00161 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,
00162 result->trajectory.poses[j].orientation.x,result->trajectory.poses[j].orientation.y,result->trajectory.poses[j].orientation.z,result->trajectory.poses[j].orientation.w);
00163 marker.markers[j].header.frame_id = result->trajectory.header.frame_id;
00164 marker.markers[j].header.stamp=ros::Time::now();
00165 marker.markers[j].type = visualization_msgs::Marker::ARROW;
00166 marker.markers[j].action = visualization_msgs::Marker::ADD;
00167 marker.markers[j].ns="trajectory";
00168 marker.markers[j].pose= result->trajectory.poses[j];
00169 marker.markers[j].scale.x=0.1;
00170 marker.markers[j].scale.y=1.0;
00171 marker.markers[j].id = j;
00172 marker.markers[j].color.r = 0.0f;
00173 marker.markers[j].color.g = 1.0f;
00174 marker.markers[j].color.b = 0.0f;
00175 marker.markers[j].color.a = 1.0f;
00176 marker.markers[j].lifetime = ros::Duration::Duration();
00177 }
00178 ROS_INFO("publishing marker array for goto poses");
00179 trajectory_marker_array_publisher.publish(marker);
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 ROS_INFO("closing the drawer");
00193 if (finished_before_timeout)
00194 {
00195 actionlib::SimpleClientGoalState state = ac.getState();
00196 ROS_INFO("Action finished: %s",state.toString().c_str());
00197
00198
00199 ROS_INFO("sucess %i", result->success);
00200 ROS_INFO("Trajectory: %i Poses", (unsigned int) result->trajectory.poses.size() );
00201 for (size_t j=0; j < result->trajectory.poses.size(); ++j)
00202 {
00203 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,
00204 result->trajectory.poses[j].orientation.x,result->trajectory.poses[j].orientation.y,result->trajectory.poses[j].orientation.z,result->trajectory.poses[j].orientation.w);
00205 }
00206
00207 ROS_INFO("TRYING NOW TO CLOSE");
00208
00209 actionlib::SimpleActionClient<ias_drawer_executive::CloseContainerAction> ac_close("close_container_action", true);
00210
00211 ROS_INFO("Waiting for action server to start.");
00212
00213 ac_close.waitForServer();
00214
00215 ROS_INFO("Action server started, sending goal.");
00216
00217 ias_drawer_executive::CloseContainerGoal closeGoal;
00218 closeGoal.arm = arm_;
00219 closeGoal.opening_trajectory = result->trajectory;
00220
00221 ac_close.sendGoal(closeGoal);
00222
00223 bool finished_before_timeout = ac_close.waitForResult(ros::Duration(1000.0));
00224
00225 if (finished_before_timeout)
00226 {
00227 actionlib::SimpleClientGoalState state = ac_close.getState();
00228 ROS_INFO("Action finished: %s",state.toString().c_str());
00229 }
00230
00231 OperateHandleController::plateTuckPose();
00232 }
00233 else
00234 ROS_INFO("Action did not finish before the time out.");
00235 }
00236
00237 geometry_msgs::Pose *getPose(double x, double y, double z, double ox, double oy, double oz, double ow)
00238 {
00239 geometry_msgs::Pose *act = new geometry_msgs::Pose();
00240 act->position.x = x;
00241 act->position.y = y;
00242 act->position.z = z;
00243 act->orientation.x = ox;
00244 act->orientation.y = oy;
00245 act->orientation.z = oz;
00246 act->orientation.w = ow;
00247 return act;
00248 }
00249
00250
00251 void closeonly() {
00252 actionlib::SimpleActionClient<ias_drawer_executive::CloseContainerAction> ac_close("close_container_action", true);
00253
00254 ROS_INFO("Waiting for action server to start.");
00255
00256 ac_close.waitForServer();
00257
00258 ROS_INFO("Action server started, sending goal.");
00259
00260 ias_drawer_executive::CloseContainerGoal closeGoal;
00261 closeGoal.arm = 0;
00262
00263 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.346634, 1.118203, 0.763804, -0.708801, -0.055698, 0.039966, 0.702069));
00264 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.509877, 1.121905, 0.761193, -0.705817, -0.039952, 0.034062, 0.706447));
00265 closeGoal.opening_trajectory.poses.push_back(*getPose( 0.710390, 1.128074, 0.761932, -0.705345, -0.038818, 0.035855, 0.706892));
00266
00267 ac_close.sendGoal(closeGoal);
00268
00269 bool finished_before_timeout = ac_close.waitForResult(ros::Duration(1000.0));
00270
00271 if (finished_before_timeout)
00272 {
00273 actionlib::SimpleClientGoalState state = ac_close.getState();
00274 ROS_INFO("Action finished: %s",state.toString().c_str());
00275 }
00276 }
00277
00278 void test_open(int arm, btTransform &t)
00279 {
00280 test_open(arm, t.getOrigin().x(), t.getOrigin().y(), t.getOrigin().z(), t.getRotation().x(),t.getRotation().y(),t.getRotation().z(),t.getRotation().w());
00281 }
00282
00283 int main (int argc, char **argv)
00284 {
00285
00286 ros::init(argc, argv, "segment_difference_interactive");
00287
00288
00289
00290 std::vector<btTransform> hints(100);
00291
00292
00293 hints[0] = btTransform(btQuaternion(1.000, 0.008, -0.024, -0.004), btVector3(0.762, 2.574, 0.791));
00294 hints[10] = btTransform(btQuaternion(-0.691, -0.039, 0.040, 0.721), btVector3(0.799, 2.137, 1.320));
00295 hints[11] = btTransform(btQuaternion(-0.715, -0.017, -0.003, 0.699), btVector3(0.777, 2.126, 0.804));
00296 hints[12] = btTransform(btQuaternion(-0.741, -0.029, -0.020, 0.671), btVector3(0.777, 2.125, 0.662));
00297 hints[20] = btTransform(btQuaternion(0.025, -0.002, 0.039, 0.999), btVector3(0.798, 1.678, 0.805));
00298 hints[30] = btTransform(btQuaternion(0.712, 0.003, 0.025, 0.702), btVector3(0.629, 1.126, 0.756));
00299 hints[31] = btTransform(btQuaternion(0.712, 0.027, 0.019, 0.701), btVector3(0.627, 1.140, 0.614));
00300 hints[32] = btTransform(btQuaternion(0.718, 0.031, 0.019, 0.695), btVector3(0.623, 1.135, 0.331));
00301 hints[40] = btTransform(btQuaternion(0.698, 0.004, 0.056, 0.714) ,btVector3(0.654, 0.442, 0.766));
00302 hints[50] = btTransform(btQuaternion(0.704, -0.035, 0.027, 0.709) ,btVector3(0.705, -0.171, 0.614));
00303 hints[60] = btTransform(btQuaternion(-0.029, -0.012, 0.020, 0.999) ,btVector3(0.882, -0.520, 0.985));
00304 hints[61] = btTransform(btQuaternion(-0.688, -0.015, 0.045, 0.724) ,btVector3(0.881, -0.776, 0.437));
00305
00306
00307 test_open(0, hints[atoi(argv[1])]);
00308
00309
00310
00311
00312 return 0;
00313 }
00314
00315
00316
00317