-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recoveries to simple commander (#2792)
* fix Typo * add recoveries * add docs * added demo using backup and spin * rename isNavigationComplete to isTaskComplete * rename cancelNav to cancelTask * add prints * fix premature exit * rename NavResult to TaskResult * fix readme order * fix import order * renaming * renaming
- Loading branch information
1 parent
2f5d1e6
commit 38ca8d5
Showing
12 changed files
with
295 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (c) 2021 Samsung Research America | ||
# | ||
# 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 ExecuteProcess, IncludeLaunchDescription | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
from launch_ros.actions import Node | ||
|
||
|
||
def generate_launch_description(): | ||
warehouse_dir = get_package_share_directory('aws_robomaker_small_warehouse_world') | ||
nav2_bringup_dir = get_package_share_directory('nav2_bringup') | ||
python_commander_dir = get_package_share_directory('nav2_simple_commander') | ||
|
||
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml') | ||
world = os.path.join(python_commander_dir, 'warehouse.world') | ||
|
||
# start the simulation | ||
start_gazebo_server_cmd = ExecuteProcess( | ||
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world], | ||
cwd=[warehouse_dir], output='screen') | ||
|
||
start_gazebo_client_cmd = ExecuteProcess( | ||
cmd=['gzclient'], | ||
cwd=[warehouse_dir], output='screen') | ||
|
||
urdf = os.path.join(nav2_bringup_dir, 'urdf', 'turtlebot3_waffle.urdf') | ||
start_robot_state_publisher_cmd = Node( | ||
package='robot_state_publisher', | ||
executable='robot_state_publisher', | ||
name='robot_state_publisher', | ||
output='screen', | ||
arguments=[urdf]) | ||
|
||
# start the visualization | ||
rviz_cmd = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')), | ||
launch_arguments={'namespace': '', | ||
'use_namespace': 'False'}.items()) | ||
|
||
# start navigation | ||
bringup_cmd = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
os.path.join(nav2_bringup_dir, 'launch', 'bringup_launch.py')), | ||
launch_arguments={'map': map_yaml_file}.items()) | ||
|
||
# start the demo autonomy task | ||
demo_cmd = Node( | ||
package='nav2_simple_commander', | ||
executable='demo_recoveries', | ||
emulate_tty=True, | ||
output='screen') | ||
|
||
ld = LaunchDescription() | ||
ld.add_action(start_gazebo_server_cmd) | ||
ld.add_action(start_gazebo_client_cmd) | ||
ld.add_action(start_robot_state_publisher_cmd) | ||
ld.add_action(rviz_cmd) | ||
ld.add_action(bringup_cmd) | ||
ld.add_action(demo_cmd) | ||
return ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
nav2_simple_commander/nav2_simple_commander/demo_recoveries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#! /usr/bin/env python3 | ||
# Copyright 2021 Samsung Research America | ||
# | ||
# 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. | ||
|
||
from geometry_msgs.msg import PoseStamped | ||
from nav2_simple_commander.robot_navigator import BasicNavigator, TaskResult | ||
import rclpy | ||
from rclpy.duration import Duration | ||
|
||
|
||
""" | ||
Basic recoveries demo. In this demonstration, the robot navigates | ||
to a dead-end where recoveries such as backup and spin are used | ||
to get out of it. | ||
""" | ||
|
||
|
||
def main(): | ||
rclpy.init() | ||
|
||
navigator = BasicNavigator() | ||
|
||
# Set our demo's initial pose | ||
initial_pose = PoseStamped() | ||
initial_pose.header.frame_id = 'map' | ||
initial_pose.header.stamp = navigator.get_clock().now().to_msg() | ||
initial_pose.pose.position.x = 3.45 | ||
initial_pose.pose.position.y = 2.15 | ||
initial_pose.pose.orientation.z = 1.0 | ||
initial_pose.pose.orientation.w = 0.0 | ||
navigator.setInitialPose(initial_pose) | ||
|
||
# Wait for navigation to fully activate | ||
navigator.waitUntilNav2Active() | ||
|
||
goal_pose = PoseStamped() | ||
goal_pose.header.frame_id = 'map' | ||
goal_pose.header.stamp = navigator.get_clock().now().to_msg() | ||
goal_pose.pose.position.x = 6.13 | ||
goal_pose.pose.position.y = 1.90 | ||
goal_pose.pose.orientation.w = 1.0 | ||
|
||
navigator.goToPose(goal_pose) | ||
|
||
i = 0 | ||
while not navigator.isTaskComplete(): | ||
i += 1 | ||
feedback = navigator.getFeedback() | ||
if feedback and i % 5 == 0: | ||
print( | ||
f'Estimated time of arrival to destination is: \ | ||
{Duration.from_msg(feedback.estimated_time_remaining).nanoseconds / 1e9}' | ||
) | ||
|
||
# Robot hit a dead end, back it up | ||
print('Robot hit a dead end, backing up...') | ||
navigator.backup(backup_dist=0.5, backup_speed=0.1) | ||
|
||
i = 0 | ||
while not navigator.isTaskComplete(): | ||
i += 1 | ||
feedback = navigator.getFeedback() | ||
if feedback and i % 5 == 0: | ||
print(f'Distance traveled: {feedback.distance_traveled}') | ||
|
||
# Turn it around | ||
print('Spinning robot around...') | ||
navigator.spin(spin_dist=3.14) | ||
|
||
i = 0 | ||
while not navigator.isTaskComplete(): | ||
i += 1 | ||
feedback = navigator.getFeedback() | ||
if feedback and i % 5 == 0: | ||
print(f'Spin angle traveled: {feedback.angular_distance_traveled}') | ||
|
||
result = navigator.getResult() | ||
if result == TaskResult.SUCCEEDED: | ||
print('Dead end confirmed! Returning to start...') | ||
elif result == TaskResult.CANCELED: | ||
print('Recovery was canceled. Returning to start...') | ||
elif result == TaskResult.FAILED: | ||
print('Recovering from dead end failed! Returning to start...') | ||
|
||
initial_pose.header.stamp = navigator.get_clock().now().to_msg() | ||
navigator.goToPose(initial_pose) | ||
while not navigator.isTaskComplete(): | ||
pass | ||
|
||
exit(0) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.