Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
example_assisted_teleop.py
1 #! /usr/bin/env python3
2 # Copyright 2022 Joshua Wallace
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from time import sleep
17 
18 from geometry_msgs.msg import PoseStamped
19 from nav2_simple_commander.robot_navigator import BasicNavigator
20 import rclpy
21 
22 """
23 Basic navigation demo to go to pose.
24 """
25 
26 
27 def main() -> None:
28  rclpy.init()
29 
30  navigator = BasicNavigator()
31 
32  # Set our demo's initial pose
33  initial_pose = PoseStamped()
34  initial_pose.header.frame_id = 'map'
35  initial_pose.header.stamp = navigator.get_clock().now().to_msg()
36  initial_pose.pose.position.x = 0.0
37  initial_pose.pose.position.y = 0.0
38  initial_pose.pose.orientation.z = 0.0
39  initial_pose.pose.orientation.w = 1.0
40  navigator.setInitialPose(initial_pose)
41 
42  # Wait for navigation to fully activate, since autostarting nav2
43  navigator.waitUntilNav2Active()
44 
45  teleop_task = navigator.assistedTeleop(time_allowance=20)
46  while not navigator.isTaskComplete(task=teleop_task):
47  # Publish twist commands to be filtered by the assisted teleop action
48  sleep(0.2)
49  pass
50 
51  navigator.lifecycleShutdown()
52  exit(0)
53 
54 
55 if __name__ == '__main__':
56  main()