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 =
Hash.new

Constants included from Log::EventGeneratorHooks

Log::EventGeneratorHooks::HOOKS

Constants included from Log::BasicObjectHooks

Log::BasicObjectHooks::HOOKS

Instance Attribute Summary collapse

Attributes inherited from EventGenerator

#command, #executable, #pending, #unreachable_handlers

Attributes inherited from PlanObject

#executable, #plan, #removed_at

Attributes inherited from BasicObject

#distribute

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StateEvent

#disable, #disabled?, #enable, #enabled?

Methods inherited from EventGenerator

#&, #_dump, _load, #achieve_with, #add_child_object, #call, #call_handlers, #call_without_propagation, #called, #calling, #cancel, #controlable?, #default_command, #delay, #droby_dump, #each_precondition, #emit, #emit_failed, #emit_on, #emit_without_propagation, #emitting, event_gathering, #executable?, #filter, #fired, #forward, #forward_once, #forwarding, gather_events, #if_unreachable, #initialize, #initialize_copy, #last, #model, #name, #new, #on, #once, #pending?, #postpone, #postponed, #precondition, #pretty_print, #realize_with, #related_events, #related_tasks, remove_event_gathering, #signal, #signal_once, #signalling, #to_event, #unreachable!, #until, #when_unreachable, #|

Methods included from Roby::Distributed::DRobyModel::Dump

#droby_dump

Methods included from Roby::Distributed::EventNotifications

#fired, #forwarding, #signalling

Methods included from Propagation::EventPrecedenceChanged

#added_child_object, #removed_child_object

Methods included from Log::EventGeneratorHooks

#added_child_object, #called, #calling, #emitting, #fired, #forwarding, #postponed, #removed_child_object, #signalling

Methods inherited from PlanObject

#add_child_object, #apply_relation_changes, child_plan_object, #each_plan_child, #executable?, #finalized?, #forget_peer, #read_write?, #remotely_useful?, #removing_child_object, #replace_by, #replace_subplan_by, #root_object, #root_object?, #subscribed?, #update_on?, #updated_by?

Methods included from Roby::Distributed::RelationModificationHooks

#added_child_object, #removed_child_object

Methods included from Transactions::PlanObjectUpdates

#adding_child_object, #removing_child_object

Methods included from DirectedRelationSupport

#add_child_object, #add_parent_object, #check_is_relation, #related_objects, #relations, #remove_child_object, #remove_children, #remove_parent_object, #remove_parents, #remove_relations

Methods inherited from BasicObject

#add_sibling_for, #distribute?, distribute?, #finalized?, #forget_peer, #has_sibling_on?, #initialize_copy, local_only, #read_write?, #remotely_useful?, #remove_sibling_for, #self_owned?, #sibling_of, #sibling_on, #subscribe, #subscribed?, #update_on?, #updated?, #updated_by?, #updated_peers

Methods included from Log::BasicObjectHooks

#added_owner, #removed_owner

Constructor Details

This class inherits a constructor from Roby::EventGenerator

Instance Attribute Details

#last_valueObject (readonly)

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



143
144
145
# File 'lib/roby/state/events.rb', line 143

def last_value
  @last_value
end

#thresholdObject

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



146
147
148
# File 'lib/roby/state/events.rb', line 146

def threshold
  @threshold
end

Class Method Details

.event_typesObject

The set of event types which



125
# File 'lib/roby/state/events.rb', line 125

def self.event_types; @@event_types end

.or(spec, base_event) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/roby/state/events.rb', line 154

def self.or(spec, base_event)
    new = State.on_delta(spec)
    result = OrGenerator.new
    result << base_event
    result << new
    result.on { 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


137
138
139
# File 'lib/roby/state/events.rb', line 137

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

Instance Method Details

#or(spec) ⇒ Object



164
165
166
# File 'lib/roby/state/events.rb', line 164

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

#pollObject

Called at each cycle by Roby.poll_state_events



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/roby/state/events.rb', line 169

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

#resetObject

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



150
151
152
# File 'lib/roby/state/events.rb', line 150

def reset
    @last_value = read
end