loading_map.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, 'loading_map')
27  self.navigation = None
28  self.connectNaoQi()
29 
30  # (re-) connect to NaoQI:
31  def connectNaoQi(self):
32  rospy.loginfo("Node Loading map at %s:%d", self.pip, self.pport)
33 
34  self.navigation = self.get_proxy("ALNavigation")
35  if self.navigation is None:
36  rospy.logerr("Unable to reach ALNavigation.")
37  exit(0)
38 
39  version_array = self.get_proxy("ALSystem").systemVersion().split('.')
40  if len(version_array) < 3:
41  rospy.logerr("Unable to deduce the system version.")
42  exit(0)
43  version_tuple = (int(version_array[0]), int(version_array[1]), int(version_array[2]))
44  min_version = (2, 5, 2)
45  if version_tuple < min_version:
46  rospy.logerr("Naoqi version " + str(min_version) +
47  " required for localization. Yours is " + str(version_tuple))
48  exit(0)
49 
50  def loadMap(self, pathtomap):
51  '''Loading the map
52  '''
53  self.navigation.stopLocalization()
54  res = self.navigation.loadExploration(pathtomap)
55  if res:
56  rospy.loginfo("The map %s has been loaded", pathtomap)
57  else:
58  rospy.logwarn("The map %s cannot be loaded", pathtomap)
59  return res
60 
61  def relocalization(self, x, y, theta):
62  '''Relocalization of the robot according to the position given as input
63  Input : The robot's position (x, y, theta)
64  '''
65  self.navigation.relocalizeInMap([x ,y ,theta])
66  self.navigation.startLocalization()
67 
68 
69 if __name__ == '__main__':
70  rospy.loginfo("LoadingMap based on Naoqi")
71  pub = LoadingMap()
72 
73  #load the map and relocalize
74  raw_input("Move Pepper to the position that corresponds to\
75  zero in the map and press enter")
76  pathtomap = rospy.get_param('~path_to_map', "")
77  if pub.loadMap(pathtomap):
78  pub.relocalization(0,0,0)
79 
80  exit(0)
def relocalization(self, x, y, theta)
Definition: loading_map.py:61
def loadMap(self, pathtomap)
Definition: loading_map.py:50
def get_proxy(self, name, warn=True)


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