Class: Roby::DeltaEvent

Inherits:
StateEvent show all
Defined in:
lib/roby/state/events.rb

Overview

Generic implementation of events which emit when a given delta is reached in the state. Subclasses must implement the following methods:

#has_sample

must return true if the state variable can be read

#delta

must return the delta between the current value and the value at the last emission (#last_value). The returned value must be comparable with #threshold.

#read

must return the current value.

Direct Known Subclasses

PosDeltaEvent, TimeDeltaEvent, YawDeltaEvent

Constant Summary collapse

@@event_types =
{}

Instance Attribute Summary collapse

Attributes inherited from EventGenerator

#command, #event_model, #history, #unreachability_reason, #unreachable_handlers

Attributes inherited from PlanObject

#addition_time, #executable, #execution_engine, #finalization_handlers, #finalization_time, #model, #plan, #promise_executor, #removed_at

Attributes included from Transaction::Proxying::Cache

#transaction_forwarder_module, #transaction_proxy_module

Attributes included from Relations::DirectedRelationSupport

#relation_graphs

Attributes inherited from DistributedObject

#local_owner_id, #owners

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StateEvent

#disable, #disabled?, #emit, #enable, #enabled?, #initialize

Methods inherited from EventGenerator

#&, #achieve_asynchronously, #achieve_with, #add_child_object, #call, #call_handlers, #call_unreachable_handlers, #call_without_propagation, #called, #calling, #cancel, #check_call_validity, #check_call_validity_after_calling, #check_emission_validity, #clear_pending, #controlable?, #create_transaction_proxy, #default_command, #delay, #each_precondition, #emit, #emit_failed, #emit_without_propagation, #emitting, #filter, #finalized!, #fire, #fired, #forward, #forward_once, #forward_to, #forward_to_once, #forwarded_to?, #garbage!, #happened?, #if_unreachable, #initialize, #initialize_copy, #initialize_replacement, #last, #mark_unreachable!, match, #match, #model, #name, #new, #on, #once, #pending, #plan=, #precondition, #pretty_print, #realize_with, #related_events, #related_tasks, #replace_by, #signal, #signals, #signals_once, #to_event, #to_execution_exception, #to_execution_exception_matcher, #unreachable!, #unreachable_without_propagation, #until, #when_unreachable, #|

Methods included from Roby::DRoby::Identifiable

#droby_id, #initialize_copy

Methods included from Roby::DRoby::V5::DRobyConstant::Dump

#droby_dump, #droby_marshallable?

Methods included from Roby::DRoby::V5::EventGeneratorDumper

#droby_dump

Methods included from GUI::RelationsCanvasEventGenerator

#display, #display_create, #display_name, #display_time_end, #display_time_start, priorities, style, styles

Methods included from GUI::RelationsCanvasPlanObject

#display, #display_create, #display_events, #display_name, #display_parent

Methods inherited from PlanObject

#add_child_object, #apply_relation_changes, #as_plan, #can_finalize?, #commit_transaction, #concrete_model, #connection_space, #each_finalization_handler, #each_in_neighbour_merged, #each_out_neighbour_merged, #each_plan_child, #engine, #executable?, #finalized!, #finalized?, #forget_peer, #fullfills?, #garbage!, #garbage?, #initialize, #initialize_copy, #initialize_replacement, #merged_relations, #promise, #read_write?, #real_object, #remotely_useful?, #replace_by, #replace_subplan_by, #root_object, #root_object?, #subscribed?, #transaction_proxy?, #transaction_stack, #update_on?, #updated_by?, #when_finalized

Methods included from Models::PlanObject

#child_plan_object, #finalization_handler, #match, #when_finalized

Methods included from GUI::GraphvizPlanObject

#apply_layout, #dot_label, #to_dot

Methods included from Relations::DirectedRelationSupport

#[], #[]=, #add_child_object, #add_parent_object, #child_object?, #child_objects, #clear_vertex, #each_child_object, #each_in_neighbour, #each_out_neighbour, #each_parent_object, #each_relation, #each_relation_graph, #each_relation_sorted, #each_root_relation_graph, #enum_child_objects, #enum_parent_objects, #enum_relations, #leaf?, #parent_object?, #parent_objects, #related_object?, #related_objects, #relation_graph_for, #relations, #remove_child_object, #remove_children, #remove_parent_object, #remove_parents, #remove_relations, #root?, #sorted_relations

Methods inherited from DistributedObject

#add_owner, #clear_owners, #initialize, #initialize_copy, #owned_by?, #remove_owner

Constructor Details

This class inherits a constructor from Roby::StateEvent

Instance Attribute Details

#last_valueObject (readonly)

The last value for the considered state, the last time this event has been emitted



248
249
250
# File 'lib/roby/state/events.rb', line 248

def last_value
  @last_value
end

#thresholdObject

A value expressing the delta in state for which the event should be emitted.



251
252
253
# File 'lib/roby/state/events.rb', line 251

def threshold
  @threshold
end

Class Method Details

.event_typesObject

The set of event types which



227
228
229
# File 'lib/roby/state/events.rb', line 227

def self.event_types
    @@event_types
end

.or(spec, base_event) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/roby/state/events.rb', line 260

def self.or(spec, base_event)
    new = State.on_delta(spec)
    result = OrGenerator.new
    result << base_event
    result << new
    result.on { |ev| result.reset }
    def result.or(spec)
        DeltaEvent.or(spec, self)
    end
    result
end

.register_as(name) ⇒ Object

Declare that the currently defined delta event has to be registered as a name option for StateSpace#on_delta. For instance, the TimeDeltaEvent is registered by using

class TimeDeltaEvent < DeltaEvent
  register_as :t
end

which allows to use it with

Roby.state.on_delta t: 10


242
243
244
# File 'lib/roby/state/events.rb', line 242

def self.register_as(name)
    event_types[name] = self
end

Instance Method Details

#or(spec) ⇒ Object



272
273
274
# File 'lib/roby/state/events.rb', line 272

def or(spec)
    DeltaEvent.or(spec, self)
end

#pollObject

Called at each cycle by Roby.poll_state_events



277
278
279
280
281
282
283
284
285
286
# File 'lib/roby/state/events.rb', line 277

def poll # :nodoc:
    if !has_sample?
        nil
    elsif !last_value
        @last_value = read
    elsif delta.abs >= threshold
        reset
        emit(last_value)
    end
end

#resetObject

Reset last_value to the current value of the state variable, making the event emit at current_value + threshold



255
256
257
258
# File 'lib/roby/state/events.rb', line 255

def reset
    @last_value = read
    super
end