
We'll create a TF broadcaster to link the IMU frame (imu_link) to the robot's base frame (base_link).
cd ~/catkin_ws/src/mpu6050_driver/scripts
- But in last post, i have made this script directory with "mpu6050_publisher.py". so, i skip this.
nano tf_broadcaster.py
this Script is same above. just edit code.
#!/usr/bin/env python3
import rospy
import tf
from geometry_msgs.msg import TransformStamped
class TFBroadcasterNode:
def __init__(self):
rospy.init_node('imu_tf_broadcaster', anonymous=True)
self.br = tf.TransformBroadcaster()
self.rate = rospy.Rate(10) # 10 Hz
# Define static transformation parameters
self.translation = (0.0, 0.0, 0.0) # Adjust based on sensor placement
self.rotation = (0.0, 0.0, 0.0, 1.0) # Quaternion (x, y, z, w)
def broadcast(self):
while not rospy.is_shutdown():
self.br.sendTransform(
self.translation,
self.rotation,
rospy.Time.now(),
"imu_link",
"base_link"
)
self.rate.sleep()
if __name__ == '__main__':
try:
node = TFBroadcasterNode()
node.broadcast()
except rospy.ROSInterruptException:
pass
Explanation of the Script:
translation and rotation: Define the spatial relationship between base_link and imu_link. Adjust these values based on how the MPU6050 is mounted on robot.
chmod +x tf_broadcaster.py
nano ~/catkin_ws/src/mpu6050_driver/CMakeLists.txt
catkin_install_python(PROGRAMS scripts/tf_broadcaster.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

mkdir -p ~/catkin_ws/src/mpu6050_driver/launch
cd ~/catkin_ws/src/mpu6050_driver/launch
this directory is already made. So, if you same, don't have to.
nano tf_broadcaster.launch
Add the Following Content:
<launch>
<node name="imu_tf_broadcaster" pkg="mpu6050_driver" type="tf_broadcaster.py" output="screen"/>
</launch>

cd ~/catkin_ws
catkin_make
source devel/setup.bash
roslaunch mpu6050_driver tf_broadcaster.launch

Verify(1) - TF Frames in RViz:
In RViz:
Add the TF display if not already present.
Ensure that the transform from base_link to imu_link is correctly represented.
Replace with an actual image or diagram for clarity.
Verify(2) - Check node in rqt
rosrun rosrpt ~~~~ (i don't remember.)