Skip to content

Commit

Permalink
deploy: ccfda52
Browse files Browse the repository at this point in the history
  • Loading branch information
azeey committed Jan 8, 2025
1 parent 7437b9a commit de8940b
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 46 deletions.
Binary file modified docs/acropolis/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/all/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/blueprint/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/citadel/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/dome/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/edifice/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/fortress/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/garden/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/harmonic/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/harmonic/.doctrees/ros2_launch_gazebo.doctree
Binary file not shown.
47 changes: 25 additions & 22 deletions docs/harmonic/_sources/ros2_launch_gazebo.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,48 @@ an option but not strictly necessary as you could decide to hardcode some of the
values or not even use all the parameters.

### Python
Python launch files provide more low-level customization and logic compared to XML launch files.
In the following example, the user can specify a world argument to launch an environment for
the Moon, Mars, or Enceladus. It additionally sets the resource path environment variable and
sets up empty arrays for topics to be bridged and remapped from Gazebo to ROS 2:
Python launch files provide more low-level customization and logic compared to XML launch files. For example, you can set environment variables and include Python specific functions and logic.
In the following example, the user can replace the example package, world, and bridged topic with their own. This is intended as a scaffolding more than something that can be run on its own.

```python
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import (DeclareLaunchArgument, SetEnvironmentVariable,
IncludeLaunchDescription, SetLaunchConfiguration)
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration, TextSubstitution
from launch_ros.actions import Node
from launch.actions import SetEnvironmentVariable, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
pkg_spaceros_gz_sim = get_package_share_directory('spaceros_gz_sim')
ros_gz_sim_pkg_path = get_package_share_directory('ros_gz_sim')
example_pkg_path = FindPackageShare('example_package') # Replace with your own package name
gz_launch_path = PathJoinSubstitution([pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py'])
gz_model_path = PathJoinSubstitution([pkg_spaceros_gz_sim, 'models'])

return LaunchDescription([
DeclareLaunchArgument(
'world',
default_value='moon',
choices=['moon', 'mars', 'enceladus'],
description='World to load into Gazebo'
SetEnvironmentVariable(
'GZ_SIM_RESOURCE_PATH',
PathJoinSubstitution([example_pkg_path, 'models'])
),
SetEnvironmentVariable(
'GZ_SIM_PLUGIN_PATH',
PathJoinSubstitution([example_pkg_path, 'plugins'])
),
SetLaunchConfiguration(name='world_file',
value=[LaunchConfiguration('world'),
TextSubstitution(text='.sdf')]),
SetEnvironmentVariable('GZ_SIM_RESOURCE_PATH', gz_model_path),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(gz_launch_path),
launch_arguments={
'gz_args': [PathJoinSubstitution([pkg_spaceros_gz_sim, 'worlds',
LaunchConfiguration('world_file')])],
'gz_args': [PathJoinSubstitution([example_pkg_path, 'worlds/example_world.sdf'])], # Replace with your own world file
'on_exit_shutdown': 'True'
}.items(),
),

# Bridging and remapping Gazebo topics to ROS 2 (replace with your own topics)
Node(
package='ros_gz_bridge',
executable='parameter_bridge',
arguments=['/example_imu_topic@sensor_msgs/msg/Imu@gz.msgs.IMU',],
remappings=[('/remapped_imu_topic'),],
output='screen'
),
])
```

Expand Down
48 changes: 25 additions & 23 deletions docs/harmonic/ros2_launch_gazebo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -530,44 +530,46 @@ <h3>XML<a class="headerlink" href="#xml" title="Link to this heading">#</a></h3>
</section>
<section id="python">
<h3>Python<a class="headerlink" href="#python" title="Link to this heading">#</a></h3>
<p>Python launch files provide more low-level customization and logic compared to XML launch files.
In the following example, the user can specify a world argument to launch an environment for
the Moon, Mars, or Enceladus. It additionally sets the resource path environment variable and
sets up empty arrays for topics to be bridged and remapped from Gazebo to ROS 2:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ament_index_python.packages</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_package_share_directory</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch</span><span class="w"> </span><span class="kn">import</span> <span class="n">LaunchDescription</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch.actions</span><span class="w"> </span><span class="kn">import</span> <span class="p">(</span><span class="n">DeclareLaunchArgument</span><span class="p">,</span> <span class="n">SetEnvironmentVariable</span><span class="p">,</span>
<span class="n">IncludeLaunchDescription</span><span class="p">,</span> <span class="n">SetLaunchConfiguration</span><span class="p">)</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch.substitutions</span><span class="w"> </span><span class="kn">import</span> <span class="n">PathJoinSubstitution</span><span class="p">,</span> <span class="n">LaunchConfiguration</span><span class="p">,</span> <span class="n">TextSubstitution</span>
<p>Python launch files provide more low-level customization and logic compared to XML launch files. For example, you can set environment variables and include Python specific functions and logic.
In the following example, the user can replace the example package, world, and bridged topic with their own. This is intended as a scaffolding more than something that can be run on its own.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">launch</span><span class="w"> </span><span class="kn">import</span> <span class="n">LaunchDescription</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch_ros.actions</span><span class="w"> </span><span class="kn">import</span> <span class="n">Node</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch.actions</span><span class="w"> </span><span class="kn">import</span> <span class="n">SetEnvironmentVariable</span><span class="p">,</span> <span class="n">IncludeLaunchDescription</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch.launch_description_sources</span><span class="w"> </span><span class="kn">import</span> <span class="n">PythonLaunchDescriptionSource</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch.substitutions</span><span class="w"> </span><span class="kn">import</span> <span class="n">PathJoinSubstitution</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">launch_ros.substitutions</span><span class="w"> </span><span class="kn">import</span> <span class="n">FindPackageShare</span>


<span class="k">def</span><span class="w"> </span><span class="nf">generate_launch_description</span><span class="p">():</span>
<span class="n">pkg_ros_gz_sim</span> <span class="o">=</span> <span class="n">get_package_share_directory</span><span class="p">(</span><span class="s1">&#39;ros_gz_sim&#39;</span><span class="p">)</span>
<span class="n">pkg_spaceros_gz_sim</span> <span class="o">=</span> <span class="n">get_package_share_directory</span><span class="p">(</span><span class="s1">&#39;spaceros_gz_sim&#39;</span><span class="p">)</span>
<span class="n">ros_gz_sim_pkg_path</span> <span class="o">=</span> <span class="n">get_package_share_directory</span><span class="p">(</span><span class="s1">&#39;ros_gz_sim&#39;</span><span class="p">)</span>
<span class="n">example_pkg_path</span> <span class="o">=</span> <span class="n">FindPackageShare</span><span class="p">(</span><span class="s1">&#39;example_package&#39;</span><span class="p">)</span> <span class="c1"># Replace with your own package name</span>
<span class="n">gz_launch_path</span> <span class="o">=</span> <span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">pkg_ros_gz_sim</span><span class="p">,</span> <span class="s1">&#39;launch&#39;</span><span class="p">,</span> <span class="s1">&#39;gz_sim.launch.py&#39;</span><span class="p">])</span>
<span class="n">gz_model_path</span> <span class="o">=</span> <span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">pkg_spaceros_gz_sim</span><span class="p">,</span> <span class="s1">&#39;models&#39;</span><span class="p">])</span>

<span class="k">return</span> <span class="n">LaunchDescription</span><span class="p">([</span>
<span class="n">DeclareLaunchArgument</span><span class="p">(</span>
<span class="s1">&#39;world&#39;</span><span class="p">,</span>
<span class="n">default_value</span><span class="o">=</span><span class="s1">&#39;moon&#39;</span><span class="p">,</span>
<span class="n">choices</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;moon&#39;</span><span class="p">,</span> <span class="s1">&#39;mars&#39;</span><span class="p">,</span> <span class="s1">&#39;enceladus&#39;</span><span class="p">],</span>
<span class="n">description</span><span class="o">=</span><span class="s1">&#39;World to load into Gazebo&#39;</span>
<span class="n">SetEnvironmentVariable</span><span class="p">(</span>
<span class="s1">&#39;GZ_SIM_RESOURCE_PATH&#39;</span><span class="p">,</span>
<span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">example_pkg_path</span><span class="p">,</span> <span class="s1">&#39;models&#39;</span><span class="p">])</span>
<span class="p">),</span>
<span class="n">SetEnvironmentVariable</span><span class="p">(</span>
<span class="s1">&#39;GZ_SIM_PLUGIN_PATH&#39;</span><span class="p">,</span>
<span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">example_pkg_path</span><span class="p">,</span> <span class="s1">&#39;plugins&#39;</span><span class="p">])</span>
<span class="p">),</span>
<span class="n">SetLaunchConfiguration</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;world_file&#39;</span><span class="p">,</span>
<span class="n">value</span><span class="o">=</span><span class="p">[</span><span class="n">LaunchConfiguration</span><span class="p">(</span><span class="s1">&#39;world&#39;</span><span class="p">),</span>
<span class="n">TextSubstitution</span><span class="p">(</span><span class="n">text</span><span class="o">=</span><span class="s1">&#39;.sdf&#39;</span><span class="p">)]),</span>
<span class="n">SetEnvironmentVariable</span><span class="p">(</span><span class="s1">&#39;GZ_SIM_RESOURCE_PATH&#39;</span><span class="p">,</span> <span class="n">gz_model_path</span><span class="p">),</span>
<span class="n">IncludeLaunchDescription</span><span class="p">(</span>
<span class="n">PythonLaunchDescriptionSource</span><span class="p">(</span><span class="n">gz_launch_path</span><span class="p">),</span>
<span class="n">launch_arguments</span><span class="o">=</span><span class="p">{</span>
<span class="s1">&#39;gz_args&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">pkg_spaceros_gz_sim</span><span class="p">,</span> <span class="s1">&#39;worlds&#39;</span><span class="p">,</span>
<span class="n">LaunchConfiguration</span><span class="p">(</span><span class="s1">&#39;world_file&#39;</span><span class="p">)])],</span>
<span class="s1">&#39;gz_args&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">PathJoinSubstitution</span><span class="p">([</span><span class="n">example_pkg_path</span><span class="p">,</span> <span class="s1">&#39;worlds/example_world.sdf&#39;</span><span class="p">])],</span> <span class="c1"># Replace with your own world file</span>
<span class="s1">&#39;on_exit_shutdown&#39;</span><span class="p">:</span> <span class="s1">&#39;True&#39;</span>
<span class="p">}</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span>
<span class="p">),</span>

<span class="c1"># Bridging and remapping Gazebo topics to ROS 2 (replace with your own topics)</span>
<span class="n">Node</span><span class="p">(</span>
<span class="n">package</span><span class="o">=</span><span class="s1">&#39;ros_gz_bridge&#39;</span><span class="p">,</span>
<span class="n">executable</span><span class="o">=</span><span class="s1">&#39;parameter_bridge&#39;</span><span class="p">,</span>
<span class="n">arguments</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;/example_imu_topic@sensor_msgs/msg/Imu@gz.msgs.IMU&#39;</span><span class="p">,],</span>
<span class="n">remappings</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;/remapped_imu_topic&#39;</span><span class="p">),],</span>
<span class="n">output</span><span class="o">=</span><span class="s1">&#39;screen&#39;</span>
<span class="p">),</span>
<span class="p">])</span>
</pre></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/harmonic/searchindex.js

Large diffs are not rendered by default.

Binary file modified docs/ionic/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/jetty/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/latest/.doctrees/environment.pickle
Binary file not shown.
Binary file modified libs/.doctrees/environment.pickle
Binary file not shown.

0 comments on commit de8940b

Please sign in to comment.