emulation_odom_laser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import argparse
4 import rospy
5 import tf2_ros
6 from geometry_msgs.msg import TransformStamped
7 from nav_msgs.msg import Odometry
8 
9 class EmulationOdomLaser(object):
10  def __init__(self, odom_frame):
11  # this node emulates the laser odom based on the odometry from the base controller
12  #
13  # interfaces
14  # - subscribers:
15  # - /base/odometry_controller/odometry [nav_msgs/Odometry]
16  # - publishers:
17  # - /scan_odom_node/scan_odom/odometry [nav_msgs/Odometry]
18  # - tf (map --> odom_frame)
19 
20 
21  # TODO
22  # - speed factor
23 
24  self._odom_frame = odom_frame
25 
26  rospy.Subscriber("/base/odometry_controller/odometry", Odometry, self.odometry_callback, queue_size=1)
27  self._odom_publisher = rospy.Publisher("/scan_odom_node/scan_odom/odometry", Odometry, queue_size=1)
28 
30 
31  self._odom = Odometry()
32  self._odom.header.frame_id = self._odom_frame
33  self._odom.child_frame_id = "base_footprint"
34  self._odom.pose.pose.orientation.w = 1 # initialize orientation with a valid quaternion
35 
36  rospy.loginfo("Emulation for laser odometry running")
37 
38  def odometry_callback(self, msg):
39  self._odom = msg
40  self._odom.header.frame_id = self._odom_frame
41  self._odom_publisher.publish(self._odom)
42  self.publish_tf()
43 
44  def publish_tf(self):
45  # publish tf
46  # pub base_footprint --> odom_frame
47  t_odom = TransformStamped()
48  t_odom.header.stamp = rospy.Time.now()
49  t_odom.header.frame_id = self._odom_frame
50  t_odom.child_frame_id = "base_footprint"
51  t_odom.transform.translation = self._odom.pose.pose.position
52  t_odom.transform.rotation = self._odom.pose.pose.orientation
53 
54  transforms = [t_odom]
55 
56  self._transform_broadcaster.sendTransform(transforms)
57 
58 if __name__ == '__main__':
59  rospy.init_node('emulation_odom_laser')
60  parser = argparse.ArgumentParser(conflict_handler='resolve',
61  description="Tool for emulating laser odom based on the odometry from the base controller")
62  parser.add_argument('-o', '--odom_frame', help='odom frame name (default: \'odom_combined\')', default='odom_combined')
63  args, unknown = parser.parse_known_args()
64  rospy.loginfo("emulation_odom_laser running!")
65  EmulationOdomLaser(args.odom_frame)
66  rospy.spin()
emulation_odom_laser.EmulationOdomLaser._odom_publisher
_odom_publisher
Definition: emulation_odom_laser.py:27
emulation_odom_laser.EmulationOdomLaser._odom_frame
_odom_frame
Definition: emulation_odom_laser.py:24
emulation_odom_laser.EmulationOdomLaser.__init__
def __init__(self, odom_frame)
Definition: emulation_odom_laser.py:10
emulation_odom_laser.EmulationOdomLaser.publish_tf
def publish_tf(self)
Definition: emulation_odom_laser.py:44
emulation_odom_laser.EmulationOdomLaser.odometry_callback
def odometry_callback(self, msg)
Definition: emulation_odom_laser.py:38
tf2_ros::TransformBroadcaster
emulation_odom_laser.EmulationOdomLaser
Definition: emulation_odom_laser.py:9
emulation_odom_laser.EmulationOdomLaser._odom
_odom
Definition: emulation_odom_laser.py:31
emulation_odom_laser.EmulationOdomLaser._transform_broadcaster
_transform_broadcaster
Definition: emulation_odom_laser.py:29


cob_hardware_emulation
Author(s): Florian Weisshardt
autogenerated on Mon May 1 2023 02:44:27