点击(此处)折叠或打开
-
启动小车
-
$ ros2 launch turtlebot3_bringup robot.launch.py
-
-
运行控制节点
-
$ ros2 run turtlebot3_teleop teleop_keyboard
-
-
运行RVIZ
- $ ros2 launch turtlebot3_bringup rviz2.launch.py
点击(此处)折叠或打开 turtlebot3_bringup robot.launch.py 分析
-
import os
-
-
from ament_index_python.packages import get_package_share_directory
-
from launch import LaunchDescription
-
from launch.actions import DeclareLaunchArgument
-
from launch.actions import IncludeLaunchDescription
-
from launch.launch_description_sources import PythonLaunchDescriptionSource
-
from launch.substitutions import LaunchConfiguration
-
from launch.substitutions import ThisLaunchFileDir
-
from launch_ros.actions import Node
-
-
-
def generate_launch_description():
-
TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL'] //Burger: 获取SHELL环境变量的设定,即机器人类型
-
-
usb_port = LaunchConfiguration('usb_port', default='/dev/ttyACM0')
-
-
tb3_param_dir = LaunchConfiguration(
-
'tb3_param_dir',
-
default=os.path.join(
-
get_package_share_directory('turtlebot3_bringup'),
-
'param',
-
TURTLEBOT3_MODEL + '.yaml'))
-
-
lidar_pkg_dir = LaunchConfiguration(
-
'lidar_pkg_dir',
-
default=os.path.join(get_package_share_directory('hls_lfcd_lds_driver'), 'launch'))
-
-
use_sim_time = LaunchConfiguration('use_sim_time', default='false')
-
-
return LaunchDescription([
-
DeclareLaunchArgument(
-
'use_sim_time',
-
default_value=use_sim_time,
-
description='Use simulation (Gazebo) clock if true'),
-
-
DeclareLaunchArgument(
-
'usb_port',
-
default_value=usb_port,
-
description='Connected USB port with OpenCR'),
-
-
DeclareLaunchArgument(
-
'tb3_param_dir',
-
default_value=tb3_param_dir,
-
description='Full path to turtlebot3 parameter file to load'),
-
-
IncludeLaunchDescription(
-
PythonLaunchDescriptionSource(
-
[ThisLaunchFileDir(), '/turtlebot3_state_publisher.launch.py']),
-
launch_arguments={'use_sim_time': use_sim_time}.items(),
-
),
-
-
IncludeLaunchDescription(
-
PythonLaunchDescriptionSource([lidar_pkg_dir, '/hlds_laser.launch.py']),
-
launch_arguments={'port': '/dev/ttyUSB0', 'frame_id': 'base_scan'}.items(),
-
),
-
-
Node(
-
package='turtlebot3_node',
-
node_executable='turtlebot3_ros',
-
parameters=[tb3_param_dir],
-
arguments=['-i', usb_port],
-
output='screen'),
- ])
点击(此处)折叠或打开 turtlebot3_state_publisher.launch.py
- //主要时报 odom信息同步到底盘中心的base_linkde 坐标系上。
-
import os
-
-
from ament_index_python.packages import get_package_share_directory
-
from launch import LaunchDescription
-
from launch.actions import DeclareLaunchArgument
-
from launch.substitutions import LaunchConfiguration
-
from launch_ros.actions import Node
-
-
-
def generate_launch_description():
-
TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL']
-
-
use_sim_time = LaunchConfiguration('use_sim_time', default='false')
-
urdf_file_name = 'turtlebot3_' + TURTLEBOT3_MODEL + '.urdf'
-
-
print("urdf_file_name : {}".format(urdf_file_name))
-
-
urdf = os.path.join(
-
get_package_share_directory('turtlebot3_description'),
-
'urdf',
-
urdf_file_name)
-
-
return LaunchDescription([
-
DeclareLaunchArgument(
-
'use_sim_time',
-
default_value='false',
-
description='Use simulation (Gazebo) clock if true'),
-
-
Node(
-
package='robot_state_publisher',
-
node_executable='robot_state_publisher',
-
node_name='robot_state_publisher',
-
output='screen',
-
parameters=[{'use_sim_time': use_sim_time}],
-
arguments=[urdf]),
- ])