Class: FB::OutgoingHandler
- Inherits:
-
Object
- Object
- FB::OutgoingHandler
show all
- Defined in:
- lib/arduino/outgoing_handler.rb
Overview
Writes GCode to the serial line. Creates messages the travel from the PI to the ARDUINO.
Defined Under Namespace
Classes: BadBooleanValue, BadNumericValue, InvalidAxisEntry
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#emergency_stop ⇒ Object
-
#home_all ⇒ Object
-
#home_x ⇒ Object
-
#home_y ⇒ Object
-
#home_z ⇒ Object
-
#initialize(bot) ⇒ OutgoingHandler
constructor
A new instance of OutgoingHandler.
-
#move_absolute(x: 0, y: 0, z: 0, s: 100) ⇒ Object
-
#move_relative(x: 0, y: 0, z: 0, s: 100) ⇒ Object
-
#read_parameter(num) ⇒ Object
Parameters are settings, which is not to be confused with status.
-
#read_pin(pin, mode = :digital) ⇒ Object
-
#read_status(num) ⇒ Object
-
#set_acceleration(axis, value) ⇒ Object
-
#set_end_inversion(axis, value) ⇒ Object
-
#set_max_speed(axis, value) ⇒ Object
-
#set_motor_inversion(axis, value) ⇒ Object
-
#set_negative_coordinates(axis, value) ⇒ Object
-
#set_steps_per_mm(axis, value) ⇒ Object
-
#set_timeout(axis, value) ⇒ Object
-
#wait(ms) ⇒ Object
-
#write_parameter(num, val) ⇒ Object
-
#write_pin(pin:, value:, mode:) ⇒ Object
Constructor Details
Returns a new instance of OutgoingHandler.
7
8
9
|
# File 'lib/arduino/outgoing_handler.rb', line 7
def initialize(bot)
@bot = bot
end
|
Instance Attribute Details
#bot ⇒ Object
Returns the value of attribute bot.
5
6
7
|
# File 'lib/arduino/outgoing_handler.rb', line 5
def bot
@bot
end
|
Instance Method Details
#emergency_stop ⇒ Object
11
12
13
14
15
16
|
# File 'lib/arduino/outgoing_handler.rb', line 11
def emergency_stop(*)
bot.outbound_queue = [] bot.serial_port.puts "E" bot.status[:last] = :emergency_stop
end
|
#home_all ⇒ Object
50
51
52
|
# File 'lib/arduino/outgoing_handler.rb', line 50
def home_all
write { "G28" }
end
|
#home_x ⇒ Object
38
39
40
|
# File 'lib/arduino/outgoing_handler.rb', line 38
def home_x
write { "F11" }
end
|
#home_y ⇒ Object
42
43
44
|
# File 'lib/arduino/outgoing_handler.rb', line 42
def home_y
write { "F12" }
end
|
#home_z ⇒ Object
46
47
48
|
# File 'lib/arduino/outgoing_handler.rb', line 46
def home_z
write { "F13" }
end
|
#move_absolute(x: 0, y: 0, z: 0, s: 100) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/arduino/outgoing_handler.rb', line 31
def move_absolute(x: 0, y: 0, z: 0, s: 100)
x = [x.to_i, 0].max
y = [y.to_i, 0].max
z = z.to_i || 0
write { "G00 X#{x} Y#{y} Z#{z}" }
end
|
#move_relative(x: 0, y: 0, z: 0, s: 100) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/arduino/outgoing_handler.rb', line 18
def move_relative(x: 0, y: 0, z: 0, s: 100)
write do
x1 ||= [(bot.current_position.x + (x || 0)), 0].max
y1 ||= [(bot.current_position.y + (y || 0)), 0].max
z1 ||= (bot.current_position.z + (z || 0)) || 0
"G00 X#{x1} Y#{y1} Z#{z1}"
end
end
|
#read_parameter(num) ⇒ Object
Parameters are settings, which is not to be confused with status.
55
56
57
|
# File 'lib/arduino/outgoing_handler.rb', line 55
def read_parameter(num)
write { "F21 P#{num}" }
end
|
#read_pin(pin, mode = :digital) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/arduino/outgoing_handler.rb', line 59
def read_pin(pin, mode = :digital)
unless [:analog, :digital].include?(mode)
raise "Mode must be :analog or :digital"
end
write { "F42 P#{pin} M#{(mode == :digital) ? 0 : 1}" }
end
|
#read_status(num) ⇒ Object
66
67
68
|
# File 'lib/arduino/outgoing_handler.rb', line 66
def read_status(num)
write { "F31 P#{num}" }
end
|
#set_acceleration(axis, value) ⇒ Object
85
86
87
|
# File 'lib/arduino/outgoing_handler.rb', line 85
def set_acceleration(axis, value)
set_paramater_value(axis, value, 41, 42, 43)
end
|
#set_end_inversion(axis, value) ⇒ Object
98
99
100
|
# File 'lib/arduino/outgoing_handler.rb', line 98
def set_end_inversion(axis, value)
set_paramater_value(axis, bool_to_int(value), 21, 22, 23)
end
|
#set_max_speed(axis, value) ⇒ Object
81
82
83
|
# File 'lib/arduino/outgoing_handler.rb', line 81
def set_max_speed(axis, value)
set_paramater_value(axis, value, 71, 72, 73)
end
|
#set_motor_inversion(axis, value) ⇒ Object
102
103
104
|
# File 'lib/arduino/outgoing_handler.rb', line 102
def set_motor_inversion(axis, value)
set_paramater_value(axis, bool_to_int(value), 31, 32, 33)
end
|
#set_negative_coordinates(axis, value) ⇒ Object
106
107
108
|
# File 'lib/arduino/outgoing_handler.rb', line 106
def set_negative_coordinates(axis, value)
raise "Not yet implemented. TODO: This method."
end
|
#set_steps_per_mm(axis, value) ⇒ Object
93
94
95
96
|
# File 'lib/arduino/outgoing_handler.rb', line 93
def set_steps_per_mm(axis, value)
raise "The Farmbot Arduino does not currently store a value for steps "\
"per mm. Keep track of this information at the application level"
end
|
#set_timeout(axis, value) ⇒ Object
89
90
91
|
# File 'lib/arduino/outgoing_handler.rb', line 89
def set_timeout(axis, value)
set_paramater_value(axis, value, 11, 12, 13)
end
|
#wait(ms) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/arduino/outgoing_handler.rb', line 110
def wait(ms)
if (ms.is_a?(Integer))
write { "F44 P13 T#{ ms } M0 v1" }
else
raise BadNumericValue, "Expected sleep command to receive an integer."
end
end
|
#write_parameter(num, val) ⇒ Object
70
71
72
73
74
|
# File 'lib/arduino/outgoing_handler.rb', line 70
def write_parameter(num, val)
write { "F22 P#{num} V#{val}" }
key = Gcode::PARAMETER_DICTIONARY.fetch(num, "UNKNOWN_PARAMETER_#{num}")
bot.status.transaction { |i| i[key] = val }
end
|
#write_pin(pin:, value:, mode:) ⇒ Object
76
77
78
79
|
# File 'lib/arduino/outgoing_handler.rb', line 76
def write_pin(pin:, value:, mode:)
write { "F41 P#{pin} V#{value} M#{mode}" }
bot.status.set_pin(pin, value)
end
|