Beispiel #1
0
def _prepare_for_dict(key, value):
    """Convert an element in SimulatorSetup to be a serializable dict"""
    if key == 'attached_instruments' and value:
        return {mount.name.lower(): data for (mount, data) in value.items()}
    if key == 'config' and value:
        return robot_configs.config_to_save(value)[1]
    return value
Beispiel #2
0
def test_dictify_roundtrip():
    new_settings = copy.deepcopy(dummy_settings)
    new_settings['tip_probe']['dimensions']\
        = robot_configs._default_probe_dimensions()
    new_settings['tip_probe']['center']\
        = robot_configs._default_probe_center()
    built_config = robot_configs.build_config(dummy_cal, dummy_settings)
    new_cal, new_config = robot_configs.config_to_save(built_config)
    assert new_cal == dummy_cal
    assert new_config == new_settings
    new_config = robot_configs.build_config(new_cal, new_config)
    assert new_config == built_config
def test_update_instrument_config(fixture):
    from opentrons.trackers.pose_tracker import change_base
    from numpy import array
    import json

    robot = fixture.robot
    inst = fixture.instrument

    inst_offset = robot.config.instrument_offset[inst.mount][inst.type]

    cfg = update_instrument_config(instrument=inst,
                                   measured_center=(0.0, 0.0, 105.0))

    new_tip_length = cfg.tip_length[inst.name]
    new_instrument_offset = cfg.instrument_offset[inst.mount][inst.type]

    assert new_tip_length == 55.0
    assert new_instrument_offset == tuple(array(inst_offset) + (5.0, 5.0, 0.0))
    assert tuple(change_base(
        robot.poses,
        src=inst,
        dst=inst.instrument_mover)) == (5.0, 5.0, 0), \
        "Expected instrument position to update relative to mover in pose tree"

    filename = CONFIG['robot_settings_file']
    _, expected = robot_configs.config_to_save(
        robot_configs.build_config([[]], {}))
    expected['instrument_offset']['right']['single'] = [5.0, 5.0, 0.0]
    expected['tip_length']['Pipette'] = 55.0

    with open(filename, 'r') as file:
        actual = json.load(file)

    # from pprint import pprint
    # print('=------> <------=')
    # print("Expected:")
    # pprint(expected)
    # print()
    # print("Actual:")
    # pprint(actual)
    # print()
    assert actual == expected
Beispiel #4
0
    },
           deserializer=lambda json_dict: {
               top_types.Mount[mount_name.upper()]: pipette_info
               for mount_name, pipette_info in json_dict.items()
           }),
    Dict[types.Axis, bool]:
    SerDes(
        serializer=lambda axisdict:
        {ax.name: engaged
         for ax, engaged in axisdict.items()},
        deserializer=lambda namedict:
        {types.Axis[ax.upper()]: engaged
         for ax, engaged in namedict.items()}),
    robot_configs.robot_config:
    SerDes(
        serializer=lambda config: list(robot_configs.config_to_save(config)),
        deserializer=lambda clist: robot_configs.build_config(*clist)),
    List[types.Axis]:
    SerDes(
        serializer=lambda axlist: [ax.name for ax in axlist],
        deserializer=lambda namelist: [types.Axis[name] for name in namelist]),
}


def _build_serializable_method(method_name, method):  # noqa(C901)
    """ Build the method to actually server over jsonrpc.

    To serve over jsonrpc, we need to have an interface that is fully
    json-serializable. Since serving over jsonrpc is a secondary task of the
    hardware controller, we don't want to make all the hc methods json
    serializable because that would take away from the readability of rich
Beispiel #5
0
    (Mount, Mount.LEFT, 'LEFT'),
    (Axis, Axis.A, 'A'),
    (CriticalPoint, CriticalPoint.NOZZLE, 'NOZZLE'),
    (Point, Point(1, 2, 3), [1, 2, 3]),
    (Dict[Mount, str], {
        Mount.LEFT: 'way hay'
    }, {
        'LEFT': 'way hay'
    }),
    (Dict[Axis, bool], {
        Axis.X: True
    }, {
        'X': True
    }),
    (robot_configs.robot_config, robot_configs.load(),
     list(robot_configs.config_to_save(robot_configs.load()))),
    (Dict[Mount, Pipette.DictType], {
        Mount.LEFT: {
            'asdasd': 2,
            'asda': False
        }
    }, {
        'LEFT': {
            'asdasd': 2,
            'asda': False
        }
    }),
    (List[Axis], [Axis.X, Axis.A], ['X', 'A']),
    (Optional[CriticalPoint], None, None),
    (Optional[CriticalPoint], CriticalPoint.NOZZLE, 'NOZZLE'),
])