Advertisement
marcusvini178

aroc_simulation_launch.py

May 18th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.39 KB | Source Code | 0 0
  1. # Copyright (c) 2018 Intel Corporation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. #     http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15. """This is all-in-one launch script intended for use by nav2 developers."""
  16.  
  17. import os
  18.  
  19. from ament_index_python.packages import get_package_share_directory
  20.  
  21. from launch import LaunchDescription
  22. from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
  23. from launch.conditions import IfCondition
  24. from launch.launch_description_sources import PythonLaunchDescriptionSource
  25. from launch.substitutions import LaunchConfiguration, PythonExpression
  26. from launch_ros.actions import Node
  27.  
  28.  
  29. def generate_launch_description():
  30.     # Get the launch directory
  31.     #bringup_dir = get_package_share_directory('nav2_bringup')
  32.     #launch_dir = os.path.join(bringup_dir, 'launch')
  33.     aroc_dir = get_package_share_directory('aroc_truck_description')
  34.     aroc_launch_dir = os.path.join(aroc_dir, 'launch')
  35.  
  36.     # Create the launch configuration variables
  37.     slam = LaunchConfiguration('slam')
  38.     namespace = LaunchConfiguration('namespace')
  39.     use_namespace = LaunchConfiguration('use_namespace')
  40.     map_yaml_file = LaunchConfiguration('map')
  41.     use_sim_time = LaunchConfiguration('use_sim_time')
  42.     params_file = LaunchConfiguration('params_file')
  43.     autostart = LaunchConfiguration('autostart')
  44.  
  45.     # Launch configuration variables specific to simulation
  46.     rviz_config_file = LaunchConfiguration('rviz_config_file')
  47.     use_simulator = LaunchConfiguration('use_simulator')
  48.     use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
  49.     use_rviz = LaunchConfiguration('use_rviz')
  50.     headless = LaunchConfiguration('headless')
  51.     world = LaunchConfiguration('world')
  52.  
  53.     # Map fully qualified names to relative ones so the node's namespace can be prepended.
  54.     # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
  55.     # https://github.com/ros/geometry2/issues/32
  56.     # https://github.com/ros/robot_state_publisher/pull/30
  57.     # TODO(orduno) Substitute with `PushNodeRemapping`
  58.     #              https://github.com/ros2/launch_ros/issues/56
  59.     remappings = [('/tf', 'tf'),
  60.                   ('/tf_static', 'tf_static')]
  61.  
  62.     # Declare the launch arguments
  63.     declare_namespace_cmd = DeclareLaunchArgument(
  64.         'namespace',
  65.         default_value='',
  66.         description='Top-level namespace')
  67.  
  68.     declare_use_namespace_cmd = DeclareLaunchArgument(
  69.         'use_namespace',
  70.         default_value='false',
  71.         description='Whether to apply a namespace to the navigation stack')
  72.  
  73.     declare_slam_cmd = DeclareLaunchArgument(
  74.         'slam',
  75.         default_value='False',
  76.         description='Whether run a SLAM')
  77.  
  78.     # declare_map_yaml_cmd = DeclareLaunchArgument(
  79.     #     'map',
  80.     #     default_value=os.path.join(
  81.     #         bringup_dir, 'maps', 'turtlebot3_world.yaml'),
  82.     #     description='Full path to map file to load')
  83.     declare_map_yaml_cmd = DeclareLaunchArgument(
  84.     'map',
  85.     default_value=os.path.join(
  86.         aroc_dir, 'map', 'fixed_map.yaml'),
  87.     description='Full path to map file to load')
  88.  
  89.     declare_use_sim_time_cmd = DeclareLaunchArgument(
  90.         'use_sim_time',
  91.         default_value='true',
  92.         description='Use simulation (Gazebo) clock if true')
  93.  
  94.     # declare_params_file_cmd = DeclareLaunchArgument(
  95.     #     'params_file',
  96.     #     default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
  97.     #     description='Full path to the ROS2 parameters file to use for all launched nodes')
  98.     declare_params_file_cmd = DeclareLaunchArgument(
  99.     'params_file',
  100.     default_value=os.path.join(aroc_dir, 'config', 'nav2_params.yaml'),
  101.     description='Full path to the ROS2 parameters file to use for all launched nodes')
  102.  
  103.     declare_autostart_cmd = DeclareLaunchArgument(
  104.         'autostart', default_value='true',
  105.         description='Automatically startup the nav2 stack')
  106.  
  107.     # declare_rviz_config_file_cmd = DeclareLaunchArgument(
  108.     #     'rviz_config_file',
  109.     #     default_value=os.path.join(
  110.     #         bringup_dir, 'rviz', 'nav2_default_view.rviz'),
  111.     #     description='Full path to the RVIZ config file to use')
  112.     declare_rviz_config_file_cmd = DeclareLaunchArgument(
  113.         'rviz_config_file',
  114.         default_value=os.path.join(
  115.             aroc_dir, 'rviz', 'nav2_default_view.rviz'),
  116.         description='Full path to the RVIZ config file to use')
  117.  
  118.     declare_use_simulator_cmd = DeclareLaunchArgument(
  119.         'use_simulator',
  120.         default_value='True',
  121.         description='Whether to start the simulator')
  122.  
  123.     declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
  124.         'use_robot_state_pub',
  125.         default_value='True',
  126.         description='Whether to start the robot state publisher')
  127.  
  128.     declare_use_rviz_cmd = DeclareLaunchArgument(
  129.         'use_rviz',
  130.         default_value='True',
  131.         description='Whether to start RVIZ')
  132.  
  133.     declare_simulator_cmd = DeclareLaunchArgument(
  134.         'headless',
  135.         default_value='False',
  136.         description='Whether to execute gzclient)')
  137.  
  138.     # declare_world_cmd = DeclareLaunchArgument(
  139.     #     'world',
  140.     #     # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
  141.     #     #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
  142.     #     # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
  143.     #     # worlds/turtlebot3_worlds/waffle.model')
  144.     #     default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'),
  145.     #     description='Full path to world model file to load')
  146.     declare_world_cmd = DeclareLaunchArgument(
  147.     'world',
  148.     # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
  149.     #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
  150.     # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
  151.     # worlds/turtlebot3_worlds/waffle.model')
  152.     default_value=os.path.join(aroc_dir, 'world', 'empty.model'),
  153.     description='Full path to world model file to load')
  154.  
  155.     # Specify the actions
  156.     start_gazebo_server_cmd = ExecuteProcess(
  157.         condition=IfCondition(use_simulator),
  158.         cmd=['gzserver', '-s', 'libgazebo_ros_init.so',  '-s', 'libgazebo_ros_factory.so', world],
  159.         cwd=[aroc_launch_dir], output='screen')
  160.  
  161.     start_gazebo_client_cmd = ExecuteProcess(
  162.         condition=IfCondition(PythonExpression(
  163.             [use_simulator, ' and not ', headless])),
  164.         cmd=['gzclient'],
  165.         cwd=[aroc_launch_dir], output='screen')
  166.  
  167.     # urdf = os.path.join(bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')
  168.     urdf = os.path.join(aroc_dir, 'src', 'description', 'aroc_truck_description.urdf')
  169.     #urdf = '/home/rota/nav2_ws/src/aroc_truck_description/aroc_truck_description/src/description/aroc_truck_description.urdf'
  170.  
  171.  
  172.     start_robot_state_publisher_cmd = Node(
  173.         condition=IfCondition(use_robot_state_pub),
  174.         package='robot_state_publisher',
  175.         executable='robot_state_publisher',
  176.         name='robot_state_publisher',
  177.         namespace=namespace,
  178.         output='screen',
  179.         parameters=[{'use_sim_time': use_sim_time}],
  180.         remappings=remappings,
  181.         arguments=[urdf])
  182.    
  183.     start_joint_state_publisher_cmd = Node(
  184.         condition=IfCondition(use_robot_state_pub),
  185.         package='joint_state_publisher',
  186.         executable='joint_state_publisher',
  187.         name='joint_state_publisher',
  188.         namespace=namespace,
  189.         output='screen',
  190.         parameters=[{'use_sim_time': use_sim_time}],
  191.         remappings=remappings,
  192.         arguments=[urdf])
  193.    
  194.     robot_localization_node = Node(
  195.         package='robot_localization',
  196.         executable='ekf_node',
  197.         name='ekf_filter_node',
  198.         output='screen',
  199.         parameters=[os.path.join(get_package_share_directory('aroc_truck_description'), 'config', 'ekf.yaml'), {'use_sim_time': use_sim_time}],
  200.         remappings=remappings,
  201.     )
  202.  
  203.  
  204.     rviz_cmd = IncludeLaunchDescription(
  205.         PythonLaunchDescriptionSource(
  206.             os.path.join(aroc_launch_dir, 'rviz_launch.py')),
  207.         condition=IfCondition(use_rviz),
  208.         launch_arguments={'namespace': '',
  209.                           'use_namespace': 'False',
  210.                           'rviz_config': rviz_config_file}.items())
  211.  
  212.     bringup_cmd = IncludeLaunchDescription(
  213.         PythonLaunchDescriptionSource(
  214.             os.path.join(aroc_launch_dir, 'bringup_launch.py')),
  215.         launch_arguments={'namespace': namespace,
  216.                           'use_namespace': use_namespace,
  217.                           'slam': slam,
  218.                           'map': map_yaml_file,
  219.                           'use_sim_time': use_sim_time,
  220.                           'params_file': params_file,
  221.                           'autostart': autostart}.items())
  222.  
  223.     # Create the launch description and populate
  224.     ld = LaunchDescription()
  225.  
  226.     # Declare the launch options
  227.     ld.add_action(declare_namespace_cmd)
  228.     ld.add_action(declare_use_namespace_cmd)
  229.     ld.add_action(declare_slam_cmd)
  230.     ld.add_action(declare_map_yaml_cmd)
  231.     ld.add_action(declare_use_sim_time_cmd)
  232.     ld.add_action(declare_params_file_cmd)
  233.     ld.add_action(declare_autostart_cmd)
  234.  
  235.     ld.add_action(declare_rviz_config_file_cmd)
  236.     ld.add_action(declare_use_simulator_cmd)
  237.     ld.add_action(declare_use_robot_state_pub_cmd)
  238.     ld.add_action(start_joint_state_publisher_cmd)
  239.     ld.add_action(robot_localization_node)
  240.     ld.add_action(declare_use_rviz_cmd)
  241.     ld.add_action(declare_simulator_cmd)
  242.     ld.add_action(declare_world_cmd)
  243.  
  244.     # Add any conditioned actions
  245.     ld.add_action(start_gazebo_server_cmd)
  246.     ld.add_action(start_gazebo_client_cmd)
  247.  
  248.     # Add the actions to launch all of the navigation nodes
  249.     ld.add_action(start_robot_state_publisher_cmd)
  250.     ld.add_action(rviz_cmd)
  251.     ld.add_action(bringup_cmd)
  252.  
  253.     return ld
  254.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement