navigation.launch.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import pathlib
  9. from ament_index_python.packages import get_package_share_directory
  10. from launch import LaunchDescription
  11. from launch.actions import IncludeLaunchDescription
  12. from launch.launch_description_sources import PythonLaunchDescriptionSource
  13. from launch_ros.actions import Node
  14. from nav2_common.launch import RewrittenYaml
  15. def generate_launch_description():
  16. package_dir = get_package_share_directory("o3de_kraken_nav")
  17. slam_toolbox_dir = get_package_share_directory('slam_toolbox')
  18. nav2_dir = get_package_share_directory("nav2_bringup")
  19. nav2_params_file = str(pathlib.Path(package_dir).joinpath('launch',
  20. 'config',
  21. 'navigation_params.yaml'))
  22. bt_xml_file = str(pathlib.Path(package_dir).joinpath('launch', 'config', 'bt.xml'))
  23. param_substitutions = {
  24. 'default_nav_to_pose_bt_xml': bt_xml_file}
  25. configured_nav2_params = RewrittenYaml(
  26. source_file=nav2_params_file,
  27. root_key='',
  28. param_rewrites=param_substitutions,
  29. convert_types=True)
  30. online_async_file = pathlib.Path(slam_toolbox_dir).joinpath('launch',
  31. 'online_async_launch.py')
  32. slam_params_file = pathlib.Path(package_dir).joinpath('launch',
  33. 'config',
  34. 'slam_params.yaml')
  35. slam = IncludeLaunchDescription(
  36. PythonLaunchDescriptionSource([str(online_async_file)]),
  37. launch_arguments={
  38. 'slam_params_file': str(slam_params_file),
  39. }.items()
  40. )
  41. navigation_launch = pathlib.Path(nav2_dir).joinpath('launch', 'navigation_launch.py')
  42. navigation = IncludeLaunchDescription(
  43. PythonLaunchDescriptionSource([str(navigation_launch)]),
  44. launch_arguments={
  45. 'params_file': configured_nav2_params,
  46. }.items()
  47. )
  48. pointcloud_to_laserscan = Node(
  49. package='pointcloud_to_laserscan',
  50. executable='pointcloud_to_laserscan_node',
  51. name='pc_to_laserscan',
  52. parameters=[{
  53. 'min_height': 0.1,
  54. 'max_height': 5.0,
  55. 'range_min': 0.2,
  56. 'range_max': 60.0
  57. }],
  58. remappings=[
  59. ('/cloud_in', '/pc'),
  60. ]
  61. )
  62. twist_to_ackermann = Node(
  63. package='o3de_kraken_nav',
  64. executable='twist_to_ackermann',
  65. name='twist_to_ackermann',
  66. parameters=[{
  67. 'wheelbase': 2.2,
  68. 'timeout_control_interval': 0.1,
  69. 'control_timeout': 0.2,
  70. 'publish_zeros_on_timeout': True
  71. }]
  72. )
  73. rviz = Node(
  74. package='rviz2',
  75. executable='rviz2',
  76. name='slam',
  77. arguments=[
  78. '-d', str(pathlib.Path(package_dir).joinpath('launch',
  79. 'config',
  80. 'config.rviz')),
  81. ]
  82. )
  83. ld = LaunchDescription()
  84. ld.add_action(pointcloud_to_laserscan)
  85. ld.add_action(twist_to_ackermann)
  86. ld.add_action(slam)
  87. ld.add_action(navigation)
  88. ld.add_action(rviz)
  89. return ld