Class: Syskit::Coordination::DataMonitoringTable

Inherits:
Roby::Coordination::Base
  • Object
show all
Extended by:
Models::DataMonitoringTable
Defined in:
lib/syskit/coordination/data_monitoring_table.rb

Overview

Definition of a data monitoring table

Examples:

Define a data monitoring table that attaches to all tasks of a given type

module Asguard
  data_monitoring_table 'TrajectoryFollowing' do
    attach_to ControlLoop.specialized_on 'controller' => TrajectoryFollower::Task
    monitor('pose', pose_child.pose_samples_port).
      trigger_on do |pose|
        # Verify that pose is within reasonable bounds of trajectory
      end.
      raise_exception
  end
  # Later, in an action interface file
  class Main < Roby::Actions::Interface
    use_data_monitoring_table Asguard::TrajectoryFollowing
  end
end

Define a standalone monitoring subsystem

module Asguard
  class LowLevelMonitor < Syskit::Composition
    add BatteryStatusSrv, :as => 'battery_provider'

    data_monitoring_table do
      monitor('battery_level', battery_provider_child.battery_status_port).
        trigger_on do |battery_status|
          battery_status.level < Robot.battery_required_to_reach_base
        end.
        raise_exception
    end
  end
end
# Later, in a profile definition
define 'low_level_monitor', Asguard::LowLevelMonitor.use(battery_dev)

Use a data monitoring table in a fault response table

module Asguard
  fault_response_table 'Safing' do
    use_data_monitoring_table LowLevelMonitor
    on_fault battery_level_monitor do
      go_recharge
    end
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Models::DataMonitoringTable

all_attachment_point, all_monitor, apply_block, attach_to, attachment_point, each_attachment_point, each_monitor, find_monitor, find_through_method_missing, has_through_method_missing?, monitor, validate_monitors

Constructor Details

#initialize(root_task, arguments = Hash.new, options = Hash.new) ⇒ DataMonitoringTable

Returns a new instance of DataMonitoringTable



55
56
57
58
59
60
61
62
63
64
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 55

def initialize(root_task, arguments = Hash.new, options = Hash.new)
    super(root_task, arguments, options)
    options, _ = Kernel.filter_options options, :on_replace => :drop
    @poll_id = root_task.poll(options) do
        poll
    end
    @monitors = Array.new
    @monitors_resolved = false
    resolve_monitors
end

Instance Attribute Details

#monitorsArray<DataMonitor> (readonly)

Returns list of instanciated data monitors

Returns:

  • (Array<DataMonitor>)

    list of instanciated data monitors



52
53
54
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 52

def monitors
  @monitors
end

Instance Method Details

#pollObject

Checks all the monitors for new data, and issue the related errors if their predicate triggers



96
97
98
99
100
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 96

def poll
    monitors.each do |m|
        m.poll(instance_for(model.root).resolve)
    end
end

#ready?Boolean

Checks whether the table is attached to all its data sources

Returns:

  • (Boolean)


103
104
105
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 103

def ready?
    @monitors_resolved && monitors.all?(&:ready?)
end

#remove!void

This method returns an undefined value.

Untie this table from the task it is currently attached to

It CANNOT be reused afterwards



70
71
72
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 70

def remove!
    root_task.remove_poll_handler(@poll_id)
end

#resolve_monitorsObject

Instanciates all data monitor registered on this table's models and stores the new monitors in #monitors



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/syskit/coordination/data_monitoring_table.rb', line 76

def resolve_monitors
    model.each_task do |coordination_task_model|
        if coordination_task_model.respond_to?(:instanciate)
            root_task.depends_on(task_instance = coordination_task_model.instanciate(root_task.plan))
            bind_coordination_task_to_instance(
                instance_for(coordination_task_model), task_instance,
                on_replace: :copy)
        end
    end

    monitors_m = model.each_monitor.to_a
    model.validate_monitors(monitors_m)
    root_task.execute do
        @monitors_resolved = true
        monitors.concat(monitors_m.map { |m| m.bind(self) })
    end
end