Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019
00020
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
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
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
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)