Class: Enginevib::Main

Inherits:
Object
  • Object
show all
Includes:
Launcher
Defined in:
lib/enginevib/main.rb

Overview

The main class. run is called when run from command line.

Constant Summary collapse

DEADLINE =

30 milliseconds

30.0 / 1000.0
TOLERANCE =

7 miliseconds

7.0 / 1000.0
AVERAGE_SAMPLE_SIZE =

100 ticks

100

Instance Attribute Summary collapse

Attributes included from Launcher

#options

Instance Method Summary collapse

Methods included from Launcher

#launch, #parse_arguments

Constructor Details

#initializeMain

Returns a new instance of Main.



11
12
13
14
15
# File 'lib/enginevib/main.rb', line 11

def initialize
  parse_arguments
  initialize_components
  initialize_scheduler
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



5
6
7
# File 'lib/enginevib/main.rb', line 5

def controller
  @controller
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/enginevib/main.rb', line 5

def output
  @output
end

#schedulerObject

Returns the value of attribute scheduler.



5
6
7
# File 'lib/enginevib/main.rb', line 5

def scheduler
  @scheduler
end

#sensorObject

Returns the value of attribute sensor.



5
6
7
# File 'lib/enginevib/main.rb', line 5

def sensor
  @sensor
end

#systemObject

Returns the value of attribute system.



5
6
7
# File 'lib/enginevib/main.rb', line 5

def system
  @system
end

Instance Method Details

#initialize_componentsObject



17
18
19
20
21
22
# File 'lib/enginevib/main.rb', line 17

def initialize_components
  @sensor = Sensor.new(@options[:serial_port], @options[:simulation_mode])
  @output = Output.new
  @system = System.new
  @controller = Controller.new
end

#initialize_schedulerObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/enginevib/main.rb', line 24

def initialize_scheduler
  @scheduler = Scheduler.new(DEADLINE, TOLERANCE) do |stats|
    if @controller.inop
      sleep DEADLINE - TOLERANCE
    else
      data = @sensor.read
      computed_data = @system.compute(data)
      @output.refresh_display(computed_data, stats)
    end
  end
end

#start_schedulerObject



36
37
38
# File 'lib/enginevib/main.rb', line 36

def start_scheduler
  @scheduler.start
end