I'm currently facing an issue while working on my robotics project. I have set up a dynamic transform for Lidar data from Map-> odam-> base_footprint->base_link. Following this, I run the ydlidar_ros_driver using the Ydlidar_launch.py file, and then I initiate the slam_toolbox using the online_async_launch.py file.
While the setup successfully creates a transform, I'm encountering a problem with the continuous creation of the map. The map doesn't seem to be updating as expected. I'm using the YDLidar X2.
Has anyone experienced a similar issue or could provide guidance on how to troubleshoot this problem? Any insights or suggestions would be greatly appreciated.
This code that i used to generates transforms for the coordinate frames "map" to "odom," "odom" to "base_footprint," and "base_footprint" to "base_link" using lidar data.
class LidarTransformPublisher(Node):
def __init__(self):
super().__init__('lidar_transform_publisher')
self.tf_broadcaster = tf2_ros.TransformBroadcaster(self)
# Subscribe to lidar data
self.create_subscription(LaserScan, '/scan', self.lidar_callback, rclpy.qos.qos_profile_sensor_data)
def lidar_callback(self, lidar_data):
# Extract relevant information from lidar data
ranges = lidar_data.ranges
angle_increment = lidar_data.angle_increment
# Assuming lidar_data provides an angle for each range
theta = lidar_data.angle_min
for range_value in ranges:
# Calculate x and y based on range and current angle
x = range_value * math.cos(theta)
y = range_value * math.sin(theta)
# Create dynamic transformations
map_to_odom_transform = self.create_transform('map', 'odom', x, y, theta)
odom_to_base_footprint_transform = self.create_transform('odom', 'base_footprint', 2 * x, 2 * y, theta)
base_footprint_to_base_link_transform = self.create_transform('base_footprint', 'base_link', 3 * x, 3 * y, theta)
# Send dynamic transformations
self.tf_broadcaster.sendTransform(map_to_odom_transform)
self.tf_broadcaster.sendTransform(odom_to_base_footprint_transform)
self.tf_broadcaster.sendTransform(base_footprint_to_base_link_transform)
# Increment the angle for the next range
theta += angle_increment
def create_transform(self, parent_frame, child_frame, x, y, theta):
transform = TransformStamped()
transform.header.stamp = self.get_clock().now().to_msg()
transform.header.frame_id = parent_frame
transform.child_frame_id = child_frame
transform.transform.translation.x = x
transform.transform.translation.y = y
transform.transform.translation.z = 0.0
transform.transform.rotation.x = 0.0
transform.transform.rotation.y = 0.0
transform.transform.rotation.z = math.sin(theta / 2.0)
transform.transform.rotation.w = math.cos(theta / 2.0)
return transform
Thank you!