116 lines
3.5 KiB
Python
116 lines
3.5 KiB
Python
from launch import LaunchDescription
|
|
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
|
|
from launch.conditions import IfCondition, UnlessCondition
|
|
from launch.substitutions import LaunchConfiguration
|
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
|
from launch_ros.actions import Node
|
|
from launch_ros.substitutions import FindPackageShare
|
|
import os
|
|
|
|
def generate_launch_description():
|
|
pkg_share = FindPackageShare("").find('toid_navigation')
|
|
params = os.path.join(pkg_share, 'params', 'toid_general_params.yaml')
|
|
map = os.path.join(pkg_share, 'maps', 'mapb2_5cm.yaml')
|
|
launch_dir = os.path.join(pkg_share, 'launch')
|
|
default_rviz_config_path = os.path.join(pkg_share, 'rviz', 'nav2.rviz')
|
|
bt_path = os.path.join(pkg_share, "behaviors", "navigate_to_pose_w_backtracking.xml")
|
|
lattice_path = os.path.join(pkg_share, "params", "output.json")
|
|
|
|
position = "0.756 0.225 0 0 0 0".split(' ')
|
|
#position = "0 0 0 0 0 0".split(' ')
|
|
|
|
visualize = LaunchConfiguration("visualize")
|
|
visualize_arg = DeclareLaunchArgument(
|
|
'visualize',
|
|
default_value='True',
|
|
description="Whether to launch rviz2"
|
|
)
|
|
|
|
toid_control = IncludeLaunchDescription(
|
|
PythonLaunchDescriptionSource(
|
|
os.path.join(launch_dir, 'mock_control_launch.py')
|
|
),
|
|
launch_arguments={
|
|
'visualize': 'False'
|
|
}.items()
|
|
)
|
|
|
|
set_position = Node(
|
|
package='tf2_ros',
|
|
executable='static_transform_publisher',
|
|
name='map_to_odom_broadcaster',
|
|
arguments=position + ['map', 'odom'],
|
|
condition=IfCondition(visualize)
|
|
)
|
|
|
|
map_server = Node(
|
|
package='nav2_map_server',
|
|
executable='map_server',
|
|
name='map_server',
|
|
output='screen',
|
|
parameters=[{'yaml_filename': map}]
|
|
)
|
|
|
|
planner_server = Node(
|
|
package='nav2_planner',
|
|
executable='planner_server',
|
|
name='planner_server',
|
|
output='screen',
|
|
parameters=[{'GridBased':{'lattice_filepath': lattice_path}}, params]
|
|
)
|
|
|
|
controller_server = Node(
|
|
package='nav2_controller',
|
|
executable='controller_server',
|
|
name='controller_server',
|
|
output='screen',
|
|
parameters=[params]
|
|
)
|
|
|
|
bt_navigator = Node(
|
|
package='nav2_bt_navigator',
|
|
executable='bt_navigator',
|
|
name='bt_navigator',
|
|
output='screen',
|
|
parameters=[{'default_nav_to_pose_bt_xml': bt_path}, params]
|
|
)
|
|
|
|
# default_nav_to_pose_bt_xml: "$(find-pkg-share toid_navigation)/behaviors/navigate_to_pose_w_backtracking.xml"
|
|
|
|
behavior_server = Node(
|
|
package='nav2_behaviors',
|
|
executable='behavior_server',
|
|
name='behavior_server',
|
|
output='screen',
|
|
parameters=[params]
|
|
)
|
|
|
|
lifecycle_manager_node = Node(
|
|
package='nav2_lifecycle_manager',
|
|
executable='lifecycle_manager',
|
|
name='lifecycle_manager',
|
|
output='screen',
|
|
parameters=[params]
|
|
)
|
|
|
|
rviz_node = Node(
|
|
package='rviz2',
|
|
executable='rviz2',
|
|
name='rviz2',
|
|
output='screen',
|
|
arguments=['-d', default_rviz_config_path],
|
|
condition=IfCondition(visualize)
|
|
)
|
|
|
|
return LaunchDescription([
|
|
visualize_arg,
|
|
set_position,
|
|
rviz_node,
|
|
map_server,
|
|
bt_navigator,
|
|
behavior_server,
|
|
planner_server,
|
|
controller_server,
|
|
lifecycle_manager_node,
|
|
toid_control
|
|
]) |