Compare commits

...

13 Commits

Author SHA1 Message Date
Your Name
91c376089f update 2025-01-14 12:49:44 +01:00
Your Name
66829235c3 update 2025-01-14 12:48:43 +01:00
Your Name
a1a70c06e8 update 2025-01-14 12:46:06 +01:00
Your Name
df832c64b7 update 2025-01-14 12:41:33 +01:00
Your Name
edb23af234 update 2025-01-14 12:40:08 +01:00
Your Name
02c4e9d741 update 2025-01-14 12:39:13 +01:00
Your Name
5320103fbe update 2025-01-14 12:37:05 +01:00
Your Name
5963c79e20 update 2025-01-14 12:26:58 +01:00
Your Name
b570ed9646 update 2025-01-14 12:25:15 +01:00
Your Name
b6192019af update 2025-01-14 11:53:14 +01:00
Your Name
4bea3eb5c6 update 2025-01-14 09:35:16 +01:00
Your Name
5dd8b2c27b update 2025-01-14 09:30:25 +01:00
Your Name
14c43a5567 update 2025-01-14 09:06:55 +01:00
3 changed files with 91 additions and 0 deletions

View File

@ -47,6 +47,14 @@ include_directories(
add_executable(odom_publisher nodes/odom_publisher.cpp)
target_link_libraries(odom_publisher ${catkin_LIBRARIES})
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
catkin_install_python(PROGRAMS
nodes/odom_publisher_python.py
nodes/odom_publisher_linus.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
################################################################################
# Install
################################################################################

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import rospy
import tf2_ros
from nav_msgs.msg import Odometry
from geometry_msgs.msg import TransformStamped
def odom_callback(msg):
# Create a TransformStamped message
odom_trans = TransformStamped()
odom_trans.header.stamp = msg.header.stamp
odom_trans.header.frame_id = msg.header.frame_id
# Set child_frame_id explicitly (e.g., base_link)
odom_trans.child_frame_id = "base_link"
# Set the translation
odom_trans.transform.translation.x = msg.pose.pose.position.x
odom_trans.transform.translation.y = msg.pose.pose.position.y
odom_trans.transform.translation.z = msg.pose.pose.position.z
# Set the rotation
odom_trans.transform.rotation = msg.pose.pose.orientation
# Publish the transform
tf_broadcaster.sendTransform(odom_trans)
if __name__ == "__main__":
rospy.init_node("tf2_broadcaster")
# Create a TransformBroadcaster
tf_broadcaster = tf2_ros.TransformBroadcaster()
# Subscribe to the /odom topic
rospy.Subscriber("/odom", Odometry, odom_callback)
rospy.loginfo("TF2 broadcaster node is running...")
# Keep the node running
rospy.spin()

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python
import rospy
from nav_msgs.msg import Odometry
import tf
import math
def normalize_quaternion(x, y, z, w):
norm = math.sqrt(x**2 + y**2 + z**2 + w**2)
return x / norm, y / norm, z / norm, w / norm
def odom_callback(msg):
# Extract position and orientation from the odometry message
position = msg.pose.pose.position
orientation = msg.pose.pose.orientation
# Normalize the quaternion
qx, qy, qz, qw = normalize_quaternion(
orientation.x, orientation.y, orientation.z, orientation.w
)
# Get frame IDs from the message
parent_frame_id = msg.header.frame_id if msg.header.frame_id else "Odometry"
child_frame_id = msg.child_frame_id if msg.child_frame_id else "base_link"
# Broadcast the transformation
br = tf.TransformBroadcaster()
br.sendTransform(
(position.x, position.y, position.z), # Translation
(qx, qy, qz, qw), # Normalized rotation (quaternion)
rospy.Time.now(), # Timestamp
child_frame_id, # Child frame ID
parent_frame_id # Parent frame ID
)
def main():
rospy.init_node('odom_tf_publisher', anonymous=True)
rospy.Subscriber('/odom', Odometry, odom_callback)
rospy.loginfo("TF Publisher for /odom topic is running...")
rospy.spin()
if __name__ == '__main__':
main()