class Orocos::OutputPort

This class represents output ports on remote task contexts.

They are obtained from Orocos::TaskContext#port or Orocos::TaskContextBase#each_port

Public Class Methods

reader_class() click to toggle source

Used by OutputPortReadAccess to determine which output reader class should be used

# File lib/orocos/output_port.rb, line 15
def self.reader_class; OutputReader end

Public Instance Methods

connect_to(input_port, distance: D_UNKNOWN, **options) click to toggle source

Connect this output port to an input port. options defines the connection policy for the connection. If a task is given instead of an input port the method will try to find the right input port by type and will raise an error if there are none or more than one matching input ports

The following options are available:

Data connections. In that connection, the reader will see only the last sample he received. Such a connection is set up with

input_port.connect_to output_port, :type => :data

Buffered connections. In that case, the reader will be able to read all the samples received since the last read. A buffer in between the output and input port will keep the samples that have not been read already. Such a connection is set up with:

output_port.connect_to input_port, :type => :buffer, :size => 10

Where the size option gives the size of the intermediate buffer. Note that new samples will be lost if they are received when the buffer is full.

Calls superclass method Orocos::OutputPortBase#connect_to
# File lib/orocos/output_port.rb, line 40
def connect_to(input_port, distance: D_UNKNOWN, **options)
    if !input_port.respond_to?(:to_orocos_port)
        return super
    end

    input_port = input_port.to_orocos_port
    if !input_port.kind_of?(InputPort)
        raise ArgumentError, "an output port can only connect to an input port (got #{input_port})"
    elsif input_port.type.name != type.name
        raise ArgumentError, "trying to connect #{self}, an output port of type #{type.name}, to #{input_port}, an input port of type #{input_port.type.name}"
    end

    policy = Port.prepare_policy(**options)
    if distance == D_UNKNOWN
        distance = distance_to(input_port)
    end
    if distance == D_SAME_HOST
        policy = handle_mq_transport(input_port.full_name, policy)
    end
    if policy[:pull]
        input_port.blocking_read = true
    end

    begin
        refine_exceptions(input_port) do
            do_connect_to(input_port, policy)
        end
    rescue Orocos::ConnectionFailed => e
        if policy[:transport] == TRANSPORT_MQ && Orocos::MQueue.auto_fallback_to_corba?
            policy[:transport] = TRANSPORT_CORBA
            Orocos.warn "failed to create a connection from #{full_name} to #{input_port.full_name} using the MQ transport, falling back to CORBA"
            retry
        end
        raise
    end
            
    self
rescue Orocos::ConnectionFailed => e
    raise e, "failed to connect #{full_name} => #{input_port.full_name} with policy #{policy.inspect}"
end
disconnect_from(input) click to toggle source

Require this port to disconnect from the provided input port

Calls superclass method Orocos::OutputPortBase#disconnect_from
# File lib/orocos/output_port.rb, line 82
def disconnect_from(input)
    if !input.respond_to?(:to_orocos_port)
        return super
    end

    input = input.to_orocos_port
    refine_exceptions(input) do
        do_disconnect_from(input)
    end
end
do_connect_to(p1, p2) click to toggle source

Actual implementation of connect_to. Sanity checks are done in Ruby. Just create the connection.

static VALUE do_port_connect_to(VALUE routput_port, VALUE rinput_port, VALUE options)
{
    RTaskContext* out_task; VALUE out_name;
    tie(out_task, tuples::ignore, out_name) = getPortReference(routput_port);
    RTaskContext* in_task; VALUE in_name;
    tie(in_task, tuples::ignore, in_name) = getPortReference(rinput_port);

    RTT::corba::CConnPolicy policy = policyFromHash(options);
    bool result = corba_blocking_fct_call_with_result(bind(&_objref_CDataFlowInterface::createConnection,(_objref_CDataFlowInterface*)out_task->ports,
                StringValuePtr(out_name),in_task->ports,StringValuePtr(in_name),policy));
    if(!result)
        rb_raise(eConnectionFailed, "failed to connect ports");
    return Qnil;
}
publish_on_ros(topic_name = default_ros_topic_name, policy = Hash.new) click to toggle source

Publishes this port on a ROS topic

# File lib/orocos/ros/ports.rb, line 10
def publish_on_ros(topic_name = default_ros_topic_name, policy = Hash.new)
    if topic_name.kind_of?(Hash)
        topic_name, policy = default_ros_topic_name, topic_name
    end
    create_stream(Orocos::TRANSPORT_ROS, topic_name, policy)
end
to_async(options = Hash.new) click to toggle source
# File lib/orocos/async/orocos.rb, line 66
def to_async(options = Hash.new)
    if use = options.delete(:use)
        Orocos::Async::CORBA::OutputPort.new(use,self,options)
    else to_async(Hash[:use => task.to_async].merge(options))
    end
end
to_proxy(options = Hash.new) click to toggle source
# File lib/orocos/async/orocos.rb, line 73
def to_proxy(options = Hash.new)
    task.to_proxy(options).port(name,:type => type)
end
unpublish_from_ros(topic_name = " click to toggle source

Unpublishes this port from a ROS topic

# File lib/orocos/ros/ports.rb, line 18
def unpublish_from_ros(topic_name = "#{task.name}/#{self.name}")
    remove_stream(topic_name)
end