map_accessibility_analysis_client.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #include <ros/ros.h>
00019 
00020 //#include <cob_3d_mapping_common/polygon.h>
00021 //#include <cob_3d_mapping_common/ros_msg_conversions.h>
00022 //#include <tf/tf.h>
00023 
00024 // services - here you have to include the header file with exactly the same name as your message in the /srv folder
00025 // (the Message.h is automatically generated from your Message.srv file during compilation)
00026 #include <cob_map_accessibility_analysis/CheckPointAccessibility.h>
00027 #include <cob_map_accessibility_analysis/CheckPerimeterAccessibility.h>
00028 #include <cob_3d_mapping_msgs/GetApproachPoseForPolygon.h>
00029 
00030 int main(int argc, char** argv)
00031 {
00032   ros::init(argc, argv, "map_point_accessibility_check_client");
00033 
00034   ros::NodeHandle n;
00035 
00036   std::string points_service_name = "/map_accessibility_analysis/map_points_accessibility_check";
00037   std::string perimeter_service_name = "/map_accessibility_analysis/map_perimeter_accessibility_check";
00038   std::string polygon_service_name = "/map_accessibility_analysis/map_polygon_accessibility_check";
00039 
00040   // here we wait until the service is available; please use the same service name as the one in the server; you may
00041   // define a timeout if the service does not show up
00042   ROS_INFO("Waiting for service server to become available...");
00043   bool serviceAvailable = ros::service::waitForService(points_service_name, 5000);
00044   serviceAvailable &= ros::service::waitForService(perimeter_service_name, 5000);
00045   serviceAvailable &= ros::service::waitForService(polygon_service_name, 5000);
00046 
00047   // only proceed if the service is available
00048   if (serviceAvailable == false)
00049   {
00050     ROS_ERROR("The services could not be found.");
00051     return -1;
00052   }
00053   ROS_INFO("The service servers are advertised.");
00054 
00055   // Call to point accessibility service
00056   cob_map_accessibility_analysis::CheckPointAccessibility::Request req_points;
00057   cob_map_accessibility_analysis::CheckPointAccessibility::Response res_points;
00058 
00059   geometry_msgs::Pose2D point;
00060   point.x = 1.;
00061   point.y = 0;
00062   req_points.points_to_check.push_back(point);
00063   point.x = -2.;
00064   point.y = 0;
00065   req_points.points_to_check.push_back(point);
00066 
00067   // this calls the service server to process our request message and put the result into the response message
00068   // this call is blocking, i.e. this program will not proceed until the service server sends the response
00069   bool success = ros::service::call(points_service_name, req_points, res_points);
00070 
00071   if (success == true)
00072   {
00073     ROS_INFO("Points request successful, results: ");
00074     for (unsigned int i = 0; i < res_points.accessibility_flags.size(); ++i)
00075       ROS_INFO(" - (xy)=(%f, %f), accessible=%d",
00076                req_points.points_to_check[i].x,
00077                req_points.points_to_check[i].y,
00078                res_points.accessibility_flags[i]);
00079   }
00080   else
00081     ROS_WARN("The service call for points was not successful.");
00082 
00083   // Call to perimeter accessibility service
00084   cob_map_accessibility_analysis::CheckPerimeterAccessibility::Request req_perimeter;
00085   cob_map_accessibility_analysis::CheckPerimeterAccessibility::Response res_perimeter;
00086 
00087   req_perimeter.center.x = 2.5;
00088   req_perimeter.center.y = 0.5;
00089   req_perimeter.center.theta = 0.;
00090   req_perimeter.radius = 1.0;
00091   req_perimeter.rotational_sampling_step = 10. / 180. * M_PI;
00092 
00093   // this calls the service server to process our request message and put the result into the response message
00094   // this call is blocking, i.e. this program will not proceed until the service server sends the response
00095   success = ros::service::call(perimeter_service_name, req_perimeter, res_perimeter);
00096 
00097   if (success == true)
00098   {
00099     ROS_INFO("Accessible points on perimeter:");
00100     for (unsigned int i = 0; i < res_perimeter.accessible_poses_on_perimeter.size(); ++i)
00101       ROS_INFO(" - (xyt)=(%f, %f, %f)",
00102                res_perimeter.accessible_poses_on_perimeter[i].x,
00103                res_perimeter.accessible_poses_on_perimeter[i].y,
00104                res_perimeter.accessible_poses_on_perimeter[i].theta);
00105   }
00106   else
00107     ROS_WARN("The service call for perimeter points was not successful.");
00108 
00110   // cob_3d_mapping_msgs::GetApproachPoseForPolygonRequest req_polygon;
00111   // cob_3d_mapping_msgs::GetApproachPoseForPolygonResponse res_polygon;
00112 
00113   // cob_3d_mapping::Polygon p1;
00114   // Eigen::Vector2f v;
00115   // std::vector<Eigen::Vector2f> vv;
00116   // p1.id_ = 1;
00117   // p1.normal_ << 0.0,0.0,1.0;
00118   // p1.d_ = -1;
00119   // v << 1,-2;//,1;
00120   // vv.push_back(v);
00121   // v << 1,-3;//,1;
00122   // vv.push_back(v);
00123   // v << 2,-3;//,1;
00124   // vv.push_back(v);
00125   // v << 2,-2;//,1;
00126   // vv.push_back(v);
00127   // p1.contours_.push_back(vv);
00128   // p1.holes_.push_back(false);
00129   // cob_3d_mapping_msgs::Shape p_msg;
00130   // toROSMsg(p1, p_msg);
00131   // req_polygon.polygon = p_msg;
00132 
00135   // success = ros::service::call(polygon_service_name, req_polygon, res_polygon);
00136 
00137   // if (success == true)
00138   //{
00139   // printf("Accessible points around the polygon:\n");
00140   // for (unsigned int i=0; i<res_polygon.approach_poses.poses.size(); i++)
00141   //{
00142   // tf::Quaternion q;
00143   // tf::quaternionMsgToTF(res_polygon.approach_poses.poses[i].orientation, q);
00144   // std::cout << "i=" << i << "  x=" << res_polygon.approach_poses.poses[i].position.x << "  y=" <<
00145   // res_polygon.approach_poses.poses[i].position.y << "  ang=" << tf::getYaw(q) << std::endl;
00146   //}
00147   //}
00148   // else
00149   // std::cout << "The service call for polygon points was not successful.\n" << std::endl;
00150 
00151   return 0;
00152 }


cob_map_accessibility_analysis
Author(s): Richard Bormann
autogenerated on Thu Jun 6 2019 21:01:20