Class: BirdbrainFinchInput
Overview
Copyright © 2021 Base2 Incorporated–All Rights Reserved.
Constant Summary
collapse
- DEFAULT_FACTOR =
1.0
- DEFAULT_MIN_RESPONSE =
0
- DEFAULT_MAX_RESPONSE =
100
- DEFAULT_TYPE_METHOD =
'to_i'
- DEFAULT_UNLIMITED_MIN_RESPONSE =
-1000000
- DEFAULT_UNLIMITED_MAX_RESPONSE =
1000000
- ORIENTATIONS =
['Beak%20Up', 'Beak%20Down', 'Tilt%20Left', 'Tilt%20Right', 'Level', 'Upside%20Down']
- ORIENTATION_RESULTS =
['Beak up', 'Beak down', 'Tilt left', 'Tilt right', 'Level', 'Upside down', 'In between']
- ORIENTATION_IN_BETWEEN =
'In between'
BirdbrainRequest::BIRDBRAIN_TEST
Class Method Summary
collapse
bounds, calculate_angle, calculate_intensity, calculate_left_or_right, calculate_speed, connected?, disconnect, not_connected?, request_status, response, response_body, uri, xyz_response
Class Method Details
.accelerometer(device) ⇒ Object
49
50
51
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 49
def self.accelerometer(device)
xyz_response(device, 'finchAccel')
end
|
.compass(device) ⇒ Object
53
54
55
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 53
def self.compass(device)
(response = response_body('hummingbird', 'in', 'finchCompass', 'static', device)).nil? ? response : response.to_i
end
|
.distance(device) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 27
def self.distance(device)
distance_options = {}
distance_options[:factor] = 0.0919
distance_options[:min_response] = DEFAULT_UNLIMITED_MIN_RESPONSE
distance_options[:max_response] = DEFAULT_UNLIMITED_MAX_RESPONSE
sensor(device, 'Distance', 'static', distance_options)
end
|
.encoder(device, direction) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 40
def self.encoder(device, direction)
encoder_options = {}
encoder_options[:min_response] = DEFAULT_UNLIMITED_MIN_RESPONSE
encoder_options[:max_response] = DEFAULT_UNLIMITED_MAX_RESPONSE
encoder_options[:type_method] = 'to_f'
sensor(device, 'Encoder', calculate_left_or_right(direction), encoder_options)
end
|
.finch?(device) ⇒ Boolean
15
16
17
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 15
def self.finch?(device)
request_status(response_body('hummingbird', 'in', 'isFinch', 'static', device))
end
|
.light(device, direction) ⇒ Object
23
24
25
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 23
def self.light(device, direction)
sensor(device, 'Light', calculate_left_or_right(direction))
end
|
.line(device, direction) ⇒ Object
36
37
38
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 36
def self.line(device, direction)
sensor(device, 'Line', calculate_left_or_right(direction))
end
|
.magnetometer(device) ⇒ Object
57
58
59
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 57
def self.magnetometer(device)
xyz_response(device, 'finchMag')
end
|
.moving?(device) ⇒ Boolean
19
20
21
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 19
def self.moving?(device)
request_status(response_body('hummingbird', 'in', 'finchIsMoving', 'static', device))
end
|
.orientation(device) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 61
def self.orientation(device)
ORIENTATIONS.each_with_index do |orientation, index|
return nil if (response = response_body('hummingbird', 'in', 'finchOrientation', orientation, device)).nil?
return ORIENTATION_RESULTS[index] if request_status(response)
end
ORIENTATION_IN_BETWEEN
end
|
.orientation_beak_down?(device) ⇒ Boolean
75
76
77
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 75
def self.orientation_beak_down?(device)
orientation_check(device, 1)
end
|
.orientation_beak_up?(device) ⇒ Boolean
71
72
73
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 71
def self.orientation_beak_up?(device)
orientation_check(device, 0)
end
|
.orientation_level?(device) ⇒ Boolean
87
88
89
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 87
def self.orientation_level?(device)
orientation_check(device, 4)
end
|
.orientation_tilt_left?(device) ⇒ Boolean
79
80
81
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 79
def self.orientation_tilt_left?(device)
orientation_check(device, 2)
end
|
.orientation_tilt_right?(device) ⇒ Boolean
83
84
85
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 83
def self.orientation_tilt_right?(device)
orientation_check(device, 3)
end
|
.orientation_upside_down?(device) ⇒ Boolean
91
92
93
|
# File 'lib/birdbrain/birdbrain_finch_input.rb', line 91
def self.orientation_upside_down?(device)
orientation_check(device, 5)
end
|