exploration.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Copyright (C) 2017 SoftBank Robotics Europe
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 #import ROS dependencies
00018 import rospy
00019 
00020 #import NAO dependencies
00021 from naoqi_driver.naoqi_node import NaoqiNode
00022 
00023 class Exploration(NaoqiNode):
00024 
00025     def __init__(self):
00026         NaoqiNode.__init__(self, 'naoqi_exploration')
00027         self.navigation = None
00028         self.connectNaoQi()
00029 
00030     # (re-) connect to NaoQI:
00031     def connectNaoQi(self):
00032         '''Connect to Naoqi modules
00033         '''
00034         rospy.loginfo("Exploration Node Connecting to NaoQi at %s:%d", self.pip, self.pport)
00035 
00036         self.navigation = self.get_proxy("ALNavigation")
00037         if self.navigation is None:
00038             rospy.logerr("Unable to reach ALNavigation.")
00039             exit(0)
00040 
00041         version_array = self.get_proxy("ALSystem").systemVersion().split('.')
00042         if len(version_array) < 3:
00043             rospy.logerr("Unable to deduce the system version.")
00044             exit(0)
00045         version_tuple = (int(version_array[0]), int(version_array[1]), int(version_array[2]))
00046         min_version = (2, 5, 2)
00047         if version_tuple < min_version:
00048             rospy.logerr("Naoqi version " + str(min_version) +
00049             " required for localization. Yours is " + str(version_tuple))
00050             exit(0)
00051 
00052         self.tts  = self.get_proxy("ALTextToSpeech")
00053 
00054         self.motion = self.get_proxy("ALMotion")
00055         if self.motion is not None:
00056             if not self.motion.robotIsWakeUp():
00057                 self.motion.wakeUp()
00058 
00059     def learnMap(self, radius):
00060         '''Learning a new map and saving it
00061         Input  : maximal radius to explore (in meters)
00062         '''
00063         #exploration
00064         if self.tts is not None:
00065             self.tts.post.say(str("starting exploration"))
00066 
00067         rospy.loginfo("Starting exploration in a radius of %d m", radius)
00068 
00069         self.setThresholds(0.2, 0.08)
00070 
00071         self.navigation.explore(radius)
00072 
00073         self.navigation.stopExploration()
00074         rospy.loginfo("Exploration has finished")
00075 
00076         #saving exploration
00077         self.pathtomap = self.navigation.saveExploration()
00078         rospy.loginfo("Path to the map: %s", self.pathtomap)
00079 
00080         if self.tts is not None:
00081             self.tts.post.say(str("saving the map"))
00082 
00083         self.setThresholds(0.4, 0.1)
00084 
00085     def setThresholds(self, th_orth, th_tan):
00086         '''Set safety thresholds
00087         Input th_orth : orthogonal security distance
00088         Input th_tan : tangential security distance
00089         '''
00090         if self.motion is not None:
00091             self.motion.setOrthogonalSecurityDistance(th_orth)
00092             self.motion.setTangentialSecurityDistance(th_tan)
00093 
00094 if __name__ == '__main__':
00095     rospy.loginfo("Exploration based on Naoqi")
00096     pub = Exploration()
00097 
00098     radius = rospy.get_param('~radius', 10)
00099     pub.learnMap(radius)
00100 
00101     exit(0)


python
Author(s):
autogenerated on Wed Aug 16 2017 02:28:15