Skip to content

Instantly share code, notes, and snippets.

@joshnewans
Created September 10, 2021 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshnewans/d0e7992dba50923a7628110d740050ea to your computer and use it in GitHub Desktop.
Save joshnewans/d0e7992dba50923a7628110d740050ea to your computer and use it in GitHub Desktop.
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