Skip to content

Commit

Permalink
feat(shared-data): add robot definitions (#11428)
Browse files Browse the repository at this point in the history
Add some quick and small json files that can represent kinds of robot,
primarily as a thing for other files to reference.

Closes RCORE-126
  • Loading branch information
sfoster1 authored Sep 6, 2022
1 parent 2f7b672 commit 7e3f1e6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 1 deletion.
8 changes: 8 additions & 0 deletions shared-data/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import type { INode } from 'svgson'
import type { RunTimeCommand } from '../protocol'
import type { PipetteName } from './pipettes'

export type RobotName = 'OT-2 Standard' | 'OT-3 Standard'

export interface RobotDefinition {
displayName: string
robotName: RobotName
models: string[]
}

// TODO Ian 2019-06-04 split this out into eg ../labware/flowTypes/labwareV1.js
export interface WellDefinition {
diameter?: number
Expand Down
25 changes: 25 additions & 0 deletions shared-data/python/opentrons_shared_data/robot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""opentrons_shared_data.robot: Submodule for handling robot definition data."""
from pathlib import Path
from typing import cast
from typing_extensions import Final

import json

from .. import get_shared_data_root

from .dev_types import RobotDefinition, RobotName

DEFAULT_ROBOT_DEFINITION_VERSION: Final = 1


def load(
robot_name: RobotName, version: int = DEFAULT_ROBOT_DEFINITION_VERSION
) -> RobotDefinition:
"""Load the definition for the specified robot id."""
for fi in Path(
get_shared_data_root() / "robot" / "definitions" / f"{version}"
).iterdir():
defn = json.load(fi.open("r"))
if defn["robotName"] == robot_name:
return cast(RobotDefinition, defn)
raise KeyError(robot_name)
17 changes: 17 additions & 0 deletions shared-data/python/opentrons_shared_data/robot/dev_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""opentrons_shared_data.robot.dev_types: types for robot def."""
from typing import NewType, List, Dict, Any
from typing_extensions import Literal, TypedDict

RobotSchemaVersion1 = Literal[1]

RobotSchema = NewType("RobotSchema", Dict[str, Any])

RobotName = Literal["OT-2 Standard", "OT-3 Standard"]


class RobotDefinition(TypedDict):
"""A python version of the robot definition type."""

displayName: str
robotName: RobotName
models: List[str]
2 changes: 1 addition & 1 deletion shared-data/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)

DATA_ROOT = ".."
DATA_SUBDIRS = ["deck", "labware", "module", "pipette", "protocol", "gripper"]
DATA_SUBDIRS = ["deck", "labware", "module", "pipette", "protocol", "gripper", "robot"]
DATA_TYPES = ["definitions", "schemas"]
DEST_BASE_PATH = "data"

Expand Down
Empty file.
20 changes: 20 additions & 0 deletions shared-data/python/tests/robot/test_typechecks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys

import pytest
import typeguard


from opentrons_shared_data.robot import load
from opentrons_shared_data.robot.dev_types import RobotDefinition, RobotName

pytestmark = pytest.mark.xfail(
condition=sys.version_info >= (3, 10),
reason="https://github.com/agronholm/typeguard/issues/242",
)


@pytest.mark.parametrize("defname", ["OT-2 Standard", "OT-3 Standard"])
def test_v1_defs(defname: RobotName) -> None:
defn = load(robot_name=defname, version=1)
typeguard.check_type("defn", defn, RobotDefinition)
assert defn["robotName"] == defname
5 changes: 5 additions & 0 deletions shared-data/robot/definitions/1/ot2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"displayName": "OT-2",
"robotName": "OT-2 Standard",
"models": ["OT-2 Standard", "OT-2 Refresh"]
}
5 changes: 5 additions & 0 deletions shared-data/robot/definitions/1/ot3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"displayName": "OT-3",
"robotName": "OT-3 Standard",
"models": ["OT-3 Standard"]
}
30 changes: 30 additions & 0 deletions shared-data/robot/schemas/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$id": "opentronsRobotSchemaV1",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"robotName": {
"type": "string",
"enum": ["OT-2 Standard", "OT-3 Standard"]
}
},
"description": "Describes an Opentrons liquid handling robot.",
"type": "object",
"required": ["displayName", "robotName", "models"],
"properties": {
"displayName": {
"description": "A user-facing friendly name for the machine.",
"type": "string"
},
"robotName": {
"description": "A machine-readable but still printable name for the machine.",
"type": "#/definitions/robotName"
},
"models": {
"description": "A list of robot models.",
"type": "array",
"items": {
"type": "string"
}
}
}
}

0 comments on commit 7e3f1e6

Please sign in to comment.