Class: Roby::StateSpace
- Inherits:
-
ExtendedStruct
- Object
- ExtendedStruct
- Roby::StateSpace
- Defined in:
- lib/roby/state/state.rb,
lib/roby/state/events.rb
Constant Summary
Constants inherited from ExtendedStruct
ExtendedStruct::FORBIDDEN_NAMES, ExtendedStruct::FORBIDDEN_NAMES_RX, ExtendedStruct::NOT_OVERRIDABLE, ExtendedStruct::NOT_OVERRIDABLE_RX
Instance Attribute Summary
Attributes inherited from ExtendedStruct
#__parent_name, #__parent_struct, #children_class
Instance Method Summary collapse
- #_dump(lvl = -1)) ⇒ Object
-
#at(options) ⇒ Object
Returns an event which emits when the given state is reached.
- #deep_copy ⇒ Object
- #export(*names) ⇒ Object
-
#initialize ⇒ StateSpace
constructor
A new instance of StateSpace.
-
#on_delta(spec) ⇒ Object
Create an event which will be emitted everytime some state parameters vary more than the given deltas.
- #simulation? ⇒ Boolean
- #testing? ⇒ Boolean
Methods inherited from ExtendedStruct
#__respond_to__, _load, #alias, #attach, #attach_child, #clear, #delete, #each_member, #empty?, #filter, #get, #method_missing, #on, #respond_to?, #stable!, #stable?, #to_hash, #update, #updated
Constructor Details
#initialize ⇒ StateSpace
Returns a new instance of StateSpace.
339 340 341 342 |
# File 'lib/roby/state/state.rb', line 339 def initialize @exported_fields = Set.new super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Roby::ExtendedStruct
Instance Method Details
#_dump(lvl = -1)) ⇒ Object
344 345 346 347 348 349 350 351 |
# File 'lib/roby/state/state.rb', line 344 def _dump(lvl = -1) marshalled_members = @exported_fields.map do |name| value = @members[name] [name, Marshal.dump(value)] rescue nil end marshalled_members.compact! Marshal.dump([marshalled_members, @aliases]) end |
#at(options) ⇒ Object
Returns an event which emits when the given state is reached. For now, the following state variables are available:
t-
time as a Time object
See TimePointEvent
56 57 58 59 60 61 |
# File 'lib/roby/state/events.rb', line 56 def at() = , :t => nil if time = [:t] TimePointEvent.new(time) end end |
#deep_copy ⇒ Object
353 354 355 356 357 358 |
# File 'lib/roby/state/state.rb', line 353 def deep_copy exported_fields, @exported_fields = @exported_fields, Set.new Marshal.load(Marshal.dump(self)) ensure @exported_fields = exported_fiels end |
#export(*names) ⇒ Object
362 363 364 |
# File 'lib/roby/state/state.rb', line 362 def export(*names) @exported_fields.merge names.map { |n| n.to_s }.to_set end |
#on_delta(spec) ⇒ Object
Create an event which will be emitted everytime some state parameters vary more than the given deltas. The following state parameters are available:
t-
time in seconds
d-
distance in meters
yaw-
heading in radians
For instance:
Roby.state.on_delta :d => 10, :t => 20
will emit everytime the robot moves more than 10 meters AND more than 20 seconds have elapsed.
If more than once specification is given, the resulting event is combined with the & operator. This can be changed by setting the :or option to ‘true’.
Roby.state.on_delta :d => 10, :t => 20, :or => true
See DeltaEvent and its subclasses.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/roby/state/events.rb', line 24 def on_delta(spec) or_aggregate = spec.delete(:or) events = spec.map do |name, value| unless klass = DeltaEvent.event_types[name] raise "unknown delta type #{name}. Known types are #{DeltaEvent.event_types.keys}" end ev = klass.new ev.threshold = value ev end if events.size > 1 result = if or_aggregate then OrGenerator.new else AndGenerator.new end result.on { result.reset } def result.or(spec); DeltaEvent.or(spec, self) end events.each { |ev| result << ev } result else events.first end end |
#simulation? ⇒ Boolean
361 |
# File 'lib/roby/state/state.rb', line 361 def simulation?; Roby.app.simulation? end |
#testing? ⇒ Boolean
360 |
# File 'lib/roby/state/state.rb', line 360 def testing?; Roby.app.testing? end |