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
00019 import rospy
00020 from sensor_msgs.msg import Range
00021
00022
00023 from nao_driver import NaoNode
00024
00025 class SonarSensor(object):
00026
00027
00028
00029
00030 SONAR_FREQ = 10
00031 SONAR_MIN_RANGE = 0.25
00032 SONAR_MAX_RANGE = 2.55
00033 SONAR_FOV = 0.523598776
00034
00035 def __init__(self, memoryKey, frameID, rosTopic):
00036 self.memoryKey = memoryKey
00037 self.rosTopic = rosTopic
00038
00039 self.msg = Range()
00040 self.msg.header.frame_id = frameID
00041 self.msg.min_range = self.SONAR_MIN_RANGE
00042 self.msg.max_range = self.SONAR_MAX_RANGE
00043 self.msg.field_of_view = self.SONAR_FOV
00044 self.msg.radiation_type = Range.ULTRASOUND
00045
00046
00047 class SonarPublisher(NaoNode):
00048
00049 NAOQI_SONAR_SUB_NAME = 'ros_sonar_subsription'
00050
00051 def __init__(self, sonarSensorList, param_sonar_rate="~sonar_rate", sonar_rate=40):
00052 NaoNode.__init__(self, "sonar_publisher")
00053 self.sonarRate = rospy.Rate(rospy.get_param(param_sonar_rate, sonar_rate))
00054 self.connectNaoQi()
00055
00056 self.sonarSensorList = sonarSensorList
00057 self.publisherList = []
00058 for sonarSensor in sonarSensorList:
00059 self.publisherList.append(
00060 rospy.Publisher(sonarSensor.rosTopic, Range, queue_size=5))
00061
00062
00063 def connectNaoQi(self):
00064 rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
00065 self.sonarProxy = self.get_proxy("ALSonar")
00066 self.memProxy = self.get_proxy("ALMemory")
00067 if self.sonarProxy is None or self.memProxy is None:
00068
00069 exit(1)
00070
00071
00072 def run(self):
00073
00074 self.sonarProxy.subscribe(self.NAOQI_SONAR_SUB_NAME)
00075
00076 while self.is_looping():
00077 for i in range(len(self.sonarSensorList)):
00078 sonar = self.sonarSensorList[i]
00079 sonar.msg.header.stamp = rospy.Time.now()
00080
00081 try:
00082 sonar.msg.range = self.memProxy.getData(sonar.memoryKey)
00083 except RuntimeError as e:
00084 print 'key not found, correct robot ?', e
00085 break
00086
00087
00088 self.publisherList[i].publish(sonar.msg)
00089
00090 self.sonarRate.sleep()
00091
00092
00093 self.sonarProxy.unsubscribe(self.NAOQI_SONAR_SUB_NAME)
nao_sensors
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 Mon Oct 6 2014 02:40:25