class OroGen::ROS::Spec::Launcher

Launcher specification ROS allows to define launch files in order to handle the startup of multiple nodes or network of nodes

This class allows to store the information contained in a ROS launcher specification in an equivalent to Orocos' deployments

Attributes

launch_file[R]
String

Path to the launch file that is or has been loaded if

load_launch_file is set

loaded_launch_file[R]
Boolean

Flag if the launch file content should be loaded

to extract node definitions

name[R]
String

Name of the launcher

project[R]
Package

Project this launcher is part of

Public Class Methods

new(project, name = nil) click to toggle source

Initialize the project

Automatically tries to resolve the corresponding launch files in the file systems @throw [ArgumentError] Raises if a corresponding launch file could not be found

# File lib/orogen/ros/spec/launcher.rb, line 101
def initialize(project, name = nil)
    @project = project
    @name = name
    @nodes = []
    @task_activities = []
    @load_launch_file = nil

    # search for launch file where project.name == ros package name
    @launch_file = project.ros_loader.roslaunch_find(project.name, name)
end
parse(filename) click to toggle source

Parses a given launch file and extracts the launch information @return [Set<Spec::XML::NodeDescription>] Extract all nodes from a launch file

# File lib/orogen/ros/spec/launcher.rb, line 160
def self.parse(filename)
    if not File.exists?(filename)
        raise ArgumentError, "#{self}: could not find file '#{filename}'"
    end

    nodes = []
    File.open(filename) do |f|
        doc = REXML::Document.new(f)
        doc.each_element('//node') do |n|
            nodes << XML::NodeDescription.from_xml_node(n)
        end
    end
    nodes
end

Public Instance Methods

load_launch_file() click to toggle source

Loads the launch file if not already loaded

# File lib/orogen/ros/spec/launcher.rb, line 113
def load_launch_file
    if !loaded_launch_file?
        @loaded_launch_file = true
        parse(launch_file)
    end
end
loaded_launch_file?() click to toggle source

Test whether the launch file has been automatically loaded

# File lib/orogen/ros/spec/launcher.rb, line 121
def loaded_launch_file?
    !!@loaded_launch_file
end
node(name, klass) click to toggle source

Declares a node in a ROS launcher

This is equivalently to declaring a task in a RTT deployment

@return [OroGen::Spec::TaskDeployment] A task deployment

# File lib/orogen/ros/spec/launcher.rb, line 146
def node(name, klass)
    task_deployment = task(name, klass)

    # Update with ros information
    node = task_deployment.task_model
    node.ros_name = node.name.split("::")[1]
    node.ros_package = node.project.name
    @nodes << node

    task_deployment
end
parse(path) click to toggle source

Parse the launch file @return [String] Absolute path to the lauch file that has been

loaded
# File lib/orogen/ros/spec/launcher.rb, line 129
def parse(path)
    if File.exists?(path)
        @node_descriptors = Launcher.parse(path)
        @node_descriptors.each do |d|
            node(d.name, "#{d.package}::#{d.type}")
        end
    else
        raise ArgumentError, "Launcher: could not find launch file: '#{path}' in #{Dir.pwd}"
    end
    File.absolute_path(path)
end
to_s() click to toggle source

String representaiton of this launcher

# File lib/orogen/ros/spec/launcher.rb, line 176
def to_s
    "Launcher: #{name}, launch_file: #{@launch_file}, loaded: #{loaded_launch_file?}"
end