class Artoo::Master

The Artoo::Master class is a registered supervisor class to keep track of all the running robots

Attributes

robots[R]

Public Class Methods

add_command(name, behaviour) click to toggle source
# File lib/artoo/master.rb, line 49
def add_command(name, behaviour)
  current.add_command(name, behaviour)
end
assign(bots=[]) click to toggle source
# File lib/artoo/master.rb, line 13
def assign(bots=[])
  current.assign(bots)
end
command(name, params) click to toggle source
# File lib/artoo/master.rb, line 45
def command(name, params)
  current.command(name, params)
end
commands() click to toggle source
# File lib/artoo/master.rb, line 53
def commands
  current.commands
end
continue_work() click to toggle source
# File lib/artoo/master.rb, line 41
def continue_work
  current.continue_work
end
current() click to toggle source
# File lib/artoo/master.rb, line 9
def current
  Celluloid::Actor[:master] ||= self.new
end
new(bots=[]) click to toggle source

Create new master @param [Collection] robots

# File lib/artoo/master.rb, line 61
def initialize(bots=[])
  @robots = []
  @commands = []
  assign(bots)
end
pause_work() click to toggle source
# File lib/artoo/master.rb, line 37
def pause_work
  current.pause_work
end
robot(name) click to toggle source
# File lib/artoo/master.rb, line 21
def robot(name)
  current.robot(name)
end
robot?(name) click to toggle source
# File lib/artoo/master.rb, line 25
def robot?(name)
  current.robot?(name)
end
robots() click to toggle source
# File lib/artoo/master.rb, line 17
def robots
  current.robots
end
start_work() click to toggle source
# File lib/artoo/master.rb, line 29
def start_work
  current.start_work
end
stop_work() click to toggle source
# File lib/artoo/master.rb, line 33
def stop_work
  current.stop_work
end

Public Instance Methods

add_command(name, behaviour) click to toggle source

add command to master

# File lib/artoo/master.rb, line 153
def add_command(name, behaviour)
  @commands << { name: name.to_sym, behaviour: behaviour }
end
assign(bots=[]) click to toggle source

Assign robots to Master controller @param [Collection] robots

# File lib/artoo/master.rb, line 69
def assign(bots=[])
  robots.concat(bots)
  bots.each {|r| r.async.work} if Artoo::Robot.is_running?
end
command(name, params) click to toggle source

execute master command

# File lib/artoo/master.rb, line 141
def command(name, params)
  command = @commands.find{ |c| c[:name] == name.to_sym }
  if command
    if params.nil?
      command[:behaviour].call
    else
      command[:behaviour].call(params)
    end
  end
end
commands() click to toggle source

return list of master command names

# File lib/artoo/master.rb, line 136
def commands
  @commands.map{ |c| c[:name] }
end
continue_work() click to toggle source

Continue work for each robot

# File lib/artoo/master.rb, line 125
def continue_work
  robots.each {|r| r.async.continue_work}
end
pause_work() click to toggle source

Pause work for each robot

# File lib/artoo/master.rb, line 117
def pause_work
  robots.each {|r|
    Logger.info "pausing #{r.name}"
    r.async.pause_work
  }
end
robot(name) click to toggle source

@param [String] name @return [Robot] robot

# File lib/artoo/master.rb, line 76
def robot(name)
  robots.find {|r| r.name == name}
end
robot?(name) click to toggle source
# File lib/artoo/master.rb, line 80
def robot?(name)
  robots.find {|r| r.name == name}
end
robot_connection(robot_id, connection_id) click to toggle source

@param [String] robot_id @param [String] connection_id @return [Device] robot connection

# File lib/artoo/master.rb, line 106
def robot_connection(robot_id, connection_id)
  robot_connections(robot_id)[connection_id.intern]
end
robot_connections(name) click to toggle source

@param [String] name @return [Collection] robot connections

# File lib/artoo/master.rb, line 99
def robot_connections(name)
  robot(name).connections
end
robot_device(name, device_id) click to toggle source

@param [String] name @param [String] device_id @return [Device] robot device

# File lib/artoo/master.rb, line 93
def robot_device(name, device_id)
  robot_devices(name)[device_id.intern]
end
robot_devices(name) click to toggle source

@param [String] name @return [Collection] robot devices

# File lib/artoo/master.rb, line 86
def robot_devices(name)
  robot(name).devices
end
start_work() click to toggle source

Do asynchronous work for each robot

# File lib/artoo/master.rb, line 111
def start_work
  robots.each {|r| r.async.work} unless Artoo::Robot.is_running?
  Artoo::Robot.running!
end
stop_work() click to toggle source

terminate all robots

# File lib/artoo/master.rb, line 130
def stop_work
  robots.each {|r| r.terminate} unless !Artoo::Robot.is_running?
  Artoo::Robot.stopped!
end