Skip to content

Commit

Permalink
organized python directory and launch cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishaan-Datta committed Sep 10, 2024
1 parent d37c7ef commit 9cd7e5a
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 545 deletions.
File renamed without changes.
251 changes: 251 additions & 0 deletions Python Folder/src/python_workspace/launch/launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# document launch parameters

import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition

def generate_launch_description():
return LaunchDescription([
DeclareLaunchArgument(
'model_path',
default_value='/default/path/to/model.trt',
description='Path to the TensorRT engine file'
),
DeclareLaunchArgument(
'source_type',
default_value='static_image',
description='Type of source: static_image, video, zed'
),
DeclareLaunchArgument(
'static_image_path',
default_value='/path/to/static/image.jpg',
description='Path to the static image file'
),
DeclareLaunchArgument(
'video_path',
default_value='/path/to/video.mp4',
description='Path to the video file'
),
DeclareLaunchArgument(
'loop',
default_value='-1',
description='Number of times to loop the video (-1 for infinite, 0 for 1 loop, >0 for # of loops )'
),
DeclareLaunchArgument(
'frame_rate',
default_value='30',
description='Desired frame rate for publishing'
),
DeclareLaunchArgument(
'model_type',
default_value='maize',
description='The model architecture being used'
),
DeclareLaunchArgument(
'use_display_node',
default_value='True',
description='Whether to launch cv2 display screens'
),
DeclareLaunchArgument(
'lower_range',
default_value='[78, 158, 124]',
description='Lower HSV range for color filtering'
),
DeclareLaunchArgument(
'upper_range',
default_value='[60, 255, 255]',
description='The model architecture being used'
),
DeclareLaunchArgument(
'min_area',
default_value='100',
description='The minimum area for a contour to be considered'
),
DeclareLaunchArgument(
'min_confidence',
default_value='0.5',
description='The minimum confidence for a detection to be considered'
),
DeclareLaunchArgument(
'roi_list',
default_value='[0,0,100,100]',
description='The region of interest for the camera'
),
DeclareLaunchArgument(
'publish_rate',
default_value='10',
description='The rate at which to publish the bounding boxes'
),
# example to toggle nodes on/off
# DeclareLaunchArgument(
# 'use_display_node',
# default_value='true',
# description='Whether to launch the display node'
# ),
Node(
package='python_workspace',
executable='camera_node', # not sure if should match setup.py
name='camera_node',
output='screen', # idk what this does
parameters=[
{'source_type': LaunchConfiguration('source_type')},
{'static_image_path': LaunchConfiguration('static_image_path')},
{'video_path': LaunchConfiguration('video_path')},
{'loop': LaunchConfiguration('loop')},
{'frame_rate': LaunchConfiguration('frame_rate')},
{'model_type': LaunchConfiguration('model_type')},
]
),
Node(
package='python_workspace',
executable='jetson_node',
name='jetson_node',
output='screen',
parameters=[{'model_path': LaunchConfiguration('model_path')}],
),
Node(
package='python_workspace',
executable='extermination',
name='extermination_node',
output='screen',
# condition=IfCondition(LaunchConfiguration('use_display_node'))
parameters=[
{'use_display_node': LaunchConfiguration('use_display_node')},
{'lower_range': LaunchConfiguration('lower_range')},
{'upper_range': LaunchConfiguration('upper_range')},
{'min_area': LaunchConfiguration('min_area')},
{'min_confidence': LaunchConfiguration('min_confidence')},
{'roi_list': LaunchConfiguration('roi_list')},
{'publish_rate': LaunchConfiguration('publish_rate')},
]
),
])

# ## for composable:
# # example_launch.py
# from launch import LaunchDescription
# from launch_ros.actions import LifecycleNode
# from launch_ros.actions import ComposableNodeContainer
# from launch_ros.descriptions import ComposableNode

# def generate_launch_description():
# container = ComposableNodeContainer(
# name='my_container',
# namespace='',
# package='rclcpp_components',
# executable='component_container_mt',
# composable_node_descriptions=[
# ComposableNode(
# package='my_package',
# plugin='mypackage.ComposablePublisherNode',
# name='composable_publisher_node'
# ),
# ],
# output='screen',
# )

# lifecycle_manager = LifecycleNode(
# package='my_package',
# executable='lifecycle_node',
# name='lifecycle_manager_node',
# namespace='',
# output='screen',
# )

# return LaunchDescription([
# container,
# lifecycle_manager
# ])

# ## parameter handling:
# from launch import LaunchDescription
# from launch_ros.actions import LifecycleNode
# from launch_ros.actions import ComposableNodeContainer
# from launch_ros.descriptions import ComposableNode
# from launch.actions import LogInfo, EmitEvent
# from launch.events.lifecycle import ChangeState
# from lifecycle_msgs.msg import Transition

# def generate_launch_description():
# # Define parameters to pass to the composable node
# composable_params = {
# 'message': 'This is a custom message from launch!',
# 'publish_frequency': 1.0
# }

# container = ComposableNodeContainer(
# name='my_container',
# namespace='',
# package='rclcpp_components',
# executable='component_container_mt',
# composable_node_descriptions=[
# ComposableNode(
# package='my_package',
# plugin='mypackage.ComposablePublisherNode',
# name='composable_publisher_node',
# parameters=[composable_params]
# ),
# ComposableNode(
# package='my_package',
# plugin='mypackage.ComposablePublisherNode',
# name='additional_publisher_node',
# parameters=[{'message': 'This is the second node!', 'publish_frequency': 2.5}]
# )
# ],
# output='screen',
# )

# lifecycle_manager = LifecycleNode(
# package='my_package',
# executable='lifecycle_node',
# name='lifecycle_manager_node',
# namespace='',
# output='screen',
# parameters=[{'lifecycle_action': 'configure'}]
# )

# # Manually trigger lifecycle transitions after nodes are up
# configure_event = EmitEvent(
# event=ChangeState(
# lifecycle_node_matcher=launch.events.matches_action(lifecycle_manager),
# transition_id=Transition.TRANSITION_CONFIGURE
# )
# )

# activate_event = EmitEvent(
# event=ChangeState(
# lifecycle_node_matcher=launch.events.matches_action(lifecycle_manager),
# transition_id=Transition.TRANSITION_ACTIVATE
# )
# )

# deactivate_event = EmitEvent(
# event=ChangeState(
# lifecycle_node_matcher=launch.events.matches_action(lifecycle_manager),
# transition_id=Transition.TRANSITION_DEACTIVATE
# )
# )

# shutdown_event = EmitEvent(
# event=ChangeState(
# lifecycle_node_matcher=launch.events.matches_action(lifecycle_manager),
# transition_id=Transition.TRANSITION_SHUTDOWN
# )
# )

# return LaunchDescription([
# LogInfo(msg="Starting the container and lifecycle manager..."),
# container,
# lifecycle_manager,
# LogInfo(msg="Configuring the lifecycle node..."),
# configure_event,
# LogInfo(msg="Activating the lifecycle node..."),
# activate_event,
# LogInfo(msg="Deactivating the lifecycle node..."),
# deactivate_event,
# LogInfo(msg="Shutting down the lifecycle node..."),
# shutdown_event,
# ])
32 changes: 32 additions & 0 deletions Python Folder/src/python_workspace/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>node_test</name>
<version>0.0.1</version>
<description>ROS2 Pure Python MVP</description>
<maintainer email="[email protected]">Ishaan Datta</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_python</buildtool_depend>

<build_depend>builtin_interfaces</build_depend>
<build_depend>std_msgs</build_depend>

<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>cv_bridge</depend>
<exec_depend>numpy</depend>
<exec_depend>opencv-python</depend>
<exec_depend>pycuda</depend>
<exec_depend>tensorrt</depend>

<!-- <test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend> -->

<export>
<build_type>ament_python</build_type>
</export>
</package>
Loading

0 comments on commit 9cd7e5a

Please sign in to comment.