Class: RobotsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/robots_controller.rb

Overview

Handles robot validation The id parameter indicates which robot is being used The controller looks up the current settings in Setting.robots These settings are currently compiled from robots.rb Robot.find_robot generates a new robot based on the matching settings On each controller action a Robot is initialized based on the sett show => renders the form for the selected robot verify => Checks that the robot has been set up correctly, and returns any problems to the user start => Starts the robot, and transitions the plates to the configured states

Instance Method Summary collapse

Instance Method Details

#labware_created_with_robot(labware_barcode, robot_barcode) ⇒ Object

Updates labware metadata with robot barcode.

Parameters:

  • labware_barcode (String)

    the barcode of the labware on the bed

  • robot_barcode (String)

    the robot barcode scanned

Raises:

  • (Sequencescape::Api::ResourceNotFound)

    if the labware cannot be found



75
76
77
78
79
# File 'app/controllers/robots_controller.rb', line 75

def labware_created_with_robot(labware_barcode, robot_barcode)
  LabwareMetadata
    .new(api: api, user: current_user_uuid, barcode: labware_barcode)
    .update!(created_with_robot: robot_barcode)
end

#showObject



17
18
19
20
21
22
# File 'app/controllers/robots_controller.rb', line 17

def show
  respond_to do |format|
    format.html { render 'show', locals: { robot: @robot } }
    format.csv
  end
end

#startObject

rubocop:todo Metrics/AbcSize



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/robots_controller.rb', line 24

def start # rubocop:todo Metrics/AbcSize
  @robot.perform_transfer(stripped_beds)
  (params[:robot_barcode]) if params[:robot_barcode].present?
  respond_to { |format| format.html { redirect_to search_path, notice: "Robot #{@robot.name} has been started." } }
rescue Robots::Bed::BedError => e
  # Our beds complained, nothing has happened.
  respond_to do |format|
    format.html { redirect_to robot_path(id: @robot.id), notice: "#{e.message} No plates have been started." }
  end
end

#update_all_labware_metadata(robot_barcode) ⇒ Object

Saves the scanned robot barcode against all the target labware involved in this bed verification (using the ‘labware metadata’ model). Beds that are not involved in this bed verification (no ‘transitions’, and no labware scanned into them) are ignored.

Parameters:

  • robot_barcode (String)

    the robot barcode scanned

Raises:

  • (Sequencescape::Api::ResourceNotFound)

    if the labware cannot be found



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/robots_controller.rb', line 43

def (robot_barcode)
  @robot.beds.each_value do |bed|
    next unless bed.transitions? && bed.labware
    (bed, robot_barcode)
  rescue Sequencescape::Api::ResourceNotFound
    labware_barcode = bed.labware.barcode.machine
    respond_to do |format|
      format.html { redirect_to robot_path(id: @robot.id), notice: "Labware #{labware_barcode} not found." }
    end
  end
end

#update_bed_labware_metadata(bed, robot_barcode) ⇒ Object

Saves the scanned robot barcode against the labware scanned into this bed (using the ‘labware metadata’ model). If the bed has its own method for updating, use that, otherwise use the method of this controller.

Parameters:

  • labware_barcode (String)

    the barcode of the labware on the bed

  • robot_barcode (String)

    the robot barcode scanned

Raises:

  • (Sequencescape::Api::ResourceNotFound)

    if the labware cannot be found



63
64
65
66
67
# File 'app/controllers/robots_controller.rb', line 63

def (bed, robot_barcode)
  return bed.labware_created_with_robot(robot_barcode) if bed.respond_to?(:labware_created_with_robot)
  labware_barcode = bed.labware.barcode.machine
  labware_created_with_robot(labware_barcode, robot_barcode)
end

#verifyObject



81
82
83
84
85
86
# File 'app/controllers/robots_controller.rb', line 81

def verify
  # ActionController::Parameters is no longer a Hash. Ensure the robot params
  # is Hash and pass only the permitted params to the robot.
  params = robot_params.to_h
  render(json: @robot.verify(params))
end