pod.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (C) 2014 Aldebaran Robotics
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #     http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 #
00017 
00018 #import ROS dependencies
00019 import rospy
00020 from visualization_msgs.msg import Marker
00021 from naoqi_bridge_msgs.msg import PoseWithConfidenceStamped
00022 
00023 #import NAO dependencies
00024 from naoqi_driver.naoqi_node import NaoqiNode
00025 import almath
00026 
00027 
00028 class PodPublisher(NaoqiNode):
00029 
00030     def __init__(self):
00031         NaoqiNode.__init__(self, 'naoqi_pod_node')
00032 
00033         self.markerpublisher = rospy.Publisher('naoqi_pod_publisher', PoseWithConfidenceStamped, queue_size=5)
00034         self.rate = rospy.Rate(2)
00035         self.init = False
00036         self.connectNaoQi()
00037 
00038     # (re-) connect to NaoQI:
00039     def connectNaoQi(self):
00040         rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
00041         self.rechargeProxy = self.get_proxy("ALRecharge")
00042         if self.rechargeProxy is not None:
00043             self.init = True
00044 
00045     # do it!
00046     def run(self):
00047         while self.is_looping():
00048             if not self.init:
00049                 break
00050             if self.markerpublisher.get_num_connections() > 0:
00051                 worldToPod = almath.Pose2D(self.rechargeProxy.getStationPosition())
00052                 confidence = self.rechargeProxy._getConfidenceIndex()
00053                 self.marker = PoseWithConfidenceStamped()
00054                 self.marker.header.stamp = rospy.Time.now()
00055                 self.marker.header.frame_id = "/odom"
00056                 self.marker.pose.orientation = almath.Quaternion_fromAngleAndAxisRotation(worldToPod.theta, 0, 0, 1)
00057                 self.marker.pose.position.x = worldToPod.x
00058                 self.marker.pose.position.y = worldToPod.y
00059                 self.marker.pose.position.z = 0.0
00060                 self.marker.confidence_index = confidence
00061                 self.markerpublisher.publish(self.marker)
00062             self.rate.sleep()
00063 
00064 if __name__ == '__main__':
00065     publisher = PodPublisher()
00066     publisher.start()
00067     rospy.spin()
00068     exit(0)


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