예제 #1
0
    def comment(self, description):
        def _do():
            pass

        def _setup():
            pass

        c = Command(do=_do, setup=_setup, description=description)
        self.add_command(c)
예제 #2
0
    def test_command(self):
        expected = ''

        def _setup():
            nonlocal expected
            expected = 'hello'

        def _do():
            nonlocal expected
            expected += ' world'

        description = 'hello world'
        command = Command(do=_do, setup=_setup, description=description)
        command()
        self.assertEquals(expected, command.description)
예제 #3
0
    def home(self, *args, **kwargs):
        """
        Home robot's head and plunger motors.

        Parameters
        ----------
        *args :
            A string with axes to home. For example ``'xyz'`` or ``'ab'``.

            If no arguments provided home Z-axis then X, Y, B, A

        enqueue : {True, False} Default: ``False``
            If ``True`` put into command queue,
            if ``False`` execute immediately.

        Notes
        -----
        Sometimes while executing a long protocol,
        a robot might accumulate precision
        error and it is recommended to home it. In this scenario, add
        ``robot.home('xyzab', enqueue=True)`` into your script.

        Examples
        --------
        >>> from opentrons import Robot
        >>> robot.connect('Virtual Smoothie')
        True
        >>> robot.home()
        True
        """
        def _do():
            if self._driver.calm_down():
                if args:
                    self._update_axis_homed(*args)
                    return self._driver.home(*args)
                else:
                    self._update_axis_homed('xyzab')
                    self._driver.home('z')
                    return self._driver.home('x', 'y', 'b', 'a')
            else:
                return False

        if kwargs.get('enqueue'):
            description = "Homing Robot"
            self.add_command(Command(do=_do, description=description))
        else:
            log.info('Executing: Home now')
            return _do()
예제 #4
0
    def create_command(self, do, setup=None, description=None, enqueue=True):
        """
        Creates an instance of Command to be appended to the
        :any:`Robot` run queue.

        Parameters
        ----------
        do : callable
            The method to execute on the robot. This usually includes
            moving an instrument's motors, or the robot head

        setup : callable
            The method to execute just before `do()`, which includes
            updating the instrument's state

        description : str
            Human-readable description of the action taking place

        enqueue : bool
            If set to `True` (default), the method will be appended
            to the robots list of commands for executing during
            :any:`run` or :any:`simulate`. If set to `False`, the
            method will skip the command queue and execute immediately

        Examples
        --------
        ..
        >>> instrument = Instrument()
        >>> def setup():
        >>>     print('hello')
        >>> def do():
        >>>     print(' world')
        >>> description = 'printing "hello world"'
        >>> instrument.create_command(do, setup, description)
        hello
        >>> robot.simulate()
        hello world
        >>> instrument.create_command(do, setup, description, enqueue=False)
        hello world
        """

        command = Command(do=do, setup=setup, description=description)

        if enqueue:
            Robot().add_command(command)
        else:
            command()
예제 #5
0
    def test_macro(self):
        expected = []

        macro = Macro('macro_test')

        for i in range(3):

            def _do():
                nonlocal expected
                expected.append('test')

            command = Command(do=_do)
            macro.add(command)

        macro.do()

        self.assertEquals(expected, ['test', 'test', 'test'])
예제 #6
0
    def move_to(self, location, instrument=None, strategy='arc', **kwargs):
        """
        Move an instrument to a coordinate, container or a coordinate within
        a container.

        Parameters
        ----------
        location : one of the following:
            1. :class:`Placeable` (i.e. Container, Deck, Slot, Well) — will
            move to the origin of a container.
            2. :class:`Vector` move to the given coordinate in Deck coordinate
            system.
            3. (:class:`Placeable`, :class:`Vector`) move to a given coordinate
            within object's coordinate system.

        instrument :
            Instrument to move relative to. If ``None``, move relative to the
            center of a gantry.

        strategy : {'arc', 'direct'}
            ``arc`` : move to the point using arc trajectory
            avoiding obstacles.

            ``direct`` : move to the point in a straight line.

        Examples
        --------
        >>> from opentrons import Robot
        >>> robot.reset() # doctest: +ELLIPSIS
        <opentrons.robot.robot.Robot object at ...>
        >>> robot.connect('Virtual Smoothie')
        True
        >>> robot.home()
        True
        >>> plate = robot.add_container('96-flat', 'A1', 'plate')
        >>> robot.move_to(plate[0])
        >>> robot.move_to(plate[0].top())
        """

        enqueue = kwargs.get('enqueue', False)
        # Adding this for backwards compatibility with old move_to(now=False)
        # convention.
        if 'now' in kwargs:
            enqueue = not kwargs.get('now')

        placeable, coordinates = containers.unpack_location(location)

        if instrument:
            coordinates = instrument.calibrator.convert(placeable, coordinates)
        else:
            coordinates += placeable.coordinates(placeable.get_deck())

        def _do():
            if strategy == 'arc':
                arc_coords = self._create_arc(coordinates, placeable)
                for coord in arc_coords:
                    self._driver.move_head(**coord)
            elif strategy == 'direct':
                self._driver.move_head(x=coordinates[0],
                                       y=coordinates[1],
                                       z=coordinates[2])
            else:
                raise RuntimeError(
                    'Unknown move strategy: {}'.format(strategy))

        if enqueue:
            _description = 'Moving to {}'.format(placeable)
            self.add_command(Command(do=_do, description=_description))
        else:
            _do()
예제 #7
0
 def commandable():
     self.add_command(Command(do=callback))