Class: OroGen::ROS::Spec::Launcher

Inherits:
Spec::Deployment show all
Extended by:
Logger::Hierarchy
Defined in:
lib/orogen/ros/spec/launcher.rb

Overview

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

Constant Summary

Constants inherited from Spec::Deployment

Spec::Deployment::KNOWN_LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Spec::Deployment

#connections, #peers, #task_activities

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spec::Deployment

#activity_ordered_tasks, #add_default_logger, #add_peers, #connect, #corba_enabled?, #disable_corba, #disable_transport, #do_not_install, #each_task, #enable_corba, #enable_transport, #find_task_by_name, #get_lock_timeout_no_period, #get_lock_timeout_period_factor, #initialize_copy, #inspect, #install?, #linux?, #load_type, #lock_timeout_no_period, #lock_timeout_period_factor, #pretty_print, #rtt_transports, #set_master_slave_activity, #task, #transports, #used_typekits, #uses_qt?, #xenomai?

Constructor Details

#initialize(project, name = nil) ⇒ Launcher

Initialize the project

Automatically tries to resolve the corresponding launch files in the file systems



101
102
103
104
105
106
107
108
109
110
# 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

Instance Attribute Details

#launch_fileObject (readonly)

String

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

#load_launch_file is set



94
95
96
# File 'lib/orogen/ros/spec/launcher.rb', line 94

def launch_file
  @launch_file
end

#loaded_launch_fileObject (readonly)

Boolean

Flag if the launch file content should be loaded

to extract node definitions



90
91
92
# File 'lib/orogen/ros/spec/launcher.rb', line 90

def loaded_launch_file
  @loaded_launch_file
end

#nameObject (readonly)

String

Name of the launcher



85
86
87
# File 'lib/orogen/ros/spec/launcher.rb', line 85

def name
  @name
end

#projectObject (readonly)

Package

Project this launcher is part of



82
83
84
# File 'lib/orogen/ros/spec/launcher.rb', line 82

def project
  @project
end

Class Method Details

.parse(filename) ⇒ Set<Spec::XML::NodeDescription>

Parses a given launch file and extracts the launch information

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
# 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

Instance Method Details

#load_launch_fileObject

Loads the launch file if not already loaded



113
114
115
116
117
118
# 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?Boolean

Test whether the launch file has been automatically loaded

Returns:

  • (Boolean)


121
122
123
# File 'lib/orogen/ros/spec/launcher.rb', line 121

def loaded_launch_file?
    !!@loaded_launch_file
end

#node(name, klass) ⇒ OroGen::Spec::TaskDeployment

Declares a node in a ROS launcher

This is equivalently to declaring a task in a RTT deployment

Returns:



146
147
148
149
150
151
152
153
154
155
156
# 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) ⇒ String

Parse the launch file

Returns:

  • (String)

    Absolute path to the lauch file that has been loaded



129
130
131
132
133
134
135
136
137
138
139
# 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_sObject

String representaiton of this launcher



176
177
178
# File 'lib/orogen/ros/spec/launcher.rb', line 176

def to_s
    "Launcher: #{name}, launch_file: #{@launch_file}, loaded: #{loaded_launch_file?}"
end