dummy_transform_publisher.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import geometry_msgs.msg
3 import rospy
4 import tf2_ros
5 
6 if __name__ == '__main__':
7  """
8  Broadcast a transform from parent_frame to target_frame forever,
9  with changing translation.
10  """
11 
12  rospy.init_node('dummy_transform_publisher', anonymous=True)
14  current_transform = geometry_msgs.msg.TransformStamped()
15  current_transform.header.frame_id = rospy.get_param('~parent_frame')
16  current_transform.child_frame_id = rospy.get_param('~child_frame')
17  # Ensure rotation quaternion is well-formed
18  current_transform.transform.rotation.w = 1.0
19 
20  osc_rate_hz = rospy.get_param('~osc_rate')
21  update_rate_hz = rospy.get_param('~update_rate')
22  # we oscillate between 0 and 1, so this is our step size
23  # for osc_rate = 1Hz, update_rate = 60Hz -> 1/60
24  step_size = (1.0 * osc_rate_hz) / update_rate_hz
25  update_rate = rospy.Rate(update_rate_hz)
26  counting_up = True
27 
28  while not rospy.is_shutdown():
29  current_transform.header.stamp = rospy.Time.now()
30  if counting_up:
31  current_transform.transform.translation.x += step_size
32  if current_transform.transform.translation.x >= 1.0:
33  counting_up = False
34  else:
35  current_transform.transform.translation.x -= step_size
36  if current_transform.transform.translation.x <= 0.0:
37  counting_up = True
38  br.sendTransform(current_transform)
39  update_rate.sleep()
40 
41 
42 


tf2_web_republisher
Author(s): Julius Kammer
autogenerated on Mon Apr 5 2021 03:02:43