Class: FB::OutgoingHandler
- Inherits:
-
Object
- Object
- FB::OutgoingHandler
- Defined in:
- lib/arduino/outgoing_handler.rb
Overview
Responsible for writing to the serial line. Sends Gcode from the pi to the arduino. (Pi -> Arduino)
Defined Under Namespace
Classes: UnhandledGcode
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
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
- #pin_write(pin:, value:, mode:) ⇒ Object
- #read_parameter(num) ⇒ Object
- #read_status(pin) ⇒ Object
- #write_parameter(num, val) ⇒ Object
Constructor Details
#initialize(bot) ⇒ OutgoingHandler
Returns a new instance of OutgoingHandler.
9 10 11 |
# File 'lib/arduino/outgoing_handler.rb', line 9 def initialize(bot) @bot = bot end |
Instance Attribute Details
#bot ⇒ Object (readonly)
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
13 14 15 16 17 18 |
# File 'lib/arduino/outgoing_handler.rb', line 13 def emergency_stop(*) # This message is special- it is the only method that bypasses the queue. bot.outbound_queue = [] # Dump pending commands. bot.serial_port.puts "E" # Don't queue this one- write to serial line. bot.status[:last] = :emergency_stop end |
#home_all ⇒ Object
44 45 46 |
# File 'lib/arduino/outgoing_handler.rb', line 44 def home_all write "G28" end |
#home_x ⇒ Object
32 33 34 |
# File 'lib/arduino/outgoing_handler.rb', line 32 def home_x write "F11" end |
#home_y ⇒ Object
36 37 38 |
# File 'lib/arduino/outgoing_handler.rb', line 36 def home_y write "F12" end |
#home_z ⇒ Object
40 41 42 |
# File 'lib/arduino/outgoing_handler.rb', line 40 def home_z write "F13" end |
#move_absolute(x: 0, y: 0, z: 0, s: 100) ⇒ Object
28 29 30 |
# File 'lib/arduino/outgoing_handler.rb', line 28 def move_absolute(x: 0, y: 0, z: 0, s: 100) write "G00 X#{x} Y#{y} Z#{z}" end |
#move_relative(x: 0, y: 0, z: 0, s: 100) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/arduino/outgoing_handler.rb', line 20 def move_relative(x: 0, y: 0, z: 0, s: 100) x = [(bot.current_position.x + (x || 0)), 0].max y = [(bot.current_position.y + (y || 0)), 0].max z = [(bot.current_position.z + (z || 0)), 0].max write { FB::Gcode.new { "G00 X#{x} Y#{y} Z#{z}" } } end |
#pin_write(pin:, value:, mode:) ⇒ Object
60 61 62 63 |
# File 'lib/arduino/outgoing_handler.rb', line 60 def pin_write(pin:, value:, mode:) write "F41 P#{pin} V#{value} M#{mode}" bot.status.set_pin(pin, value) end |
#read_parameter(num) ⇒ Object
48 49 50 |
# File 'lib/arduino/outgoing_handler.rb', line 48 def read_parameter(num) write "F21 P#{num}" end |
#read_status(pin) ⇒ Object
56 57 58 |
# File 'lib/arduino/outgoing_handler.rb', line 56 def read_status(pin) write "F31 P#{pin}" end |
#write_parameter(num, val) ⇒ Object
52 53 54 |
# File 'lib/arduino/outgoing_handler.rb', line 52 def write_parameter(num, val) write "F22 P#{num} V#{val}" end |