localization_survey.py
Go to the documentation of this file.
1 import rospy
2 import actionlib
3 import clearpath_localization_msgs.msg
4 from sensor_msgs.msg import NavSatFix
5 
6 
7 # The name of the action server for surveying.
8 # This needs to match the CPR OutdoorNav API.
9 SURVEY_ACTION_NAME = 'localization/survey'
10 SURVEY_PROPERTIES_TOPIC_NAME = SURVEY_ACTION_NAME + '/properties'
11 
12 
14  """Performs surveying, prior to running missions.
15 
16  This is typically used to initialize the position of the Base Station.
17  """
18 
19  def __init__(self, progress_callback=None, done_callback=None):
20  """Builds up the data structure containing the details of the surveying.
21 
22  Parameters
23  ----------
24  progress_callback : fn(float32), optional
25  A callback function that is called at regular intervals while the surveying
26  is being executed to provide progress updates. The function should take
27  float32 parameter that is the percent complete. If set to None, no feedback
28  will be provided and the surveying will execute to completion.
29 
30  done_callback : fn(enum, bool), optional
31  A callback function that is called when the surveying is complete. The function
32  should take two parameters: the terminal state (as an integer from
33  actionlib_msgs/GoalStatus) and the result.
34  """
35 
36  self._survey_complete = False
37  self._survey_success = False
38  self._base_location = NavSatFix()
39  self._survey_progress_callback = progress_callback
40  self._survey_done_callback = done_callback
42  SURVEY_ACTION_NAME, clearpath_localization_msgs.msg.SurveyBaseStationAction)
43 
44  def _surveyFeedbackCallback(self, feedback):
45  """Executes when 'feedback' is received from the surveying.
46 
47  Forwards the callback to the survey feedback callback (if provided).
48  """
49 
50  rospy.loginfo("Surveying is %0.3f percent complete" % (feedback.percent_complete))
51  if self._survey_progress_callback is not None:
52  self._survey_progress_callback(feedback)
53 
54  def _surveyDoneCallback(self, goal_state, result):
55  """Executes when 'done' is received from the surveying.
56 
57  Forwards the callback to the survey feedback callback (if provided).
58  """
59 
60  if goal_state == actionlib.GoalStatus.SUCCEEDED and result.success:
61  self._survey_success = True
62  else:
63  self._survey_success = False
64  self._survey_complete = True
65  rospy.loginfo("Surveying is complete. Success: %s" % (self._survey_success))
66  try:
67  base_properties_msg = rospy.wait_for_message(SURVEY_PROPERTIES_TOPIC_NAME, clearpath_localization_msgs.msg.SurveyProperties, 2.0)
68  self._base_location = base_properties_msg.base_location
69  except rospy.ROSException as e:
70  rospy.logerr("Failed to get survey properties message.")
71  if self._survey_done_callback is not None:
72  self._survey_done_callback(goal_state, result)
73 
74  def startSurvey(self, num_of_desired_fixes=2000):
75  """Begin the survey.
76 
77  Using the default value, this process will take approximately 5 minutes.
78 
79  Parameters
80  ----------
81  num_of_desired_fixes : int, optional
82  The number of sample to take during the surveying process (default is 2000)
83  """
84 
85  self._survey_success = False
86  self._survey_complete = False
87  try:
88  # Waits until the action server has started up and started
89  # listening for goals, then sends the goal
90  if not self._client.wait_for_server(timeout=rospy.Duration(2.0)):
91  rospy.logerr("Failed to connect to server")
92  return False
93  goal = clearpath_localization_msgs.msg.SurveyBaseStationActionGoal
94  goal.number_of_desired_fixes = num_of_desired_fixes
95  self._client.send_goal(goal, feedback_cb=self._surveyFeedbackCallback,
96  done_cb=self._surveyDoneCallback)
97  except rospy.ROSInterruptException:
98  rospy.logerr("localization/survey server is not available; exception detected")
99  return False
100  return True
101 
102  def cancelSurvey(self):
103  """Cancels the active survey."""
104 
105  self._client.cancel_goal()
106 
107  def getSurveySuccess(self):
108  """Determines if the survey was successful.
109 
110  If the survey is still in progress, reports False.
111 
112  See also isSurveyComplete().
113 
114  Returns
115  -------
116  bool
117  True if the survey completed successfully, else False
118  """
119 
120  return self._survey_success
121 
122  def isSurveyComplete(self):
123  """Determines if the survey is complete.
124 
125  See also getSurveySuccess().
126 
127  Returns
128  -------
129  bool
130  True if the survey is complete, else False if survey is still running
131  """
132 
133  return self._survey_complete
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey.cancelSurvey
def cancelSurvey(self)
Definition: localization_survey.py:102
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._base_location
_base_location
Definition: localization_survey.py:38
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey
Definition: localization_survey.py:13
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._survey_success
_survey_success
Definition: localization_survey.py:37
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey.getSurveySuccess
def getSurveySuccess(self)
Definition: localization_survey.py:107
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._survey_progress_callback
_survey_progress_callback
Definition: localization_survey.py:39
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey.isSurveyComplete
def isSurveyComplete(self)
Definition: localization_survey.py:122
actionlib::SimpleActionClient
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._surveyDoneCallback
def _surveyDoneCallback(self, goal_state, result)
Definition: localization_survey.py:54
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._survey_complete
_survey_complete
Definition: localization_survey.py:36
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._surveyFeedbackCallback
def _surveyFeedbackCallback(self, feedback)
Definition: localization_survey.py:44
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._client
_client
Definition: localization_survey.py:41
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey._survey_done_callback
_survey_done_callback
Definition: localization_survey.py:40
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey.startSurvey
def startSurvey(self, num_of_desired_fixes=2000)
Definition: localization_survey.py:74
clearpath_onav_api_examples_lib.localization_survey.LocalizationSurvey.__init__
def __init__(self, progress_callback=None, done_callback=None)
Definition: localization_survey.py:19


clearpath_onav_api_examples_lib
Author(s):
autogenerated on Sun Nov 12 2023 03:29:19