Class: Artoo::Adaptors::Roomba

Inherits:
Adaptor
  • Object
show all
Defined in:
lib/artoo/adaptors/roomba.rb

Overview

Connect to a Roomba

See Also:

Instance Attribute Summary collapse

Attributes inherited from Adaptor

#parent, #port

Instance Method Summary collapse

Methods inherited from Adaptor

#connect_to, #connect_to_serial, #connect_to_tcp, #connect_to_udp, #connected?, #initialize, #reconnect

Constructor Details

This class inherits a constructor from Artoo::Adaptors::Adaptor

Instance Attribute Details

#spObject (readonly)

Returns the value of attribute sp.



9
10
11
# File 'lib/artoo/adaptors/roomba.rb', line 9

def sp
  @sp
end

Instance Method Details

#connectBoolean

Creates serial or tcp connection

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
# File 'lib/artoo/adaptors/roomba.rb', line 21

def connect
  if port.is_serial?
    @sp = connect_to_serial
    @sp.dtr = 0
    @sp.rts = 0
  else
    @sp = connect_to_tcp
  end
  super
end

#disconnectBoolean

Closes connection to device

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/artoo/adaptors/roomba.rb', line 44

def disconnect
  @sp.close
  super
end

#finalizeBoolean

Closes connection if already connected

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/artoo/adaptors/roomba.rb', line 13

def finalize
  if connected?
    @sp.close
  end
end

#send_bytes(bytes) ⇒ Object

Send bytes to device



33
34
35
36
37
38
39
40
# File 'lib/artoo/adaptors/roomba.rb', line 33

def send_bytes(bytes)
  bytes = [bytes] unless bytes.respond_to?(:map)
  bytes.map!(&:chr)
  Logger.debug "sending: #{bytes.inspect}"
  res = []
  bytes.each{|b| res << @sp.write(b) }
  Logger.debug "returned: #{res.inspect}"
end