Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Robot State Publisher Launch File
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
import xacro
def generate_launch_description():
# Specify the name of the package and path to xacro file within the package
pkg_name = 'my_package'
file_subpath = 'description/example_robot.urdf.xacro'
# Use xacro to process the file
xacro_file = os.path.join(get_package_share_directory(pkg_name),file_subpath)
robot_description_raw = xacro.process_file(xacro_file).toxml()
# Configure the node
node_robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[{'robot_description': robot_description_raw}] # add other parameters here if required
)
# Run the node
return LaunchDescription([
node_robot_state_publisher
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment