class Orocos::RobyPlugin::PortDynamics

A representation of the actual dynamics of a port

At the last stages, the Engine object will try to create and update PortDynamics for each known ports.

The PortDynamics objects maintain a list of so-called ‘triggers’. One trigger represents a single periodic event on a port (i.e. reception on an input port and emission on an output port). It states that the port will receive/send Orocos::RobyPlugin::PortDynamics::Trigger#sample_count samples at a period of Orocos::RobyPlugin::PortDynamics::Trigger#period. If period is zero, it means that it will happend “every once in a while”.

A sample is virtual: it is not an actual data sample on the connection. The translation between both is given by #sample_size.

Attributes

name[R]

The name of the port we are computing dynamics for. This is used for debugging purposes only

sample_size[R]

The number of data samples per trigger, if the port’s model value needs to be overriden

triggers[R]

The set of registered triggers for this port, as a list of Trigger objects, where period is in seconds and #sample_count is the count of samples sent at period intervals

Public Class Methods

new(name, sample_size = 1) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 91
def initialize(name, sample_size = 1)
    @name = name
    @sample_size = sample_size.to_int
    @triggers = Array.new
end

Public Instance Methods

add_trigger(name, period, sample_count) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 99
def add_trigger(name, period, sample_count)
    if sample_count != 0
        DataFlowDynamics.debug { "  [#{self.name}]: adding trigger from #{name} - #{period} #{sample_count}" }
        triggers << Trigger.new(name, period, sample_count).freeze
    end
end
empty?() click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 97
def empty?; triggers.empty? end
merge(other_dynamics) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 106
def merge(other_dynamics)
    DataFlowDynamics.debug do
        DataFlowDynamics.debug "adding triggers from #{other_dynamics.name} to #{name}"
        DataFlowDynamics.log_nest(4) do
            DataFlowDynamics.log_pp(:debug, other_dynamics)
        end
        break
    end
    triggers.concat(other_dynamics.triggers)
    true
end
minimal_period() click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 118
def minimal_period
    triggers.map(&:period).min
end
pretty_print(pp) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 143
def pretty_print(pp)
    pp.seplist(triggers) do |tr|
        pp.text "(#{tr.name}): #{tr.period} #{tr.sample_count}"
    end
end
queue_size(duration) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 139
def queue_size(duration)
    (1 + sample_count(duration)) * sample_size
end
sample_count(duration) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 129
def sample_count(duration)
    triggers.map do |trigger|
        if trigger.period == 0
            trigger.sample_count
        else
            (duration/trigger.period).floor * trigger.sample_count
        end
    end.inject(&:+)
end
sampled_at(duration) click to toggle source
# File lib/orocos/roby/dataflow_dynamics.rb, line 122
def sampled_at(duration)
    result = PortDynamics.new(name, sample_size)
    names = triggers.map(&:name)
    result.add_trigger("#{name}.resample(#{names.join(",")},#{duration})", duration, queue_size(duration))
    result
end