octomap.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2014 Aldebaran Robotics
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 from distutils.version import LooseVersion
18 
19 import rospy
20 
21 from octomap_msgs.msg import Octomap
22 
23 from naoqi_driver.naoqi_node import NaoqiNode
24 from naoqi_sensors_py.boost.octomap_python import octomap_str_to_tuple
25 
27  def __init__(self):
28  NaoqiNode.__init__(self, 'nao_octomap')
29 
30  if self.get_version() < LooseVersion('2.0'):
31  rospy.loginfo('NAOqi version < 2.0, Octomap is not used')
32  exit(0)
33 
34  proxy = self.get_proxy("ALNavigation")
35  if proxy is None:
36  rospy.loginfo('Could not get access to the ALNavigation proxy')
37  exit(1)
38 
39  # Create ROS publisher
40  self.pub = rospy.Publisher("octomap", Octomap, latch = True, queue_size=1)
41 
42  self.fps = 1
43 
44  rospy.loginfo("nao_octomap initialized")
45 
46  def run(self):
47  r = rospy.Rate(self.fps)
48  octomap = Octomap()
49  octomap.header.frame_id = '/odom'
50 
51  while self.is_looping():
52  if self.pub.get_num_connections() > 0:
53  octomap_bin = self.get_proxy("ALNavigation")._get3DMap()
54  if len(octomap_bin) > 129:
55  octomap.binary, octomap.id, octomap.resolution, octomap.data = octomap_str_to_tuple(octomap_bin)
56  if len(octomap.data) > 0:
57  octomap.header.stamp = rospy.Time.now()
58  self.pub.publish(octomap)
59 
60  r.sleep()
61 
62 if __name__ == '__main__':
63  nao_octomap = NaoqiOctomap()
64  nao_octomap.start()
65  rospy.spin()
boost::python::tuple octomap_str_to_tuple(const std::string &str_msg)
def __init__(self)
Definition: octomap.py:27
def run(self)
Definition: octomap.py:46
def get_proxy(self, name, warn=True)


naoqi_sensors_py
Author(s): Séverin Lemaignan, Vincent Rabaud, Karsten Knese, Jack O'Quin, Ken Tossell, Patrick Beeson, Nate Koenig, Andrew Howard, Damien Douxchamps, Dan Dennedy, Daniel Maier
autogenerated on Thu Jul 16 2020 03:18:33