Skip to content

Commit b4ece38

Browse files
committed
feat: add launch files
Adde launch files for slam, nav2, localization and organized existing launch files
1 parent 596242d commit b4ece38

15 files changed

+442
-143
lines changed

drl_agent/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ install(
3030
DIRECTORY
3131
launch
3232
scripts
33+
config
3334
DESTINATION
3435
share/${PROJECT_NAME}/
3536
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from launch import LaunchDescription
2+
from launch.actions import DeclareLaunchArgument, GroupAction, IncludeLaunchDescription
3+
from launch.launch_description_sources import PythonLaunchDescriptionSource
4+
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
5+
6+
from launch_ros.actions import PushRosNamespace
7+
from ament_index_python.packages import get_package_share_directory
8+
9+
10+
ARGUMENTS = [
11+
DeclareLaunchArgument('use_sim_time', default_value='true',
12+
choices=['true', 'false'],
13+
description='Use sim time'),
14+
DeclareLaunchArgument('namespace', default_value='',
15+
description='Robot namespace')
16+
]
17+
18+
19+
def generate_launch_description():
20+
drl_agent_pkg = get_package_share_directory('drl_agent')
21+
pkg_nav2_bringup = get_package_share_directory('nav2_bringup')
22+
23+
localization_params_arg = DeclareLaunchArgument(
24+
'params',
25+
default_value=PathJoinSubstitution(
26+
[drl_agent_pkg, 'config', 'localization.yaml']),
27+
description='Localization parameters')
28+
29+
map_arg = DeclareLaunchArgument(
30+
'map',
31+
default_value=PathJoinSubstitution(
32+
[drl_agent_pkg, 'maps', 'warehouse.yaml']), # TODO: add default map here
33+
description='Full path to map yaml file to load')
34+
35+
namespace = LaunchConfiguration('namespace')
36+
use_sim_time = LaunchConfiguration('use_sim_time')
37+
38+
localization = GroupAction([
39+
PushRosNamespace(namespace),
40+
41+
IncludeLaunchDescription(
42+
PythonLaunchDescriptionSource(
43+
PathJoinSubstitution(
44+
[pkg_nav2_bringup, 'launch', 'localization_launch.py'])),
45+
launch_arguments={'namespace': namespace,
46+
'map': LaunchConfiguration('map'),
47+
'use_sim_time': use_sim_time,
48+
'params_file': LaunchConfiguration('params')}.items()),
49+
])
50+
51+
ld = LaunchDescription(ARGUMENTS)
52+
ld.add_action(localization_params_arg)
53+
ld.add_action(map_arg)
54+
ld.add_action(localization)
55+
return ld

drl_agent/launch/nav2.launch.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/python3
2+
3+
from launch import LaunchDescription
4+
from launch.actions import (
5+
DeclareLaunchArgument,
6+
GroupAction,
7+
IncludeLaunchDescription,
8+
OpaqueFunction
9+
)
10+
from launch.launch_description_sources import PythonLaunchDescriptionSource
11+
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
12+
from launch_ros.actions import PushRosNamespace, SetRemap
13+
from ament_index_python.packages import get_package_share_directory
14+
15+
16+
ARGUMENTS = [
17+
DeclareLaunchArgument('use_sim_time', default_value='true',
18+
choices=['true', 'false'],
19+
description='Use sim time'),
20+
DeclareLaunchArgument('params_file',
21+
default_value=PathJoinSubstitution([
22+
get_package_share_directory('drl_agent'),
23+
'config',
24+
'nav2.yaml'
25+
]),
26+
description='Nav2 parameters'),
27+
DeclareLaunchArgument('namespace', default_value='',
28+
description='Robot namespace')
29+
]
30+
31+
32+
def launch_setup(context, *args, **kwargs):
33+
pkg_nav2_bringup = get_package_share_directory('nav2_bringup')
34+
35+
nav2_params = LaunchConfiguration('params_file')
36+
namespace = LaunchConfiguration('namespace')
37+
use_sim_time = LaunchConfiguration('use_sim_time')
38+
39+
namespace_str = namespace.perform(context)
40+
if (namespace_str and not namespace_str.startswith('/')):
41+
namespace_str = '/' + namespace_str
42+
43+
launch_nav2 = PathJoinSubstitution(
44+
[pkg_nav2_bringup, 'launch', 'navigation_launch.py'])
45+
46+
nav2 = GroupAction([
47+
PushRosNamespace(namespace),
48+
SetRemap(namespace_str + '/global_costmap/scan', namespace_str + '/scan'),
49+
SetRemap(namespace_str + '/local_costmap/scan', namespace_str + '/scan'),
50+
51+
IncludeLaunchDescription(
52+
PythonLaunchDescriptionSource(launch_nav2),
53+
launch_arguments=[
54+
('use_sim_time', use_sim_time),
55+
('params_file', nav2_params.perform(context)),
56+
('use_composition', 'False'),
57+
('namespace', namespace_str)
58+
]
59+
),
60+
])
61+
62+
return [nav2]
63+
64+
65+
def generate_launch_description():
66+
ld = LaunchDescription(ARGUMENTS)
67+
ld.add_action(OpaqueFunction(function=launch_setup))
68+
return ld

drl_agent/launch/slam.launch.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/python3
2+
3+
from launch import LaunchDescription
4+
from launch.actions import DeclareLaunchArgument, GroupAction
5+
from launch.conditions import IfCondition, UnlessCondition
6+
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
7+
from launch_ros.actions import Node, PushRosNamespace
8+
from nav2_common.launch import RewrittenYaml
9+
from ament_index_python.packages import get_package_share_directory
10+
11+
12+
ARGUMENTS = [
13+
DeclareLaunchArgument('use_sim_time', default_value='true',
14+
choices=['true', 'false'],
15+
description='Use sim time'),
16+
DeclareLaunchArgument('sync', default_value='false',
17+
choices=['true', 'false'],
18+
description='Use synchronous SLAM'),
19+
DeclareLaunchArgument('namespace', default_value='',
20+
description='Robot namespace')
21+
]
22+
23+
24+
def generate_launch_description():
25+
drl_agent_pkg = get_package_share_directory('drl_agent')
26+
27+
namespace = LaunchConfiguration('namespace')
28+
sync = LaunchConfiguration('sync')
29+
30+
slam_params_arg = DeclareLaunchArgument(
31+
'params',
32+
default_value=PathJoinSubstitution(
33+
[drl_agent_pkg, 'config', 'slam.yaml']),
34+
description='Robot namespace')
35+
36+
slam_params = RewrittenYaml(
37+
source_file=LaunchConfiguration('params'),
38+
root_key=namespace,
39+
param_rewrites={},
40+
convert_types=True
41+
)
42+
43+
remappings = [
44+
('/tf', 'tf'),
45+
('/tf_static', 'tf_static'),
46+
('/scan', 'scan'),
47+
('/map', 'map'),
48+
('/map_metadata', 'map_metadata'),
49+
]
50+
51+
slam = GroupAction([
52+
PushRosNamespace(namespace),
53+
54+
Node(package='slam_toolbox',
55+
executable='sync_slam_toolbox_node',
56+
name='slam_toolbox',
57+
output='screen',
58+
parameters=[
59+
slam_params,
60+
{'use_sim_time': LaunchConfiguration('use_sim_time')}
61+
],
62+
remappings=remappings,
63+
condition=IfCondition(sync)),
64+
65+
Node(package='slam_toolbox',
66+
executable='async_slam_toolbox_node',
67+
name='slam_toolbox',
68+
output='screen',
69+
parameters=[
70+
slam_params,
71+
{'use_sim_time': LaunchConfiguration('use_sim_time')}
72+
],
73+
remappings=remappings,
74+
condition=UnlessCondition(sync))
75+
])
76+
77+
ld = LaunchDescription(ARGUMENTS)
78+
ld.add_action(slam_params_arg)
79+
ld.add_action(slam)
80+
return ld

drl_agent/launch/test_drl_agent.launch.py

Whitespace-only changes.

drl_agent/launch/train_drl_agent.launch.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

drl_agent/scripts/environment/environment_interface.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import rclpy
44
from rclpy.node import Node
55
import numpy as np
6-
from drl_agent_interfaces.srv import Step, Reset, Seed, GetDimensions, SampleActionSpace
6+
from drl_agent_interfaces.srv import (
7+
Step,
8+
Reset,
9+
Seed,
10+
GetDimensions,
11+
SampleActionSpace
12+
)
713

814

915
class EnvInterface(Node):
@@ -80,7 +86,7 @@ def set_env_seed(self, seed):
8086
rclpy.spin_until_future_complete(self, future)
8187
except Exception as e:
8288
self.get_logger().error(f"Service call /seed failed: {e}")
83-
self.get_logger().info(f"\nEnvironment seed set to: {seed}, Success: {future.result().success}\n")
89+
self.get_logger().info(f"Environment seed set to: {seed}, Success: {future.result().success}\n")
8490

8591

8692
def main(args=None):

drl_agent/scripts/policies/test_td7_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def __init__(self, args, env):
3333
self.rl_agent = Agent(state_dim=state_dim, action_dim=action_dim, max_action=max_action)
3434
try:
3535
self.rl_agent.load(self.pytorch_models_dir, self.args.file_name)
36-
self.get_logger().info("\n > Model parameters loaded successfuly\n")
36+
self.get_logger().info(f'{"Model parameters loaded successfuly":-^50}')
3737
except Exception as e:
38-
self.get_logger().error("\n > Could not load network parameters :(\n")
38+
self.get_logger().error(f'{"Could not load network parameters :(":-^50}')
3939
sys.exit(-1)
4040

4141
# Set seed for the test environment

drl_agent_description/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ install(
3030
urdf
3131
worlds
3232
rviz
33+
config
3334
DESTINATION
3435
share/${PROJECT_NAME}/
3536
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
gazebo:
2+
ros__parameters:
3+
publish_rate: 62.0

0 commit comments

Comments
 (0)