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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 import roslib
00033 roslib.load_manifest('elektron_calibration')
00034
00035 import rospy
00036 from sensor_msgs.msg import LaserScan
00037 from elektron_calibration.msg import ScanDistAngle
00038
00039 from math import *
00040
00041 class ScanToDistAngle:
00042 def __init__(self):
00043 self.min_angle = rospy.get_param('min_angle', -0.3)
00044 self.max_angle = rospy.get_param('max_angle', 0.3)
00045 self.pub = rospy.Publisher('scan_dist_angle', ScanDistAngle)
00046 self.sub = rospy.Subscriber('scan', LaserScan, self.scan_cb)
00047
00048
00049 def scan_cb(self, msg):
00050 angle = msg.angle_min
00051 d_angle = msg.angle_increment
00052 sum_x = 0
00053 sum_y = 0
00054 sum_xx = 0
00055 sum_xy = 0
00056 sum_r = 0
00057 num = 0
00058 for r in msg.ranges:
00059 if angle > self.min_angle and angle < self.max_angle:
00060 x = sin(angle) * r
00061 y = cos(angle) * r
00062 sum_x += x
00063 sum_y += y
00064 sum_xx += x*x
00065 sum_xy += x*y
00066 num += 1
00067 angle += d_angle
00068 angle=atan2((-sum_x*sum_y+num*sum_xy)/(num*sum_xx-sum_x*sum_x), 1)
00069 res = ScanDistAngle()
00070 res.header = msg.header
00071 res.dist = sum_y / num
00072 res.angle= angle
00073 self.pub.publish(res)
00074
00075
00076
00077 def main():
00078 rospy.init_node('scan_to_dist_angle')
00079 s = ScanToDistAngle()
00080 rospy.spin()
00081
00082
00083 if __name__ == '__main__':
00084 main()