class Roby::DeltaEvent
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 withthreshold
. #read
-
must return the current value.
Attributes
The last value for the considered state, the last time this event has been emitted
A value expressing the delta in state for which the event should be emitted.
Public Class Methods
The set of event types which
# File lib/roby/state/events.rb, line 214 def self.event_types; @@event_types end
# File lib/roby/state/events.rb, line 244 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
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
# File lib/roby/state/events.rb, line 226 def self.register_as(name) event_types[name] = self end
Public Instance Methods
# File lib/roby/state/events.rb, line 254 def or(spec) DeltaEvent.or(spec, self) end
Reset last_value
to the current value of the state variable, making the event emit at current_value + threshold
Roby::StateEvent#reset
# File lib/roby/state/events.rb, line 239 def reset @last_value = read super end