TurtleBot3 的 ROS2 运行框架梳理 1 - 底盘和键盘手动控制部分

1940阅读 0评论2020-09-01 iibull
分类:其他平台

点击(此处)折叠或打开

  1. 启动小车
  2. $ ros2 launch turtlebot3_bringup robot.launch.py

  3. 运行控制节点
  4. $ ros2 run turtlebot3_teleop teleop_keyboard

  5. 运行RVIZ
  6. $ ros2 launch turtlebot3_bringup rviz2.launch.py

点击(此处)折叠或打开  turtlebot3_bringup robot.launch.py 分析

  1. import os

  2. from ament_index_python.packages import get_package_share_directory
  3. from launch import LaunchDescription
  4. from launch.actions import DeclareLaunchArgument
  5. from launch.actions import IncludeLaunchDescription
  6. from launch.launch_description_sources import PythonLaunchDescriptionSource
  7. from launch.substitutions import LaunchConfiguration
  8. from launch.substitutions import ThisLaunchFileDir
  9. from launch_ros.actions import Node


  10. def generate_launch_description():
  11.     TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL']  //Burger: 获取SHELL环境变量的设定,即机器人类型

  12.     usb_port = LaunchConfiguration('usb_port', default='/dev/ttyACM0'

  13.     tb3_param_dir = LaunchConfiguration(
  14.         'tb3_param_dir',
  15.         default=os.path.join(
  16.             get_package_share_directory('turtlebot3_bringup'),
  17.             'param',
  18.             TURTLEBOT3_MODEL + '.yaml'))

  19.     lidar_pkg_dir = LaunchConfiguration(
  20.         'lidar_pkg_dir',
  21.         default=os.path.join(get_package_share_directory('hls_lfcd_lds_driver'), 'launch'))

  22.     use_sim_time = LaunchConfiguration('use_sim_time', default='false')

  23.     return LaunchDescription([
  24.         DeclareLaunchArgument(
  25.            'use_sim_time',
  26.            default_value=use_sim_time,
  27.            description='Use simulation (Gazebo) clock if true'),

  28.         DeclareLaunchArgument(
  29.             'usb_port',
  30.             default_value=usb_port,
  31.             description='Connected USB port with OpenCR'),

  32.         DeclareLaunchArgument(
  33.             'tb3_param_dir',
  34.             default_value=tb3_param_dir,
  35.             description='Full path to turtlebot3 parameter file to load'),

  36.         IncludeLaunchDescription(
  37.             PythonLaunchDescriptionSource(
  38.                 [ThisLaunchFileDir(), '/turtlebot3_state_publisher.launch.py']),
  39.             launch_arguments={'use_sim_time': use_sim_time}.items(),
  40.         ),

  41.         IncludeLaunchDescription(
  42.             PythonLaunchDescriptionSource([lidar_pkg_dir, '/hlds_laser.launch.py']),
  43.             launch_arguments={'port': '/dev/ttyUSB0', 'frame_id': 'base_scan'}.items(),
  44.         ),

  45.         Node(
  46.             package='turtlebot3_node',
  47.             node_executable='turtlebot3_ros',
  48.             parameters=[tb3_param_dir],
  49.             arguments=['-i', usb_port],
  50.             output='screen'),
  51.     ])

点击(此处)折叠或打开  turtlebot3_state_publisher.launch.py

  1. //主要时报 odom信息同步到底盘中心的base_linkde 坐标系上。
  2. import os

  3. from ament_index_python.packages import get_package_share_directory
  4. from launch import LaunchDescription
  5. from launch.actions import DeclareLaunchArgument
  6. from launch.substitutions import LaunchConfiguration
  7. from launch_ros.actions import Node


  8. def generate_launch_description():
  9.     TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL']

  10.     use_sim_time = LaunchConfiguration('use_sim_time', default='false')
  11.     urdf_file_name = 'turtlebot3_' + TURTLEBOT3_MODEL + '.urdf'

  12.     print("urdf_file_name : {}".format(urdf_file_name))

  13.     urdf = os.path.join(
  14.         get_package_share_directory('turtlebot3_description'),
  15.         'urdf',
  16.         urdf_file_name)

  17.     return LaunchDescription([
  18.         DeclareLaunchArgument(
  19.             'use_sim_time',
  20.             default_value='false',
  21.             description='Use simulation (Gazebo) clock if true'),

  22.         Node(
  23.             package='robot_state_publisher',
  24.             node_executable='robot_state_publisher',
  25.             node_name='robot_state_publisher',
  26.             output='screen',
  27.             parameters=[{'use_sim_time': use_sim_time}],
  28.             arguments=[urdf]),
  29.     ])
Teleop就是简单的手动遥控操作的内容了

上一篇:ROS2 摄像头校准
下一篇:TurtleBot3 的 ROS2 运行框架梳理 2 - SLAM