Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create new package nav2_composition #2546

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added nav2_composition/CHANGELOG.rst
Empty file.
50 changes: 50 additions & 0 deletions nav2_composition/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.5)
project(nav2_composition)

find_package(ament_cmake REQUIRED)
find_package(nav2_common REQUIRED)
find_package(rclcpp REQUIRED)
find_package(nav2_map_server REQUIRED)
find_package(nav2_amcl REQUIRED)
find_package(nav2_controller REQUIRED)
find_package(nav2_planner REQUIRED)
find_package(nav2_recoveries REQUIRED)
find_package(nav2_bt_navigator REQUIRED)
find_package(nav2_waypoint_follower REQUIRED)
find_package(nav2_lifecycle_manager REQUIRED)

nav2_package()

set(executable_name loc_and_nav)
add_executable(${executable_name}
src/main.cpp
)

set(dependencies
rclcpp
nav2_map_server
nav2_amcl
nav2_controller
nav2_planner
nav2_recoveries
nav2_bt_navigator
nav2_waypoint_follower
nav2_lifecycle_manager
)

ament_target_dependencies(${executable_name}
${dependencies}
)

install(TARGETS ${executable_name}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
38 changes: 38 additions & 0 deletions nav2_composition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# nav2_compostion

The `nav2_compistion` package is a composition-based bringup for Nav2, which is useful for embedded systems users that need to make optimizations due to harsh resource constraints.

### Pre-requisites:

- [Install ROS 2](https://index.ros.org/doc/ros2/Installation/Dashing/)

- Install Nav2

`sudo apt install ros-<ros2_distro>-navigation2`

- Install Nav2 Bringup

`sudo apt install ros-<ros2_distro>-nav2-bringup`

- Install your robot specific package (ex:[Turtlebot 3](http://emanual.robotis.com/docs/en/platform/turtlebot3/ros2/))

## Launch Nav2 in *Simulation* with Gazebo

refer to package `nav2_bringup`, there is only difference when you run `Terminal 3: Launch Nav2` , which just replaces `bringup_launch.py` with `compostion_bringup_launch.py`.

```bash
source /opt/ros/dashing/setup.bash
ros2 launch nav2_compostion compostion_bringup_launch.py use_sim_time:=True autostart:=True \
map:=<full/path/to/map.yaml>
```

### Advanced: single-terminal launch

A convenience file is provided to launch Gazebo, RVIZ and Nav2 using a single command:

```bash
ros2 launch nav2_compostion tb3_simulation_launch.py
```



91 changes: 91 additions & 0 deletions nav2_composition/launch/composition_bringup_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (c) 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from nav2_common.launch import RewrittenYaml


def generate_launch_description():
# Get the launch directory
bringup_dir = get_package_share_directory('nav2_bringup')

namespace = LaunchConfiguration('namespace')
map_yaml_file = LaunchConfiguration('map')
use_sim_time = LaunchConfiguration('use_sim_time')
autostart = LaunchConfiguration('autostart')
params_file = LaunchConfiguration('params_file')

# Map fully qualified names to relative ones so the node's namespace can be prepended.
# In case of the transforms (tf), currently, there doesn't seem to be a better alternative
# https://github.com/ros/geometry2/issues/32
# https://github.com/ros/robot_state_publisher/pull/30
# TODO(orduno) Substitute with `PushNodeRemapping`
# https://github.com/ros2/launch_ros/issues/56
remappings = [('/tf', 'tf'),
('/tf_static', 'tf_static')]

# Create our own temporary YAML files that include substitutions
param_substitutions = {
'yaml_filename': map_yaml_file,
'use_sim_time': use_sim_time,
'autostart': autostart}

configured_params = RewrittenYaml(
source_file=params_file,
root_key=namespace,
param_rewrites=param_substitutions,
convert_types=True)

return LaunchDescription([
# Set env var to print messages to stdout immediately
SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),

DeclareLaunchArgument(
'namespace', default_value='',
description='Top-level namespace'),

DeclareLaunchArgument(
'map',
default_value=os.path.join(bringup_dir, 'maps', 'turtlebot3_world.yaml'),
description='Full path to map yaml file to load'),

DeclareLaunchArgument(
'use_sim_time', default_value='false',
description='Use simulation (Gazebo) clock if true'),

DeclareLaunchArgument(
'autostart', default_value='true',
description='Automatically startup the nav2 stack'),

DeclareLaunchArgument(
'params_file',
default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
description='Full path to the ROS2 parameters file to use'),

Node(
package='nav2_composition',
executable='loc_and_nav',
output='screen',
parameters=[configured_params,
{'use_sim_time': use_sim_time},
{'autostart': autostart}],
remappings=remappings)
])
Loading