Advertisement
Guest User

main_launch

a guest
May 14th, 2024
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 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. import os
  16.  
  17. from ament_index_python.packages import get_package_share_directory
  18.  
  19. from launch import LaunchDescription
  20. from launch.substitutions import LaunchConfiguration
  21. from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument
  22. from launch.launch_description_sources import PythonLaunchDescriptionSource
  23. from launch.conditions import IfCondition
  24. from nav2_common.launch import RewrittenYaml
  25. from launch.actions import ExecuteProcess
  26.  
  27.  
  28.  
  29.  
  30. def generate_launch_description():
  31. # Get the launch directory
  32. bringup_dir = get_package_share_directory('nav2_bringup')
  33. launch_dir = os.path.join(bringup_dir, 'launch')
  34. params_dir = os.path.join(bringup_dir, "params")
  35.  
  36. nav2_params = os.path.join(params_dir, "real_truck_nav2_params.yaml")
  37. configured_params = RewrittenYaml(
  38. source_file=nav2_params, root_key="", param_rewrites="", convert_types=True
  39. )
  40.  
  41. # Keep truck static by publishing to /cmd_vel in a loop
  42. keep_truck_static_cmd = ExecuteProcess(
  43. cmd=['bash', '-c', "while true; do ros2 topic pub /cmd_vel geometry_msgs/msg/Twist '{linear: {x: -0.8, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}' -1; sleep 0.1; done"],
  44. output='screen'
  45. )
  46.  
  47.  
  48. use_rviz = LaunchConfiguration('use_rviz')
  49. use_mapviz = LaunchConfiguration('use_mapviz')
  50.  
  51. declare_use_rviz_cmd = DeclareLaunchArgument(
  52. 'use_rviz',
  53. default_value='False',
  54. description='Whether to start RVIZ')
  55.  
  56. declare_use_mapviz_cmd = DeclareLaunchArgument(
  57. 'use_mapviz',
  58. default_value='False',
  59. description='Whether to start mapviz')
  60.  
  61. robot_localization_cmd = IncludeLaunchDescription(
  62. PythonLaunchDescriptionSource(
  63. os.path.join(launch_dir, 'real_bot_dual_ekf_navsat.launch.py'))
  64. )
  65.  
  66. navigation2_cmd = IncludeLaunchDescription(
  67. PythonLaunchDescriptionSource(
  68. os.path.join(bringup_dir, "launch", "real_navigation_launch.py")
  69. ),
  70. launch_arguments={
  71. "use_sim_time": "True",
  72. "params_file": configured_params,
  73. "autostart": "True",
  74. }.items(),
  75. )
  76.  
  77. rviz_cmd = IncludeLaunchDescription(
  78. PythonLaunchDescriptionSource(
  79. os.path.join(bringup_dir, "launch", 'rviz_launch.py')),
  80. condition=IfCondition(use_rviz)
  81. )
  82.  
  83. mapviz_cmd = IncludeLaunchDescription(
  84. PythonLaunchDescriptionSource(
  85. os.path.join(launch_dir, 'mapviz.launch.py')),
  86. #condition=IfCondition(use_mapviz)
  87. )
  88.  
  89. robot_cmd = IncludeLaunchDescription(
  90. PythonLaunchDescriptionSource(
  91. os.path.join(launch_dir, 'real_truck_environment_launch.py'))
  92. )
  93.  
  94.  
  95. # Create the launch description and populate
  96. ld = LaunchDescription()
  97.  
  98. # robot launch
  99. ld.add_action(robot_cmd)
  100.  
  101. # robot localization launch
  102. ld.add_action(robot_localization_cmd)
  103.  
  104. # navigation2 launch
  105. ld.add_action(navigation2_cmd)
  106.  
  107. # viz launch
  108. ld.add_action(declare_use_rviz_cmd)
  109. ld.add_action(rviz_cmd)
  110. #ld.add_action(declare_use_mapviz_cmd)
  111. #ld.add_action(mapviz_cmd)
  112.  
  113. #Uncomment when the terrain does not move the truck backwards (plane terrains don't need it)
  114. #ld.add_action(keep_truck_static_cmd) #FAKE BRAKE
  115.  
  116.  
  117. return ld
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement