Create launch file for axidraw

This commit is contained in:
2023-01-09 17:34:41 +02:00
parent e8e076155a
commit d694289634
3 changed files with 53 additions and 1 deletions

View File

@@ -52,5 +52,6 @@ endif()
# Install directories # Install directories
#install(DIRECTORY launch rviz urdf worlds DESTINATION share/${PROJECT_NAME}) #install(DIRECTORY launch rviz urdf worlds DESTINATION share/${PROJECT_NAME})
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
ament_package() ament_package()

View File

@@ -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)
])

View File

@@ -48,8 +48,12 @@ class AxidrawSerial(Node):
self.status["motion"] = "ready" self.status["motion"] = "ready"
return True return True
def __init__(self, port="/dev/ttyACM0"): def __init__(self):
super().__init__('axidraw_serial') 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) self.status_srv = self.create_service(Status, 'axidraw_status', self.get_status)
while not self.init_serial(port): while not self.init_serial(port):