$search
00001 #!/usr/bin/env python 00002 00003 """ 00004 sensors.py - various conversions from raw analog to sensor range 00005 Copyright (c) 2011 Vanadium Labs LLC. All right reserved. 00006 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions are met: 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright 00012 notice, this list of conditions and the following disclaimer in the 00013 documentation and/or other materials provided with the distribution. 00014 * Neither the name of Vanadium Labs LLC nor the names of its 00015 contributors may be used to endorse or promote products derived 00016 from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00019 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 DISCLAIMED. IN NO EVENT SHALL VANADIUM LABS BE LIABLE FOR ANY DIRECT, INDIRECT, 00022 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00025 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00026 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00027 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 """ 00029 00030 from sensor_msgs.msg import Range 00031 00032 class SharpIR: 00033 radiation_type = Range.INFRARED 00034 field_of_view = 0.001 00035 min_range = 0.0 00036 max_range = 1.0 00037 00038 def convert(self, raw): 00039 """ Convert raw analog (10-bit) to distance. """ 00040 return raw 00041 00042 class gpA710YK(SharpIR): 00043 """ Ultra long-range Sharp IR sensor. """ 00044 min_range = 0.75 00045 max_range = 5.50 00046 00047 def convert(self, raw): 00048 """ Convert raw analog (10-bit) to distance. """ 00049 if raw > 100: 00050 return (497.0/(raw-56)) 00051 else: 00052 return self.max_range+0.1 00053 00054 class gpA02YK(SharpIR): 00055 min_range = 0.20 00056 max_range = 1.50 00057 00058 def convert(self, raw): 00059 """ Convert raw analog (10-bit) to distance. """ 00060 if raw > 80: 00061 return (115.0/(raw-12)) 00062 else: 00063 return self.max_range+0.1 00064 00065 class gp2d12(SharpIR): 00066 """ The typical GP2D12 IR ranger. """ 00067 min_range = 0.10 00068 max_range = 0.80 00069 00070 def convert(self, raw): 00071 """ Convert raw analog (10-bit) to distance. """ 00072 if raw > 40: 00073 return (52.0/(raw-12)) 00074 else: 00075 return self.max_range+0.1 00076 00077 class maxSonar(): 00078 radiation_type = Range.ULTRASOUND 00079 field_of_view = 0.785398163 00080 min_range = 0.0 00081 max_range = 6.4516 00082 00083 def convert(self, raw): 00084 """ Convert raw analog (10-bit) to distance. """ 00085 return 12.7 * (raw/1024.0) 00086