forked from zbw/yiliao2026
add&fix:修改了文件名称以及添加了slam定位的卵巢文件
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument, TimerAction
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
from launch_ros.parameter_descriptions import ParameterValue
|
||||
from launch.substitutions import Command
|
||||
from launch.actions import ExecuteProcess
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
ld = LaunchDescription()
|
||||
|
||||
# =============================1.定位到包的地址=============================================================
|
||||
gc_navigation_fish_dir = get_package_share_directory(
|
||||
'gc_navigation2_slamtoolbox')
|
||||
nav2_bringup_dir = get_package_share_directory('nav2_bringup')
|
||||
origincar_urdf_dir = get_package_share_directory(
|
||||
'origincar_description')
|
||||
|
||||
# =============================2.声明参数,获取配置文件路径===================================================
|
||||
# use_sim_time 这里要设置成true,因为gazebo是仿真环境,其时间是通过/clock话题获取,而不是系统时间
|
||||
use_sim_time = LaunchConfiguration('use_sim_time', default='true')
|
||||
map_yaml_path = LaunchConfiguration('map', default=os.path.join(
|
||||
gc_navigation_fish_dir, 'maps', 'my_map.yaml'))
|
||||
nav2_param_path = LaunchConfiguration('params_file', default=os.path.join(
|
||||
gc_navigation_fish_dir, 'params', 'gc_navigation_amcl.yaml'))
|
||||
|
||||
# =============================3.声明启动launch文件,传入:地图路径、是否使用仿真时间以及nav2参数文件==============
|
||||
nav2_bringup_launch = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
[nav2_bringup_dir, '/launch', '/bringup_launch.py']),
|
||||
launch_arguments={
|
||||
'map': map_yaml_path,
|
||||
'use_sim_time': use_sim_time,
|
||||
'params_file': nav2_param_path}.items(),
|
||||
)
|
||||
|
||||
|
||||
# =============================4.Gazebo仿真设置==========================================================
|
||||
robot_name_in_model = 'mycar'
|
||||
default_model_path = os.path.join(
|
||||
origincar_urdf_dir, "urdf", "origincar.urdf")
|
||||
model = DeclareLaunchArgument(
|
||||
name="model", default_value=default_model_path)
|
||||
|
||||
gazebo_world_path = os.path.join(origincar_urdf_dir, 'world/test.world')
|
||||
start_gazebo_cmd = ExecuteProcess(
|
||||
cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so',
|
||||
'-s', 'libgazebo_ros_factory.so', gazebo_world_path],
|
||||
output='screen')
|
||||
|
||||
spawn_entity_cmd = Node(
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
arguments=['-entity', robot_name_in_model,
|
||||
'-file', default_model_path],
|
||||
output='screen'
|
||||
)
|
||||
|
||||
robot_description = ParameterValue(Command(["xacro ", LaunchConfiguration("model")]),
|
||||
value_type=str)
|
||||
|
||||
robot_state_publisher = Node(
|
||||
package="robot_state_publisher",
|
||||
executable="robot_state_publisher",
|
||||
parameters=[{"robot_description": robot_description,
|
||||
'use_sim_time': True, 'publish_frequency': 30.0}]
|
||||
)
|
||||
|
||||
# 2.启动 joint_state_publisher 节点发布非固定关节状态
|
||||
joint_state_publisher = Node(
|
||||
package="joint_state_publisher",
|
||||
executable="joint_state_publisher"
|
||||
)
|
||||
|
||||
ld.add_action(model)
|
||||
ld.add_action(nav2_bringup_launch)
|
||||
ld.add_action(start_gazebo_cmd)
|
||||
ld.add_action(spawn_entity_cmd)
|
||||
ld.add_action(robot_state_publisher)
|
||||
# ld.add_action(joint_state_publisher)
|
||||
|
||||
return ld
|
||||
Reference in New Issue
Block a user