(Jetson Project#8) Integrate IMU Data with Robot's TF Tree

mseokq23·2024년 11월 24일
0
post-thumbnail

For accurate localization and navigation, it's essential to correctly configure the TF (transform) frames in ROS.

6.1. Create a TF Broadcaster Node (Optional)

If your robot model requires specific TF frames (e.g., linking imu_link to base_link), you can create a TF broadcaster.

1.Navigate to Your ROS Package's Scripts Directory:

cd ~/catkin_ws/src/mpu6050_driver/scripts

2. Create the tf_broadcaster.py Script:

nano tf_broadcaster.py

3. Add the Following Content:

#!/usr/bin/env python3
import rospy
import tf
from geometry_msgs.msg import TransformStamped

def broadcast_tf():
    rospy.init_node('imu_tf_broadcaster')
    br = tf.TransformBroadcaster()
    rate = rospy.Rate(10)  # 10 Hz

    while not rospy.is_shutdown():
        # Define the transform from imu_link to base_link
        translation = (0.0, 0.0, 0.0)  # Adjust based on your robot's configuration
        rotation = (0.0, 0.0, 0.0, 1.0)  # Quaternion (x, y, z, w)

        br.sendTransform(translation,
                         rotation,
                         rospy.Time.now(),
                         "imu_link",
                         "base_link")
        rate.sleep()

if __name__ == '__main__':
    try:
        broadcast_tf()
    except rospy.ROSInterruptException:
        pass

Explanation:
This node broadcasts a static transform between base_link and imu_link.
Adjust translation and rotation based on the physical mounting of the MPU6050 on your robot.

4. Make the Script Executable:

chmod +x tf_broadcaster.py

5. Add to Launch File:

  • Edit mpu6050.launch:

nano ~/catkin_ws/src/mpu6050_driver/launch/mpu6050.launch

  • Add the TF Broadcaster Node:
<launch>
  <node name="mpu6050_publisher" pkg="mpu6050_driver" type="mpu6050_publisher.py" output="screen"/>
  <node name="imu_tf_broadcaster" pkg="mpu6050_driver" type="tf_broadcaster.py" output="screen"/>
</launch>

6. Re-launch the IMU Node with TF Broadcaster && rviz:

  • First terminal:
roslaunch mpu6050_driver mpu6050.launch
  • Second terminal:
rviz

*In RViz: Add the "TF" display. Add "imu", change "Fixed Frame" map to "imu_link"
Ensure that the transform between base_link and imu_link is correctly represented.

can see that base_link and imu_link is correctly represented

7. If need, Calibration

Static Calibration:

  • Place the MPU6050 on a flat, stable surface.
  • Record the zero-offsets for accelerometer and gyroscope.
  • Update the mpu6050_publisher.py script with these calibration values.

8. Automate Node Launching

Create a master launch file that starts all necessary nodes (RPLIDAR, MPU6050, TF broadcaster, etc.) together.

1) Create a New ROS Package (Optional):

  • If you prefer organizing all launch files in one package:
cd ~/catkin_ws/src
catkin_create_pkg robot_bringup rospy

2) Create the Master Launch File:

mkdir -p ~/catkin_ws/src/robot_bringup/launch
nano ~/catkin_ws/src/robot_bringup/launch/bringup.launch

3) Add the Following Content:

<launch>
  <!-- Launch RPLIDAR -->
  <include file="$(find rplidar_ros)/launch/rplidar_a1.launch" />

  <!-- Launch MPU6050 IMU -->
  <include file="$(find mpu6050_driver)/launch/mpu6050.launch" />

  <!-- Add other necessary nodes here -->
</launch>

4) Launch All Nodes Together:

roslaunch robot_bringup bringup.launch

9. Monitoring and Debugging

  • Use rqt_graph to Visualize Node Connections:
rosrun rqt_graph rqt_graph

10. Maintain Security and Permissions

  • Avoid Running ROS Nodes with sudo: Running ROS nodes as the root user can cause permission issues and is generally discouraged.

  • Ensure User is in the dialout Group:
    To access serial ports without sudo:

sudo usermod -a -G dialout $USER

0개의 댓글