scan_to_dist_angle.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2011, Robot Control and Pattern Recognition Group, Warsaw University of Technology
00006 #
00007 # All rights reserved.
00008 # 
00009 # Redistribution and use in source and binary forms, with or without
00010 # modification, are permitted provided that the following conditions are met:
00011 #     * Redistributions of source code must retain the above copyright
00012 #       notice, this list of conditions and the following disclaimer.
00013 #     * Redistributions in binary form must reproduce the above copyright
00014 #       notice, this list of conditions and the following disclaimer in the
00015 #       documentation and/or other materials provided with the distribution.
00016 #     * Neither the name of the <organization> nor the
00017 #       names of its contributors may be used to endorse or promote products
00018 #       derived from this software without specific prior written permission.
00019 # 
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00024 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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()


elektron_calibration
Author(s): Maciej StefaƄczyk
autogenerated on Sun Oct 5 2014 23:43:58