module Roby::Coordination::Models::Script

The metamodel for all script-based coordination models

Public Instance Methods

add(instruction) click to toggle source
# File lib/roby/coordination/models/script.rb, line 274
def add(instruction)
    if terminal?
        raise ArgumentError, "a terminal command has been called on this script, cannot add anything further"
    end
    instructions << instruction
end
call(script) click to toggle source

Execute another script at this point in the execution

# File lib/roby/coordination/models/script.rb, line 258
def call(script)
    instructions.concat(script.instructions)
end
emit(event) click to toggle source

Emit the given event

@param [Event] event

# File lib/roby/coordination/models/script.rb, line 252
def emit(event)
    validate_event event
    add Emit.new(event)
end
execute(task, options = Hash.new) click to toggle source

Starts the given task, and waits for it to successfully finish

@param [Task] task the action-task. It must be created by

calling {Base#task} on the relevant object

@param [Hash] options the dependency relation options. See

{Roby::TaskStructure::Dependency::Extension#depends_on}
# File lib/roby/coordination/models/script.rb, line 211
def execute(task, options = Hash.new)
    task = validate_or_create_task task
    start(task, options)
    wait(task.success_event)
end
sleep(time) click to toggle source

Waits a certain amount of time before continuing

@param [Float] time the amount of time to wait, in seconds

# File lib/roby/coordination/models/script.rb, line 220
def sleep(time)
    task = self.task(ActionCoordination::TaskFromAsPlan.new(Tasks::Timeout.with_arguments(delay: time), Tasks::Timeout))
    start task, explicit_start: true
    wait task.stop_event
end
start(task, explicit_start: false, **options) click to toggle source

Starts the given task

@param [Task] task the action-task. It must be created by

calling {Base#task} on the relevant object

@param [Hash] options the dependency relation options. See

{Roby::TaskStructure::Dependency::Extension#depends_on}
# File lib/roby/coordination/models/script.rb, line 199
def start(task, explicit_start: false, **options)
    task = validate_or_create_task task
    add Start.new(task, explicit_start: explicit_start, **options)
    wait(task.start_event)
end
terminal() click to toggle source

Marks this script has being terminated, i.e. that no new instructions can be added to it

Once this is called, adding new instructions will raise ArgumentError

# File lib/roby/coordination/models/script.rb, line 179
def terminal
    __terminal(true)
end
terminal?() click to toggle source

@return [Boolean] if true, this script cannot get new

instructions (a terminal instruction has been added)
# File lib/roby/coordination/models/script.rb, line 185
def terminal?
    __terminal
end
timeout_start(delay, options = Hash.new) click to toggle source
# File lib/roby/coordination/models/script.rb, line 262
def timeout_start(delay, options = Hash.new)
    ins = TimeoutStart.new(delay, options)
    add ins
    ins
end
timeout_stop(timeout_start) click to toggle source
# File lib/roby/coordination/models/script.rb, line 268
def timeout_stop(timeout_start)
    ins = TimeoutStop.new(timeout_start)
    add ins
    ins
end
wait(event, timeout: nil, **wait_options) click to toggle source

Waits until this event gets emitted

It will wait even if this event has already been emitted at this point in the script (i.e. waits for a “new” emission)

@param [Event] event the event to wait for @param [Hash] options @param [Float] timeout a timeout (for backward

compatibility, use timeout(seconds) do ... end instead)
# File lib/roby/coordination/models/script.rb, line 235
def wait(event, timeout: nil, **wait_options)
    validate_event event

    wait = Wait.new(event, **wait_options)
    if timeout
        timeout(timeout) do
            add wait
        end
    else
        add wait
    end
    wait
end