Go to the documentation of this file.00001
00002
00003 import rospy
00004
00005 from geometry_msgs.msg import Twist
00006 from kingfisher_msgs.msg import Drive
00007 from dynamic_reconfigure.server import Server
00008 from kingfisher_node.cfg import TwistConfig
00009 from math import fabs, copysign
00010 from std_msgs.msg import Float32
00011
00012
00013 class TwistSubscriber:
00014 def __init__(self):
00015
00016
00017
00018 self.cmd_pub = rospy.Publisher('cmd_drive', Drive)
00019 rospy.Subscriber("cmd_vel", Twist, self.callback)
00020
00021 srv = Server(TwistConfig, self.reconfigure)
00022
00023 def reconfigure(self, config, level):
00024 self.rotation_scale = config['rotation_scale']
00025 self.fwd_speed_scale = config['fwd_speed_scale']
00026 self.rev_speed_scale = config['rev_speed_scale']
00027 self.left_max = config['left_max']
00028 self.right_max = config['right_max']
00029 return config
00030
00031 def callback(self, twist):
00032 """ Receive twist message, formulate and send Chameleon speed msg. """
00033 cmd = Drive()
00034 speed_scale = 1.0
00035 if twist.linear.x > 0.0: speed_scale = self.fwd_speed_scale
00036 if twist.linear.x < 0.0: speed_scale = self.rev_speed_scale
00037 cmd.left = (twist.linear.x * speed_scale) - (twist.angular.z * self.rotation_scale)
00038 cmd.right = (twist.linear.x * speed_scale) + (twist.angular.z * self.rotation_scale)
00039
00040
00041 if fabs(cmd.left) > 1.0:
00042 cmd.right = cmd.right * 1.0 / fabs(cmd.left)
00043 cmd.left = copysign(1.0, cmd.left)
00044 if fabs(cmd.right) > 1.0:
00045 cmd.left = cmd.left * 1.0 / fabs(cmd.right)
00046 cmd.right = copysign(1.0, cmd.right)
00047
00048
00049 cmd.left *= self.left_max
00050 cmd.right *= self.right_max
00051
00052 self.cmd_pub.publish(cmd)