exploration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2017 SoftBank Robotics Europe
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 #import ROS dependencies
18 import rospy
19 
20 #import NAO dependencies
21 from naoqi_driver.naoqi_node import NaoqiNode
22 
24 
25  def __init__(self):
26  NaoqiNode.__init__(self, 'naoqi_exploration')
27  self.navigation = None
28  self.connectNaoQi()
29 
30  # (re-) connect to NaoQI:
31  def connectNaoQi(self):
32  '''Connect to Naoqi modules
33  '''
34  rospy.loginfo("Exploration Node Connecting to NaoQi at %s:%d", self.pip, self.pport)
35 
36  self.navigation = self.get_proxy("ALNavigation")
37  if self.navigation is None:
38  rospy.logerr("Unable to reach ALNavigation.")
39  exit(0)
40 
41  version_array = self.get_proxy("ALSystem").systemVersion().split('.')
42  if len(version_array) < 3:
43  rospy.logerr("Unable to deduce the system version.")
44  exit(0)
45  version_tuple = (int(version_array[0]), int(version_array[1]), int(version_array[2]))
46  min_version = (2, 5, 2)
47  if version_tuple < min_version:
48  rospy.logerr("Naoqi version " + str(min_version) +
49  " required for localization. Yours is " + str(version_tuple))
50  exit(0)
51 
52  self.tts = self.get_proxy("ALTextToSpeech")
53 
54  self.motion = self.get_proxy("ALMotion")
55  if self.motion is not None:
56  if not self.motion.robotIsWakeUp():
57  self.motion.wakeUp()
58 
59  def learnMap(self, radius):
60  '''Learning a new map and saving it
61  Input : maximal radius to explore (in meters)
62  '''
63  #exploration
64  if self.tts is not None:
65  self.tts.post.say(str("starting exploration"))
66 
67  rospy.loginfo("Starting exploration in a radius of %d m", radius)
68 
69  self.setThresholds(0.2, 0.08)
70 
71  self.navigation.explore(radius)
72 
73  self.navigation.stopExploration()
74  rospy.loginfo("Exploration has finished")
75 
76  #saving exploration
77  self.pathtomap = self.navigation.saveExploration()
78  rospy.loginfo("Path to the map: %s", self.pathtomap)
79 
80  if self.tts is not None:
81  self.tts.post.say(str("saving the map"))
82 
83  self.setThresholds(0.4, 0.1)
84 
85  def setThresholds(self, th_orth, th_tan):
86  '''Set safety thresholds
87  Input th_orth : orthogonal security distance
88  Input th_tan : tangential security distance
89  '''
90  if self.motion is not None:
91  self.motion.setOrthogonalSecurityDistance(th_orth)
92  self.motion.setTangentialSecurityDistance(th_tan)
93 
94 if __name__ == '__main__':
95  rospy.loginfo("Exploration based on Naoqi")
96  pub = Exploration()
97 
98  radius = rospy.get_param('~radius', 10)
99  pub.learnMap(radius)
100 
101  exit(0)
def learnMap(self, radius)
Definition: exploration.py:59
def setThresholds(self, th_orth, th_tan)
Definition: exploration.py:85
def get_proxy(self, name, warn=True)


python
Author(s):
autogenerated on Thu Jul 16 2020 03:18:36