00001
00002
00003 """
00004 base_laser_from_tilt.py - extract a base scan from a laser on a tilt stage
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 import roslib; roslib.load_manifest('arbotix_sensors')
00031 import rospy
00032
00033 from sensor_msgs.msg import LaserScan, JointState
00034
00035 class base_laser_from_tilt():
00036 """ Create a base scan from a tilting laser. """
00037
00038 def __init__(self):
00039
00040 self.joint = rospy.get_param("~joint","laser_tilt_mount_joint")
00041 self.copy_position = rospy.get_param("~copy_position",0.0)
00042 self.copy_threshold = rospy.get_param("~copy_threshold",0.05)
00043 self.tilt_scan = rospy.get_param("~tilt_scan","tilt_scan")
00044 self.new_scan = rospy.get_param("~base_scan","base_scan")
00045 self.new_frame_id = rospy.get_param("~base_frame","base_laser_link")
00046
00047
00048 self.scanPub = rospy.Publisher("base_scan", LaserScan)
00049 rospy.Subscriber(self.tilt_scan, LaserScan, self.laserCb)
00050 rospy.Subscriber('joint_states', JointState, self.stateCb)
00051
00052 self.copy = False
00053
00054 rospy.loginfo("Started base_laser sensor '"+name)
00055
00056 def laserCb(self, msg):
00057 if self.copy:
00058 msg.header.frame_id = self.new_frame_id
00059 self.scanPub.publish(msg)
00060 print "Published Base Scan"
00061 self.copy = False
00062
00063 def stateCb(self, msg):
00064 try:
00065 if abs(msg.position[msg.name.index(self.joint)] - self.copy_position) < self.copy_threshold:
00066 self.copy = True
00067 except:
00068 self.copy = False
00069
00070 if __name__ == "__main__":
00071 rospy.init_node("base_laser_from_tilt")
00072 node = base_laser_from_tilt()
00073 rospy.spin()
00074