Skip to content

Commit

Permalink
Port demos to the generic ros2 launch file so all rosargs are now exp…
Browse files Browse the repository at this point in the history
…osed in all demos
  • Loading branch information
jlblancoc committed Dec 23, 2024
1 parent 03b7955 commit 4536dca
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 306 deletions.
144 changes: 139 additions & 5 deletions docs/mvsim_node.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,149 @@
mvsim ROS node
Use from ROS
===================

This page describes the ROS 1 and ROS 2 node for MVSim, which
is an executable named `mvsim_node` that is shipped with the
ROS package named `mvsim`.
MVSim comes with a ROS 1 and ROS 2 **node** (an executable named `mvsim_node`),
which is shipped with the **ROS package** named `mvsim`.

.. note::
You can also use the cli application ``mvsim`` if you want to test or run your world without launching a whole ROS system.
See :ref:`mvsim cli`.


Generic launch file
-------------------------
This launch file can be used to launch a simulated world integrated with ROS from the command line,
or can be also included into your own launch file by setting its **ROS launch arguments**.

Write me!
|
Basic usage from the command line
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. tab-set::
.. tab-item:: ROS 1

.. code-block:: bash
roslaunch mvsim launch_world.launch \
XX
.. tab-item:: ROS 2
:selected:

.. code-block:: bash
ros2 launch mvsim launch_world.launch.py \
world_file:=/path/to/your/my.world.xml
|
All launch parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. tab-set::
.. tab-item:: ROS 1

.. code-block:: bash
xxx
.. tab-item:: ROS 2
:selected:

.. code-block:: bash
$ ros2 launch mvsim launch_world.launch.py --show-args
Arguments (pass arguments as '<name>:=<value>'):
'world_file':
Path to the *.world.xml file to load
'headless':
no description given
(default: 'False')
'do_fake_localization':
publish fake identity tf "map" -> "odom"
(default: 'True')
'publish_tf_odom2baselink':
publish tf "odom" -> "base_link"
(default: 'True')
'force_publish_vehicle_namespace':
Use vehicle name namespace even if there is only one vehicle
(default: 'False')
'use_rviz':
Whether to launch RViz2
(default: 'True')
'rviz_config_file':
If use_rviz:="True", the configuration file for rviz
(default: '')
|
How to include it into your own launch
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can use this code to bootstrap your own launch files:
.. tab-set::
.. tab-item:: ROS 1
.. code-block:: bash
xxx
.. tab-item:: ROS 2
:selected:
.. code-block:: python
import os
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
# *** REMEMBER: Change this to your actual world file ***
world_file = os.path.join(
get_package_share_directory('my_package'), 'mvsim', 'demo.world.xml')
# and replace this RViz file with yours as needed:
rviz_config_file = os.path.join(
get_package_share_directory('mvsim'), 'mvsim_tutorial', 'demo_depth_camera_ros2.rviz')
headless = 'False'
do_fake_localization = 'True'
publish_tf_odom2baselink = 'True'
force_publish_vehicle_namespace = 'False'
use_rviz = 'True'
# Create LaunchDescription
ld = LaunchDescription()
# Add actions to LaunchDescription
ld.add_action(IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory('mvsim'), 'launch', 'launch_world.launch.py')
),
launch_arguments={
'world_file': world_file,
'headless': headless,
'do_fake_localization': do_fake_localization,
'publish_tf_odom2baselink': publish_tf_odom2baselink,
'force_publish_vehicle_namespace': force_publish_vehicle_namespace,
'use_rviz': use_rviz,
'rviz_config_file': rviz_config_file
}.items()
))
return ld
|
1 change: 0 additions & 1 deletion launch/launch_world.launch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generic ROS2 launch file

from launch import LaunchDescription
from launch.substitutions import TextSubstitution
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
Expand Down
109 changes: 59 additions & 50 deletions mvsim_tutorial/demo_1robot.launch.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
# ROS2 launch file, invoking mvsim/launch/launch_world.launch.py
# See: https://mvsimulator.readthedocs.io/en/latest/mvsim_node.html

# ROS2 launch file

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import TextSubstitution
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.conditions import IfCondition
from launch.actions import DeclareLaunchArgument
from ament_index_python import get_package_share_directory
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
# mvsim directory:
mvsimDir = get_package_share_directory("mvsim")
# print('mvsimDir: ' + mvsimDir)

# args that can be set from the command line or a default will be used
world_file_launch_arg = DeclareLaunchArgument(
"world_file", default_value=TextSubstitution(
text=os.path.join(mvsimDir, 'mvsim_tutorial', 'demo_1robot.world.xml')))
do_fake_localization_arg = DeclareLaunchArgument(
"do_fake_localization", default_value='True', description='publish tf odom -> base_link')
headless_launch_arg = DeclareLaunchArgument(
"headless", default_value='False')
use_rviz_arg = DeclareLaunchArgument(
'use_rviz', default_value='True',
description='Whether to launch RViz2'
)

mvsim_node = Node(
package='mvsim',
executable='mvsim_node',
name='mvsim',
output='screen',
parameters=[
os.path.join(mvsimDir, 'mvsim_tutorial', 'mvsim_ros2_params.yaml'),
{
"world_file": LaunchConfiguration('world_file'),
"headless": LaunchConfiguration('headless'),
"do_fake_localization": LaunchConfiguration('do_fake_localization'),
}]
)

rviz2_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=[
'-d', [os.path.join(mvsimDir, 'mvsim_tutorial', 'demo_1robot_ros2.rviz')]],
condition=IfCondition(LaunchConfiguration('use_rviz'))
)

return LaunchDescription([
world_file_launch_arg,
do_fake_localization_arg,
headless_launch_arg,
mvsim_node,
use_rviz_arg,
rviz2_node,
])

# World to launch:
world_file = os.path.join(
mvsimDir, 'mvsim_tutorial', 'demo_1robot.world.xml')
rviz_config_file = os.path.join(
get_package_share_directory('mvsim'), 'mvsim_tutorial', 'demo_1robot_ros2.rviz')

# Configurable arguments
headless = LaunchConfiguration('headless', default='True')
do_fake_localization = LaunchConfiguration(
'do_fake_localization', default='False')
publish_tf_odom2baselink = LaunchConfiguration(
'publish_tf_odom2baselink', default='False')
force_publish_vehicle_namespace = LaunchConfiguration(
'force_publish_vehicle_namespace', default='True')
use_rviz = LaunchConfiguration('use_rviz', default='False')

# Create LaunchDescription
ld = LaunchDescription()

# Add arguments to LaunchDescription
ld.add_action(DeclareLaunchArgument('headless', default_value='False',
description='Run in headless mode'))
ld.add_action(DeclareLaunchArgument('do_fake_localization', default_value='True',
description='Publish fake identity tf "map" -> "odom"'))
ld.add_action(DeclareLaunchArgument('publish_tf_odom2baselink', default_value='True',
description='Publish tf "odom" -> "base_link"'))
ld.add_action(DeclareLaunchArgument('force_publish_vehicle_namespace', default_value='False',
description='Use vehicle name namespace even if there is only one vehicle'))
ld.add_action(DeclareLaunchArgument('use_rviz', default_value='True',
description='Whether to launch RViz2'))

# Include the original launch file
ld.add_action(IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory('mvsim'),
'launch', 'launch_world.launch.py')
),
launch_arguments={
'world_file': world_file,
'headless': headless,
'do_fake_localization': do_fake_localization,
'publish_tf_odom2baselink': publish_tf_odom2baselink,
'force_publish_vehicle_namespace': force_publish_vehicle_namespace,
'use_rviz': use_rviz,
'rviz_config_file': rviz_config_file
}.items()
))

return ld
101 changes: 60 additions & 41 deletions mvsim_tutorial/demo_depth_camera.launch.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,70 @@
# ROS2 launch file, invoking mvsim/launch/launch_world.launch.py
# See: https://mvsimulator.readthedocs.io/en/latest/mvsim_node.html

# ROS2 launch file

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import TextSubstitution
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.conditions import IfCondition
from launch.actions import DeclareLaunchArgument
from ament_index_python import get_package_share_directory
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
# mvsim directory:
mvsimDir = get_package_share_directory("mvsim")
# print('mvsimDir: ' + mvsimDir)

# args that can be set from the command line or a default will be used
world_file_launch_arg = DeclareLaunchArgument(
"world_file", default_value=TextSubstitution(
text=os.path.join(mvsimDir, 'mvsim_tutorial', 'demo_depth_camera.world.xml')))
do_fake_localization_arg = DeclareLaunchArgument(
"do_fake_localization", default_value='True', description='publish tf odom -> base_link')

mvsim_node = Node(
package='mvsim',
executable='mvsim_node',
name='mvsim',
output='screen',
parameters=[
os.path.join(mvsimDir, 'mvsim_tutorial',
'mvsim_ros2_params.yaml'),
{
"world_file": LaunchConfiguration('world_file'),
"do_fake_localization": LaunchConfiguration('do_fake_localization'),
}]
)

rviz2_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=[
'-d', [os.path.join(mvsimDir, 'mvsim_tutorial', 'demo_depth_camera_ros2.rviz')]]
)

return LaunchDescription([
world_file_launch_arg,
do_fake_localization_arg,
mvsim_node,
rviz2_node
])

# World to launch:
world_file = os.path.join(
mvsimDir, 'mvsim_tutorial', 'demo_depth_camera.world.xml')
rviz_config_file = os.path.join(
get_package_share_directory('mvsim'), 'mvsim_tutorial', 'demo_depth_camera_ros2.rviz')

# Configurable arguments
headless = LaunchConfiguration('headless', default='True')
do_fake_localization = LaunchConfiguration(
'do_fake_localization', default='False')
publish_tf_odom2baselink = LaunchConfiguration(
'publish_tf_odom2baselink', default='False')
force_publish_vehicle_namespace = LaunchConfiguration(
'force_publish_vehicle_namespace', default='True')
use_rviz = LaunchConfiguration('use_rviz', default='False')

# Create LaunchDescription
ld = LaunchDescription()

# Add arguments to LaunchDescription
ld.add_action(DeclareLaunchArgument('headless', default_value='False',
description='Run in headless mode'))
ld.add_action(DeclareLaunchArgument('do_fake_localization', default_value='True',
description='Publish fake identity tf "map" -> "odom"'))
ld.add_action(DeclareLaunchArgument('publish_tf_odom2baselink', default_value='True',
description='Publish tf "odom" -> "base_link"'))
ld.add_action(DeclareLaunchArgument('force_publish_vehicle_namespace', default_value='False',
description='Use vehicle name namespace even if there is only one vehicle'))
ld.add_action(DeclareLaunchArgument('use_rviz', default_value='True',
description='Whether to launch RViz2'))

# Include the original launch file
ld.add_action(IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory('mvsim'),
'launch', 'launch_world.launch.py')
),
launch_arguments={
'world_file': world_file,
'headless': headless,
'do_fake_localization': do_fake_localization,
'publish_tf_odom2baselink': publish_tf_odom2baselink,
'force_publish_vehicle_namespace': force_publish_vehicle_namespace,
'use_rviz': use_rviz,
'rviz_config_file': rviz_config_file
}.items()
))

return ld
Loading

0 comments on commit 4536dca

Please sign in to comment.