map_accessibility_analysis_client.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <ros/ros.h>
19 
20 //#include <cob_3d_mapping_common/polygon.h>
21 //#include <cob_3d_mapping_common/ros_msg_conversions.h>
22 //#include <tf/tf.h>
23 
24 // services - here you have to include the header file with exactly the same name as your message in the /srv folder
25 // (the Message.h is automatically generated from your Message.srv file during compilation)
26 #include <cob_map_accessibility_analysis/CheckPointAccessibility.h>
27 #include <cob_map_accessibility_analysis/CheckPerimeterAccessibility.h>
28 #include <cob_3d_mapping_msgs/GetApproachPoseForPolygon.h>
29 
30 int main(int argc, char** argv)
31 {
32  ros::init(argc, argv, "map_point_accessibility_check_client");
33 
35 
36  std::string points_service_name = "/map_accessibility_analysis/map_points_accessibility_check";
37  std::string perimeter_service_name = "/map_accessibility_analysis/map_perimeter_accessibility_check";
38  std::string polygon_service_name = "/map_accessibility_analysis/map_polygon_accessibility_check";
39 
40  // here we wait until the service is available; please use the same service name as the one in the server; you may
41  // define a timeout if the service does not show up
42  ROS_INFO("Waiting for service server to become available...");
43  bool serviceAvailable = ros::service::waitForService(points_service_name, 5000);
44  serviceAvailable &= ros::service::waitForService(perimeter_service_name, 5000);
45  serviceAvailable &= ros::service::waitForService(polygon_service_name, 5000);
46 
47  // only proceed if the service is available
48  if (serviceAvailable == false)
49  {
50  ROS_ERROR("The services could not be found.");
51  return -1;
52  }
53  ROS_INFO("The service servers are advertised.");
54 
55  // Call to point accessibility service
56  cob_map_accessibility_analysis::CheckPointAccessibility::Request req_points;
57  cob_map_accessibility_analysis::CheckPointAccessibility::Response res_points;
58 
59  geometry_msgs::Pose2D point;
60  point.x = 1.;
61  point.y = 0;
62  req_points.points_to_check.push_back(point);
63  point.x = -2.;
64  point.y = 0;
65  req_points.points_to_check.push_back(point);
66 
67  // this calls the service server to process our request message and put the result into the response message
68  // this call is blocking, i.e. this program will not proceed until the service server sends the response
69  bool success = ros::service::call(points_service_name, req_points, res_points);
70 
71  if (success == true)
72  {
73  ROS_INFO("Points request successful, results: ");
74  for (unsigned int i = 0; i < res_points.accessibility_flags.size(); ++i)
75  ROS_INFO(" - (xy)=(%f, %f), accessible=%d",
76  req_points.points_to_check[i].x,
77  req_points.points_to_check[i].y,
78  res_points.accessibility_flags[i]);
79  }
80  else
81  ROS_WARN("The service call for points was not successful.");
82 
83  // Call to perimeter accessibility service
84  cob_map_accessibility_analysis::CheckPerimeterAccessibility::Request req_perimeter;
85  cob_map_accessibility_analysis::CheckPerimeterAccessibility::Response res_perimeter;
86 
87  req_perimeter.center.x = 2.5;
88  req_perimeter.center.y = 0.5;
89  req_perimeter.center.theta = 0.;
90  req_perimeter.radius = 1.0;
91  req_perimeter.rotational_sampling_step = 10. / 180. * M_PI;
92 
93  // this calls the service server to process our request message and put the result into the response message
94  // this call is blocking, i.e. this program will not proceed until the service server sends the response
95  success = ros::service::call(perimeter_service_name, req_perimeter, res_perimeter);
96 
97  if (success == true)
98  {
99  ROS_INFO("Accessible points on perimeter:");
100  for (unsigned int i = 0; i < res_perimeter.accessible_poses_on_perimeter.size(); ++i)
101  ROS_INFO(" - (xyt)=(%f, %f, %f)",
102  res_perimeter.accessible_poses_on_perimeter[i].x,
103  res_perimeter.accessible_poses_on_perimeter[i].y,
104  res_perimeter.accessible_poses_on_perimeter[i].theta);
105  }
106  else
107  ROS_WARN("The service call for perimeter points was not successful.");
108 
110  // cob_3d_mapping_msgs::GetApproachPoseForPolygonRequest req_polygon;
111  // cob_3d_mapping_msgs::GetApproachPoseForPolygonResponse res_polygon;
112 
113  // cob_3d_mapping::Polygon p1;
114  // Eigen::Vector2f v;
115  // std::vector<Eigen::Vector2f> vv;
116  // p1.id_ = 1;
117  // p1.normal_ << 0.0,0.0,1.0;
118  // p1.d_ = -1;
119  // v << 1,-2;//,1;
120  // vv.push_back(v);
121  // v << 1,-3;//,1;
122  // vv.push_back(v);
123  // v << 2,-3;//,1;
124  // vv.push_back(v);
125  // v << 2,-2;//,1;
126  // vv.push_back(v);
127  // p1.contours_.push_back(vv);
128  // p1.holes_.push_back(false);
129  // cob_3d_mapping_msgs::Shape p_msg;
130  // toROSMsg(p1, p_msg);
131  // req_polygon.polygon = p_msg;
132 
135  // success = ros::service::call(polygon_service_name, req_polygon, res_polygon);
136 
137  // if (success == true)
138  //{
139  // printf("Accessible points around the polygon:\n");
140  // for (unsigned int i=0; i<res_polygon.approach_poses.poses.size(); i++)
141  //{
142  // tf::Quaternion q;
143  // tf::quaternionMsgToTF(res_polygon.approach_poses.poses[i].orientation, q);
144  // std::cout << "i=" << i << " x=" << res_polygon.approach_poses.poses[i].position.x << " y=" <<
145  // res_polygon.approach_poses.poses[i].position.y << " ang=" << tf::getYaw(q) << std::endl;
146  //}
147  //}
148  // else
149  // std::cout << "The service call for polygon points was not successful.\n" << std::endl;
150 
151  return 0;
152 }
bool call(const std::string &service_name, MReq &req, MRes &res)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
#define ROS_WARN(...)
#define ROS_INFO(...)
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


cob_map_accessibility_analysis
Author(s): Richard Bormann
autogenerated on Sat Oct 24 2020 03:50:48