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 import rospy
00030 from nav_msgs.msg import Odometry
00031 from math import pi
00032
00033
00034 class NovatelWheelVelocity(object):
00035 """ Subscribes to a platform's odom topic and sends SPAN
00036 wheelvelocity messages about the platform's linear movement. """
00037
00038 def __init__(self, port):
00039 self.port = port
00040
00041
00042
00043
00044 self.fake_wheel_diameter = rospy.get_param("~fake_wheel/diameter", 0.33)
00045 self.fake_wheel_ticks = rospy.get_param("~fake_wheel/ticks", 1000)
00046
00047
00048
00049 self.latency = rospy.get_param("~wheel_velocity_latency", 100)
00050 max_frequency = rospy.get_param("~wheel_velocity_max_frequency", 1.0)
00051 self.minimum_period = rospy.Duration(1.0 / max_frequency)
00052
00053
00054 self.circumference = self.fake_wheel_diameter * pi
00055 cmd = 'setwheelparameters %d %f %f' % (
00056 self.fake_wheel_ticks,
00057 self.circumference,
00058 self.circumference / self.fake_wheel_ticks)
00059
00060 rospy.logdebug("Sending: %s" % cmd)
00061 self.port.send(cmd)
00062
00063 self.cumulative_ticks = 0
00064 self.last_received_stamp = None
00065 self.last_sent = None
00066 rospy.Subscriber('odom', Odometry, self.odom_handler)
00067
00068 def odom_handler(self, odom):
00069 if self.last_received_stamp:
00070
00071 velocity = abs(odom.twist.twist.linear.x)
00072 velocity_ticks = velocity * self.fake_wheel_ticks / self.circumference
00073
00074 period = (odom.header.stamp - self.last_received_stamp).to_sec()
00075 self.cumulative_ticks += velocity_ticks * period
00076
00077 cmd = 'wheelvelocity %d %d %d 0 %f 0 0 %d \r\n' % (
00078 self.latency,
00079 self.fake_wheel_ticks,
00080 int(velocity_ticks),
00081 velocity_ticks,
00082 self.cumulative_ticks)
00083
00084 if not self.last_sent or (odom.header.stamp - self.last_sent) > self.minimum_period:
00085 rospy.logdebug("Sending: %s" % repr(cmd))
00086 self.port.send(cmd)
00087 self.last_sent = odom.header.stamp
00088
00089 self.last_received_stamp = odom.header.stamp