From 481087197f4fef41c5e521d6aefc50c0b5b437fb Mon Sep 17 00:00:00 2001
From: Tim Korjakow <you@example.com>
Date: Sun, 9 Jul 2023 16:36:43 +0800
Subject: [PATCH] Added config to slambox

---
 src/dcaiti_control/launch/launch_sim.py |  3 ++-
 src/dcaitirobot/config/slam.yml         |  3 +++
 src/dcaitirobot/launch/launch_slam.py   | 32 +++++++++++++++++++++++++
 src/dcaitirobot/setup.py                |  3 ++-
 4 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 src/dcaitirobot/config/slam.yml
 create mode 100644 src/dcaitirobot/launch/launch_slam.py

diff --git a/src/dcaiti_control/launch/launch_sim.py b/src/dcaiti_control/launch/launch_sim.py
index 30bbc90..670d343 100644
--- a/src/dcaiti_control/launch/launch_sim.py
+++ b/src/dcaiti_control/launch/launch_sim.py
@@ -25,6 +25,7 @@ def generate_launch_description():
     package_name='dcaiti_control' #<--- CHANGE ME
 
     use_ros2_control = LaunchConfiguration('use_ros2_control')
+    world_path='~/.gazebo/models'
 
     rsp = IncludeLaunchDescription(
                 PythonLaunchDescriptionSource([os.path.join(
@@ -36,7 +37,7 @@ def generate_launch_description():
     gazebo = IncludeLaunchDescription(
                 PythonLaunchDescriptionSource([os.path.join(
                     get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')]),
-                    launch_arguments={'params_file': gazebo_params_path}.items()
+                    launch_arguments={'params_file': gazebo_params_path, 'world': world_path }.items()
              )
 
     # Run the spawner node from the gazebo_ros package. The entity name doesn't really matter if you only have a single robot.
diff --git a/src/dcaitirobot/config/slam.yml b/src/dcaitirobot/config/slam.yml
new file mode 100644
index 0000000..d17dee9
--- /dev/null
+++ b/src/dcaitirobot/config/slam.yml
@@ -0,0 +1,3 @@
+slam_toolbox:
+  ros__parameters:
+    base_frame: base_link
\ No newline at end of file
diff --git a/src/dcaitirobot/launch/launch_slam.py b/src/dcaitirobot/launch/launch_slam.py
new file mode 100644
index 0000000..daf9f3d
--- /dev/null
+++ b/src/dcaitirobot/launch/launch_slam.py
@@ -0,0 +1,32 @@
+import os
+from pathlib import Path
+
+from launch import LaunchDescription
+from launch.actions import IncludeLaunchDescription
+from launch.launch_description_sources import PythonLaunchDescriptionSource
+from launch_ros.actions import Node
+from ament_index_python import get_package_share_directory
+
+
+def generate_launch_description():
+
+    slam_params = os.path.join(
+        get_package_share_directory('dcaitirobot'), # <-- Replace with your package name
+        'config',
+        'slam.yml'
+        )
+    
+    print(slam_params)
+
+    slam_toolbox = IncludeLaunchDescription(
+                PythonLaunchDescriptionSource([os.path.join(
+                    get_package_share_directory('slam_toolbox'),'launch','online_async_launch.py'
+                )]), 
+                launch_arguments={
+                    'use_sim_time': 'false', 
+                    'slam_params_file': slam_params}.items()
+    )
+
+    return LaunchDescription([
+        slam_toolbox
+    ])
\ No newline at end of file
diff --git a/src/dcaitirobot/setup.py b/src/dcaitirobot/setup.py
index 11908f7..c439b80 100644
--- a/src/dcaitirobot/setup.py
+++ b/src/dcaitirobot/setup.py
@@ -12,7 +12,8 @@ setup(
         ('share/ament_index/resource_index/packages',
             ['resource/' + package_name]),
         ('share/' + package_name, ['package.xml']),
-        (os.path.join('share', package_name), glob('launch/*.launch.py'))
+        (os.path.join('share', package_name), glob('launch/*.py')),
+        (os.path.join('share', package_name, 'config'), glob('config/*.yml')),
     ],
     install_requires=['setuptools'],
     zip_safe=True,