-
Notifications
You must be signed in to change notification settings - Fork 0
Dev kth space lab world #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9eaccb2
9b2f5f7
b601311
c92a014
c0e0f83
f20c9f5
c1880b9
9d671c6
dcfbff7
d2a3a46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| from launch import LaunchDescription | ||
| from launch.actions import ExecuteProcess, DeclareLaunchArgument | ||
| from launch.actions import DeclareLaunchArgument, OpaqueFunction, ExecuteProcess | ||
| from launch.substitutions import LaunchConfiguration | ||
| import os | ||
|
|
||
| def generate_launch_description(): | ||
| """Launch Gazebo with a freeflyer running PX4 communicating over ROS 2.""" | ||
|
|
||
| def launch_px4(context, *args, **kwargs): | ||
| px4_dir = os.getenv("PX4_SPACE_SYSTEMS_DIR") | ||
| if not px4_dir: | ||
| raise RuntimeError("PX4_SPACE_SYSTEMS_DIR is not set. Did you add it to your .bashrc file?") | ||
|
|
||
| return LaunchDescription( | ||
| [ | ||
| # We have the first robot always start with id 0 | ||
| DeclareLaunchArgument("id", default_value="0"), | ||
| DeclareLaunchArgument("pose", default_value="0,0,0"), | ||
| DeclareLaunchArgument("name", default_value="snap"), | ||
| DeclareLaunchArgument("delay", default_value="0"), | ||
| DeclareLaunchArgument("headless", default_value="1"), | ||
| id_ = LaunchConfiguration("id").perform(context) | ||
| pose = LaunchConfiguration("pose").perform(context) | ||
| name = LaunchConfiguration("name").perform(context) | ||
| delay = LaunchConfiguration("delay").perform(context) | ||
| model = LaunchConfiguration("model").perform(context) if "model" in context.launch_configurations else "spacecraft_2d" | ||
| world = LaunchConfiguration("world").perform(context) | ||
|
|
||
| model_name = f"{model}_{id_}" | ||
|
|
||
| use_odom_bridge = LaunchConfiguration("use_odom_bridge").perform(context).lower() == "true" | ||
|
|
||
| processes = [ | ||
| ExecuteProcess( | ||
| cmd=[ | ||
| "bash", "-c", | ||
| f"sleep {delay} && {px4_dir}/build/px4_sitl_default/bin/px4 -i {id_}" | ||
| ], | ||
| cwd=px4_dir, | ||
| env={ | ||
| **os.environ, | ||
| "PX4_SIM_AUTOSTART": "71002", | ||
| "PX4_SIM_SPEED_FACTOR": "1", | ||
| "PX4_GZ_MODEL_POSE": pose, | ||
| "PX4_INSTANCE": id_, | ||
| "PX4_DELAY": delay, | ||
| "PX4_SIM_MODEL": f"gz_{model}", | ||
| "PX4_UXRCE_DDS_NS": name, | ||
| "PX4_GZ_WORLD": world | ||
| }, | ||
| output="screen" | ||
| ) | ||
| ] | ||
|
|
||
| if use_odom_bridge: | ||
| processes.append( | ||
| ExecuteProcess( | ||
| cmd=[ | ||
| "xterm", # or "gnome-terminal", "konsole", "xterm" | ||
| "-hold", # Keep terminal open for debugging | ||
| "-e", | ||
| "bash", | ||
| "-c", | ||
| "sleep $PX4_DELAY && " +px4_dir+"/build/px4_sitl_default/bin/px4 -i $PX4_INSTANCE", | ||
| "ros2", "run", "ros_gz_bridge", "parameter_bridge", | ||
| f"/model/{model_name}/odometry@nav_msgs/msg/Odometry[gz.msgs.Odometry", | ||
| "--ros-args", "-r", f"/model/{model_name}/odometry:=/{name}/odom" | ||
| ], | ||
| cwd=px4_dir, | ||
| env={**os.environ, | ||
| "PX4_SIM_AUTOSTART": "4001", | ||
| "PX4_SIM_SPEED_FACTOR": "1", | ||
| "PX4_GZ_MODEL_POSE": LaunchConfiguration("pose"), | ||
| "PX4_INSTANCE": LaunchConfiguration("id"), | ||
| "PX4_DELAY": LaunchConfiguration("delay"), | ||
| "PX4_SIM_MODEL": "gz_spacecraft_2d", | ||
| "PX4_UXRCE_DDS_NS": LaunchConfiguration("name")}, | ||
| # "HEADLESS": LaunchConfiguration("headless")}, | ||
| output="screen", | ||
| ), | ||
| ] | ||
| ) | ||
| output="screen" | ||
| ) | ||
| ) | ||
|
|
||
| return processes | ||
|
|
||
| def generate_launch_description(): | ||
| return LaunchDescription([ | ||
| DeclareLaunchArgument("id", default_value="0"), | ||
| DeclareLaunchArgument("pose", default_value="0,0,0"), | ||
| DeclareLaunchArgument("name", default_value="snap"), | ||
| DeclareLaunchArgument("delay", default_value="0"), | ||
| DeclareLaunchArgument("world", default_value=""), | ||
| DeclareLaunchArgument("use_odom_bridge", default_value="false"), | ||
|
|
||
| OpaqueFunction(function=launch_px4) | ||
| ]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env python | ||
| from ament_index_python.packages import get_package_share_directory | ||
| from launch import LaunchDescription | ||
| from launch.actions import IncludeLaunchDescription | ||
| from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
|
||
| def generate_launch_description(): | ||
| """Launch multiple spacecrafts in the kthspacelab world with PX4 and ROS 2.""" | ||
| ld = LaunchDescription() | ||
|
|
||
| # Path to the shared px4 launcher | ||
| px4_launch_path = [get_package_share_directory('discower_launch'), '/px4.launch.py'] | ||
|
|
||
| # First agent | ||
| spacecraft_0 = IncludeLaunchDescription( | ||
| PythonLaunchDescriptionSource(px4_launch_path), | ||
| launch_arguments={ | ||
| 'id': '0', | ||
| 'pose': '1,0,0.2', | ||
| 'name': 'snap', | ||
| 'delay': '0', | ||
| 'world': 'kthspacelab', | ||
| 'use_odom_bridge': 'true', | ||
| }.items() | ||
| ) | ||
|
|
||
| # Second agent | ||
| spacecraft_1 = IncludeLaunchDescription( | ||
| PythonLaunchDescriptionSource(px4_launch_path), | ||
| launch_arguments={ | ||
| 'id': '1', | ||
| 'pose': '2,0,0.2', | ||
| 'name': 'crackle', | ||
| 'delay': '5', | ||
| 'world': 'kthspacelab', | ||
| 'use_odom_bridge': 'true', | ||
| }.items() | ||
| ) | ||
|
|
||
| # Third agent | ||
| spacecraft_2 = IncludeLaunchDescription( | ||
| PythonLaunchDescriptionSource(px4_launch_path), | ||
| launch_arguments={ | ||
| 'id': '2', | ||
| 'pose': '3,0,0.2', | ||
| 'name': 'pop', | ||
| 'delay': '5', | ||
| 'world': 'kthspacelab', | ||
| 'use_odom_bridge': 'true', | ||
| }.items() | ||
| ) | ||
|
|
||
| # Add all to launch description | ||
| ld.add_action(spacecraft_0) | ||
| ld.add_action(spacecraft_1) | ||
| ld.add_action(spacecraft_2) | ||
|
|
||
| return ld |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env python | ||
| from ament_index_python.packages import get_package_share_directory | ||
| from launch import LaunchDescription | ||
| from launch.actions import IncludeLaunchDescription | ||
| from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
|
||
| def generate_launch_description(): | ||
| """Launch Gazebo with a spacecraft in the kthspacelab world and ROS bridge.""" | ||
| px4_launch_path = [get_package_share_directory('discower_launch'), '/px4.launch.py'] | ||
|
|
||
| return LaunchDescription([ | ||
| IncludeLaunchDescription( | ||
| PythonLaunchDescriptionSource(px4_launch_path), | ||
| launch_arguments={ | ||
| 'id': '0', | ||
| 'pose': '2,0,0', | ||
| 'name': 'snap', | ||
| 'delay': '0', | ||
| 'world': 'kthspacelab', | ||
| 'use_odom_bridge': 'true', | ||
| }.items() | ||
| ) | ||
| ]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| maintainer_email='[email protected]', | ||
| description='simple SITL launch files for single- and multi-agent simulation of the ATMOS platform', | ||
| license='BSD 3-Clause', | ||
| tests_require=['pytest'], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this removal?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I'll verify and update it. |
||
| extras_require={ | ||
| 'test': ['pytest'] | ||
| }, | ||
| entry_points={}, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.