nao_laser.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 import roslib
00003 roslib.load_manifest('nao_driver')
00004 import rospy
00005 from nao_driver import NaoNode
00006 from sensor_msgs.msg import LaserScan
00007 from naoqi import ALProxy
00008 
00009 class NaoLaser (NaoNode):
00010     def __init__(self):
00011         NaoNode.__init__(self)
00012         rospy.init_node('nao_laser')
00013 
00014         # for measureddata
00015         self.startpoint = -30.0
00016         self.endpoint = 210.0
00017         self.scaninterval = 0
00018         self.dataGroupingnumber = 1
00019         self.dataInterval = 0.35
00020         self.sensorstate = 'NORMAL'
00021         self.distancenum = 682
00022         # for rangedata
00023         self.minangle = -0.49087
00024         self.maxangle = 3.64474
00025         self.maxdatanum = 768
00026         self.angres = 0.0061
00027         self.minrange = 0.06
00028         self.maxrange = 5.6
00029         self.rangeres = 0.01
00030         self.frequency = 10
00031 
00032         self.laserscan = LaserScan()
00033         self.laserscan.header.frame_id = "/urg_frame"
00034         self.laserscan.range_min = self.minrange
00035         self.laserscan.range_max = self.maxrange
00036 
00037         try:
00038             self.alurg = self.getProxy("ALLaser")
00039             self.alurg.setOpeningAngle(-2.09439, 2.09439)
00040             self.alurg.setDetectingLength(20, 5600)
00041             self.alurg.laserON()
00042         except Exception,e:
00043             print "Error when creating ALLaser proxy:"
00044             print str(e)
00045             exit(1)
00046 
00047         try:
00048             self.almem = self.getProxy("ALMemory")
00049         except Exception,e:
00050             print "Error when creating ALMemory proxy:"
00051             print str(e)
00052             exit(1)
00053 
00054         self.pub_laser = rospy.Publisher('scan', LaserScan)
00055 
00056 
00057     def main_loop(self):
00058         while not rospy.is_shutdown():
00059             try:
00060                 laserdata = self.almem.getData("Device/Laser/Value", 0)
00061             except:
00062                 continue
00063 
00064             self.laserscan.header.stamp = rospy.get_rostime()
00065 
00066             minangle = -1
00067             maxangle = -1
00068             for i in range(len(laserdata)):
00069                 if laserdata[i][1] != 0:
00070                     minangle = laserdata[i][1]
00071                     break
00072             cnt = 0
00073             # distance = []
00074             self.laserscan.ranges = []
00075 
00076             i_pre = -1
00077             for i in range(len(laserdata)):
00078                 if laserdata[i][1] != 0:
00079                     if i_pre >= 0:
00080                         angdif = laserdata[i][1] - laserdata[i_pre][1]
00081                         angrate = int(round(angdif / self.angres, 0))
00082                         # print "i = ", i, ", angrate = ", angrate
00083                         for j in range(angrate - 1):
00084                             # interpolation
00085                             # distance.append(laserdata[i][0])
00086                             self.laserscan.ranges.append(laserdata[i][0] / 1000.0)
00087                             cnt += 1
00088                     # distance.append(laserdata[i][0])
00089                     self.laserscan.ranges.append(laserdata[i][0] / 1000.0)
00090                     i_pre = i
00091                     maxangle = laserdata[i][1]
00092                     cnt += 1
00093                 # print "laserdata[", i_pre, "][0] = ", laserdata[i_pre][0]
00094                 # print "laserdata[", i_pre, "][1] = ", laserdata[i_pre][1]
00095                 # print "cnt = ", cnt
00096             self.laserscan.angle_min = minangle
00097             self.laserscan.angle_max = maxangle
00098             # self.laserscan.angle_increment = (maxangle - minangle) / cnt
00099             self.laserscan.angle_increment = self.angres
00100             self.pub_laser.publish(self.laserscan)
00101 
00102 
00103 if __name__ == "__main__":
00104     try:
00105         naolaser = NaoLaser()
00106         naolaser.main_loop()
00107     except RuntimeError, e:
00108         rospy.logerr('Something went wrong: %s' % (e) )
00109     rospy.loginfo('Laser stopped')
00110 


naoeus
Author(s): Junpei Tsuji
autogenerated on Wed Sep 16 2015 10:29:55