blocked_goal_alternative.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 
20 from geometry_msgs.msg import Pose2D
21 from cob_map_accessibility_analysis.srv import CheckPointAccessibility, CheckPointAccessibilityRequest, CheckPointAccessibilityResponse # pylint: disable=import-error,no-name-in-module
22 from cob_map_accessibility_analysis.srv import CheckPerimeterAccessibility, CheckPerimeterAccessibilityRequest, CheckPerimeterAccessibilityResponse # pylint: disable=import-error,no-name-in-module
23 
24 
26 
27  def __init__(self):
28  rospy.wait_for_service("/map_accessibility_analysis/map_points_accessibility_check")
29  rospy.wait_for_service("/map_accessibility_analysis/map_perimeter_accessibility_check")
30 
31  rospy.loginfo("All map_accessibility_analysis services available")
32 
33  self.point_client = rospy.ServiceProxy(
34  "/map_accessibility_analysis/map_points_accessibility_check", CheckPointAccessibility)
35  self.point_req = None
36  self.point_res = None
37  self.perimeter_client = rospy.ServiceProxy(
38  "/map_accessibility_analysis/map_perimeter_accessibility_check", CheckPerimeterAccessibility)
39  self.perimeter_req = None
40  self.perimeter_res = None
41 
42  def check_nav_goal(self, pose2d):
43  try:
44  self.point_req = CheckPointAccessibilityRequest()
45  # array of points which should be checked for accessibility
46  self.point_req.points_to_check.append(pose2d)
47  # if true, the path to a goal position must be accessible as well
48  self.point_req.approach_path_accessibility_check = False
49 
50  self.point_res = self.point_client(self.point_req)
51  # rospy.loginfo("CheckPointAccessibilityResponse")
52  # print(self.point_res)
53  except rospy.ServiceException as e:
54  rospy.logerr("Service call 'map_points_accessibility_check' failed: %s" % e)
55  return (False, None)
56 
57  for i in range(len(self.point_req.points_to_check)):
58  if self.point_res.accessibility_flags[i]:
59  rospy.loginfo("Nav Goal is valid")
60  # print(self.point_req.points_to_check[i])
61  return (True, self.point_req.points_to_check[i])
62 
63  rospy.logwarn("Nav Goal is not accessible")
64  return (False, None)
65 
66  def check_perimeter(self, pose2d):
67  for radius in [0.1, 0.3, 0.5, 0.7, 1.0, 2.0]:
68  rospy.loginfo("Checking with perimeter radius %f", radius)
69  try:
70  self.perimeter_req = CheckPerimeterAccessibilityRequest()
71  # center of the circle whose perimeter should be checked for accessibility, in [m,m,rad]
72  self.perimeter_req.center = pose2d
73  self.perimeter_req.radius = radius # radius of the circle, in [m]
74  # rotational sampling step width for checking points on the perimeter, in [rad]
75  self.perimeter_req.rotational_sampling_step = 0.0
76 
78  # rospy.loginfo("CheckPerimeterAccessibilityResponse")
79  # print(self.perimeter_res)
80  except rospy.ServiceException as e:
81  rospy.logerr("Service call 'map_perimeter_accessibility_check' failed: %s" % e)
82  break
83 
84  # use first valid alternative
85  if not self.perimeter_res.accessible_poses_on_perimeter == []:
86  rospy.loginfo("Found valid alternative")
87  # print(self.perimeter_res.accessible_poses_on_perimeter[0])
88  return (True, self.perimeter_res.accessible_poses_on_perimeter[0])
89 
90  rospy.logerr("No valid alternative in perimeter")
91  return (False, None)


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