Skip to content

Commit

Permalink
Adapted format for ROS 2 Jazzy
Browse files Browse the repository at this point in the history
  • Loading branch information
KuraZuzu committed Nov 26, 2024
1 parent abace32 commit 2836ded
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 180 deletions.
35 changes: 19 additions & 16 deletions raspimouse_navigation/launch/pc_navigation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
Expand All @@ -32,51 +32,54 @@ def generate_launch_description():
declare_arg_use_sim_time = DeclareLaunchArgument(
'use_sim_tim',
default_value='True',
description='True: Simulate, False: Machine'
description='True: Simulate, False: Machine',
)

declare_arg_map = DeclareLaunchArgument(
'map',
description='The full path to the map yaml file.'
'map', description='The full path to the map yaml file.'
)

declare_arg_params_file = DeclareLaunchArgument(
'params_file',
default_value=os.path.join(
get_package_share_directory('raspimouse_navigation'),
'params',
'raspimouse.yaml'),
description='The full path to the param file.'
'raspimouse.yaml',
),
description='The full path to the param file.',
)

declare_arg_rviz2_config_path = DeclareLaunchArgument(
'rviz2_file', default_value=os.path.join(
'rviz2_file',
default_value=os.path.join(
get_package_share_directory('raspimouse_navigation'),
'rviz',
'nav2_view.rviz'),
description='The full path to the rviz file'
'nav2_view.rviz',
),
description='The full path to the rviz file',
)

nav2_launch_file_dir = os.path.join(
get_package_share_directory('nav2_bringup'),
'launch'
get_package_share_directory('nav2_bringup'), 'launch'
)

# Launch files and Nodes #
nav2_node = IncludeLaunchDescription(
PythonLaunchDescriptionSource([
nav2_launch_file_dir, '/bringup_launch.py']),
PythonLaunchDescriptionSource([nav2_launch_file_dir, '/bringup_launch.py']),
launch_arguments={
'map': map_yaml_file,
'params_file': params_file,
'use_sim_time': use_sim_time}.items(),
'use_sim_time': use_sim_time,
}.items(),
)

rviz2_node = Node(
name='rviz2',
package='rviz2', executable='rviz2', output='screen',
package='rviz2',
executable='rviz2',
output='screen',
arguments=['-d', rviz2_file],
parameters=[{'use_sim_time': use_sim_time}]
parameters=[{'use_sim_time': use_sim_time}],
)

ld = LaunchDescription()
Expand Down
107 changes: 59 additions & 48 deletions raspimouse_navigation/launch/robot_navigation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,82 +17,99 @@
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.actions import RegisterEventHandler, EmitEvent
from launch.actions import EmitEvent, RegisterEventHandler
from launch.conditions import LaunchConfigurationEquals
from launch.events import matches_action, Shutdown
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import LifecycleNode, Node
from launch_ros.events import lifecycle
from launch_ros.event_handlers import OnStateTransition
from launch_ros.events import lifecycle
from lifecycle_msgs.msg import Transition


def generate_launch_description():
# Launch arguments #
lidar_port = LaunchConfiguration(
'lidar_port', default='/dev/ttyUSB0')
lidar_port = LaunchConfiguration('lidar_port', default='/dev/ttyUSB0')

declare_arg_lidar = DeclareLaunchArgument(
'lidar',
default_value='none',
description='Set "none", "urg", "lds", or "rplidar".')
description='Set "none", "urg", "lds", or "rplidar".',
)

declare_arg_lidar_frame = DeclareLaunchArgument(
'lidar_frame',
default_value='laser',
description='Set lidar frame name.')
'lidar_frame', default_value='laser', description='Set lidar frame name.'
)

declare_arg_namespace = DeclareLaunchArgument(
'namespace',
default_value='',
description='Set namespace for tf tree.')
'namespace', default_value='', description='Set namespace for tf tree.'
)

# Launch files and Nodes #
lds_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('hls_lfcd_lds_driver'),
'launch'),
'/hlds_laser.launch.py']),
condition=LaunchConfigurationEquals('lidar', 'lds')
PythonLaunchDescriptionSource(
[
os.path.join(
get_package_share_directory('hls_lfcd_lds_driver'), 'launch'
),
'/hlds_laser.launch.py',
]
),
condition=LaunchConfigurationEquals('lidar', 'lds'),
)

urg_launch = Node(
name='urg_node_driver',
package='urg_node', executable='urg_node_driver', output='screen',
package='urg_node',
executable='urg_node_driver',
output='screen',
parameters=[{'serial_port': lidar_port}],
condition=LaunchConfigurationEquals('lidar', 'urg')
condition=LaunchConfigurationEquals('lidar', 'urg'),
)

rplidar_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('rplidar_ros'),
'launch'),
'/rplidar_a1_launch.py']),
launch_arguments={'serial_port': lidar_port,
'frame_id': LaunchConfiguration('lidar_frame')
}.items(),
condition=LaunchConfigurationEquals('lidar', 'rplidar')
PythonLaunchDescriptionSource(
[
os.path.join(get_package_share_directory('rplidar_ros'), 'launch'),
'/rplidar_a1_launch.py',
]
),
launch_arguments={
'serial_port': lidar_port,
'frame_id': LaunchConfiguration('lidar_frame'),
}.items(),
condition=LaunchConfigurationEquals('lidar', 'rplidar'),
)

description_params = {'lidar': LaunchConfiguration('lidar'),
'lidar_frame': LaunchConfiguration('lidar_frame'),
'namespace': LaunchConfiguration('namespace')
}.items()
description_params = {
'lidar': LaunchConfiguration('lidar'),
'lidar_frame': LaunchConfiguration('lidar_frame'),
'namespace': LaunchConfiguration('namespace'),
}.items()

# Launch files and Nodes #
robot_description_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('raspimouse_slam'), 'launch/'),
'description.launch.py']),
launch_arguments=description_params
PythonLaunchDescriptionSource(
[
os.path.join(get_package_share_directory('raspimouse_slam'), 'launch/'),
'description.launch.py',
]
),
launch_arguments=description_params,
)

mouse_node = LifecycleNode(
name='raspimouse', namespace='',
package='raspimouse', executable='raspimouse', output='screen',
parameters=[os.path.join(get_package_share_directory(
'raspimouse_slam'), 'config', 'mouse.yaml')]
name='raspimouse',
namespace='',
package='raspimouse',
executable='raspimouse',
output='screen',
parameters=[
os.path.join(
get_package_share_directory('raspimouse_slam'), 'config', 'mouse.yaml'
)
],
)

emit_configuring_event = EmitEvent(
Expand All @@ -109,27 +126,21 @@ def generate_launch_description():
)
)

emit_shutdown_event = EmitEvent(
event=Shutdown()
)
emit_shutdown_event = EmitEvent(event=Shutdown())

register_activating_transition = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=mouse_node,
goal_state='inactive',
entities=[
emit_activating_event
],
entities=[emit_activating_event],
)
)

register_shutting_down_transition = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=mouse_node,
goal_state='finalized',
entities=[
emit_shutdown_event
],
entities=[emit_shutdown_event],
)
)

Expand Down
51 changes: 31 additions & 20 deletions raspimouse_slam/launch/description.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,63 @@
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace
from launch.substitutions import Command
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace


def generate_launch_description():
# Declare arguments #
declare_arg_lidar = DeclareLaunchArgument(
'lidar',
default_value='none',
description='Set "none", "urg", "lds", or "rplidar".')
description='Set "none", "urg", "lds", or "rplidar".',
)

declare_arg_lidar_frame = DeclareLaunchArgument(
'lidar_frame',
default_value='laser',
description='Set lidar link name.')
'lidar_frame', default_value='laser', description='Set lidar link name.'
)

declare_arg_namespace = DeclareLaunchArgument(
'namespace',
default_value='',
description='Set namespace for tf tree.')
'namespace', default_value='', description='Set namespace for tf tree.'
)

xacro_file = os.path.join(
get_package_share_directory('raspimouse_description'),
'urdf',
'raspimouse.urdf.xacro')
'raspimouse.urdf.xacro',
)

params = {'robot_description': Command(
['xacro ', xacro_file,
' lidar:=', LaunchConfiguration('lidar'),
' lidar_frame:=', LaunchConfiguration('lidar_frame')]),
'frame_prefix': [LaunchConfiguration('namespace'), '/']}
params = {
'robot_description': Command(
[
'xacro ',
xacro_file,
' lidar:=',
LaunchConfiguration('lidar'),
' lidar_frame:=',
LaunchConfiguration('lidar_frame'),
]
),
'frame_prefix': [LaunchConfiguration('namespace'), '/'],
}

push_ns = PushRosNamespace([LaunchConfiguration('namespace')])

# Nodes #
robot_state_pub_node = Node(package='robot_state_publisher',
executable='robot_state_publisher',
output='both',
parameters=[params])
robot_state_pub_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='both',
parameters=[params],
)

joint_state_pub_node = Node(
package='joint_state_publisher',
executable='joint_state_publisher',
output='screen')
output='screen',
)

ld = LaunchDescription()

Expand Down
Loading

0 comments on commit 2836ded

Please sign in to comment.