cmd_vel_to_ackermann_drive.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Author: christoph.roesmann@tu-dortmund.de
4 
5 import rospy, math
6 from geometry_msgs.msg import Twist
7 from ackermann_msgs.msg import AckermannDriveStamped
8 
9 
10 def convert_trans_rot_vel_to_steering_angle(v, omega, wheelbase):
11  if omega == 0 or v == 0:
12  return 0
13 
14  radius = v / omega
15  return math.atan(wheelbase / radius)
16 
17 
18 def cmd_callback(data):
19  global wheelbase
20  global ackermann_cmd_topic
21  global frame_id
22  global pub
23  global cmd_angle_instead_rotvel
24 
25  v = data.linear.x
26  # if cmd_angle_instead_rotvel is true, the rotational velocity is already converted in the C++ node
27  # in this case this script only needs to do the msg conversion from twist to Ackermann drive
28  if cmd_angle_instead_rotvel:
29  steering = data.angular.z
30  else:
31  steering = convert_trans_rot_vel_to_steering_angle(v, data.angular.z, wheelbase)
32 
33  msg = AckermannDriveStamped()
34  msg.header.stamp = rospy.Time.now()
35  msg.header.frame_id = frame_id
36  msg.drive.steering_angle = steering
37  msg.drive.speed = v
38 
39  pub.publish(msg)
40 
41 
42 
43 
44 
45 if __name__ == '__main__':
46  try:
47 
48  rospy.init_node('cmd_vel_to_ackermann_drive')
49 
50  twist_cmd_topic = rospy.get_param('~twist_cmd_topic', '/cmd_vel')
51  ackermann_cmd_topic = rospy.get_param('~ackermann_cmd_topic', '/ackermann_cmd')
52  wheelbase = rospy.get_param('~wheelbase', 1.0)
53  frame_id = rospy.get_param('~frame_id', 'odom')
54  cmd_angle_instead_rotvel = rospy.get_param('/move_base/TebLocalPlannerROS/cmd_angle_instead_rotvel', False)
55 
56  rospy.Subscriber(twist_cmd_topic, Twist, cmd_callback, queue_size=1)
57  pub = rospy.Publisher(ackermann_cmd_topic, AckermannDriveStamped, queue_size=1)
58 
59  rospy.loginfo("Node 'cmd_vel_to_ackermann_drive' started.\nListening to %s, publishing to %s. Frame id: %s, wheelbase: %f", "/cmd_vel", ackermann_cmd_topic, frame_id, wheelbase)
60 
61  rospy.spin()
62 
63  except rospy.ROSInterruptException:
64  pass
65 
def convert_trans_rot_vel_to_steering_angle(v, omega, wheelbase)


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Wed Jun 3 2020 04:03:08