diff --git a/src/axidraw_controller/CMakeLists.txt b/src/axidraw_controller/CMakeLists.txt index bc9b649..aed3487 100644 --- a/src/axidraw_controller/CMakeLists.txt +++ b/src/axidraw_controller/CMakeLists.txt @@ -52,5 +52,6 @@ endif() # Install directories #install(DIRECTORY launch rviz urdf worlds DESTINATION share/${PROJECT_NAME}) +install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}) ament_package() diff --git a/src/axidraw_controller/launch/axidraw_controller.launch.py b/src/axidraw_controller/launch/axidraw_controller.launch.py new file mode 100644 index 0000000..233904e --- /dev/null +++ b/src/axidraw_controller/launch/axidraw_controller.launch.py @@ -0,0 +1,47 @@ +import os +from launch import LaunchDescription +from launch.actions import OpaqueFunction, IncludeLaunchDescription, DeclareLaunchArgument +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution +from launch_ros.substitutions import FindPackageShare +from launch_ros.actions import Node + +from ament_index_python import get_package_share_directory +from launch.launch_description_sources import load_python_launch_file_as_module +from launch import LaunchDescription +from launch.actions import RegisterEventHandler, EmitEvent +from launch.event_handlers import OnProcessExit +from launch.events import Shutdown + + +def launch_setup(context, *args, **kwargs): + serial_port = LaunchConfiguration('serial_port', default='/dev/ttyACM0') + log_level = LaunchConfiguration("log_level", default='warn') + + nodes = [ + Node( + package="axidraw_controller", + executable="axidraw_controller", + output="log", + arguments=["--ros-args", "--log-level", log_level], + parameters=[ + ], + ), + Node( + package="axidraw_controller", + executable="axidraw_serial.py", + output="log", + arguments=["--ros-args", "--log-level", log_level], + parameters=[ + {"serial_port": serial_port}, + ], + ), + ] + + return nodes + + +def generate_launch_description(): + return LaunchDescription([ + OpaqueFunction(function=launch_setup) + ]) diff --git a/src/axidraw_controller/src/py/axidraw_serial.py b/src/axidraw_controller/src/py/axidraw_serial.py index 4712aa7..129e367 100644 --- a/src/axidraw_controller/src/py/axidraw_serial.py +++ b/src/axidraw_controller/src/py/axidraw_serial.py @@ -48,8 +48,12 @@ class AxidrawSerial(Node): self.status["motion"] = "ready" return True - def __init__(self, port="/dev/ttyACM0"): + def __init__(self): super().__init__('axidraw_serial') + + self.declare_parameter('serial_port', '/dev/ttyACM0') + port = self.get_parameter('serial_port').get_parameter_value().string_value + self.status_srv = self.create_service(Status, 'axidraw_status', self.get_status) while not self.init_serial(port):