Skip to content

Instantly share code, notes, and snippets.

@PeterMitrano
Created August 4, 2025 10:43
Show Gist options
  • Save PeterMitrano/4cf3faa9cdb63963f380c9356ac3ae01 to your computer and use it in GitHub Desktop.
Save PeterMitrano/4cf3faa9cdb63963f380c9356ac3ae01 to your computer and use it in GitHub Desktop.
How to run the equivalent of `ros2 launch` in python, so it can be debugged
import launch
import launch_ros
from launch import LaunchService
from launch.frontend import Parser
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.utilities import normalize_to_list_of_substitutions
import os
# Absolute path to your launch file
launch_file_path = (
"/home/peter.mitrano/code/src/p2_4_ros2/p2_4_hardware/launch/debug_jtc.launch.py"
)
def main():
# Create the launch service
ls = LaunchService()
# Load the launch description from the file
launch_description = PythonLaunchDescriptionSource(
launch_file_path,
).get_launch_description(context=ls.context)
# Include it in the launch service
ls.include_launch_description(launch_description)
# Run the launch service
out = ls.run()
return out
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment