Module: Roby::Coordination::Script

Included in:
ActionScript, TaskScript
Defined in:
lib/roby/coordination/script.rb

Overview

Common logic for script-based coordination models

Defined Under Namespace

Modules: Models Classes: BlockExecute, PollUntil, TimedOut, TimeoutStart, TimeoutStop

Constant Summary collapse

DeadInstruction =
Models::Script::DeadInstruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_instructionObject (readonly)

Returns the value of attribute current_instruction.



153
154
155
# File 'lib/roby/coordination/script.rb', line 153

def current_instruction
  @current_instruction
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



153
154
155
# File 'lib/roby/coordination/script.rb', line 153

def instructions
  @instructions
end

Instance Method Details

#dependency_options_for(toplevel, task, roles) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/roby/coordination/script.rb', line 172

def dependency_options_for(toplevel, task, roles)
    options = super
    if current_instruction.respond_to?(:task) &&
       current_instruction.task == task
        options = options.merge(current_instruction.dependency_options)
    end
    options
end

#finished?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/roby/coordination/script.rb', line 206

def finished?
    instructions.empty? && !@current_instruction
end

#jump_to(target) ⇒ Object



195
196
197
198
199
200
201
202
203
204
# File 'lib/roby/coordination/script.rb', line 195

def jump_to(target)
    # Verify that the jump is valid
    if current_instruction != target && !instructions.include?(target)
        raise ArgumentError, "#{target} is not an instruction in #{self}"
    end

    current_instruction.cancel if current_instruction != target
    instructions.shift while instructions.first != target
    step
end

#prepareObject



155
156
157
158
159
160
161
162
163
164
# File 'lib/roby/coordination/script.rb', line 155

def prepare
    @instructions = []
    resolve_instructions
    @current_instruction = nil

    root_task.stop_event.on do |_context|
        current_instruction&.cancel
        instructions.each(&:cancel)
    end
end

#resolve_instructionsObject



166
167
168
169
170
# File 'lib/roby/coordination/script.rb', line 166

def resolve_instructions
    model.instructions.each do |ins|
        instructions << instance_for(ins)
    end
end

#stepObject



181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/roby/coordination/script.rb', line 181

def step
    return if current_instruction && !current_instruction.disabled?

    while (@current_instruction = instructions.shift)
        next if current_instruction.disabled?

        break unless current_instruction.execute(self)
    end
rescue LocalizedError => e
    raise e
rescue Exception => e # rubocop:disable Lint/RescueException
    raise CodeError.new(e, root_task), e.message, e.backtrace
end