Ejemplo n.º 1
0
def test_different_calibration_unit():
    calibration = LinearCalibration(q.count / q.deg, 0 * q.deg)

    motor = DummyMotor(calibration)
    motor.position = 0 * q.deg
    motor.move(1 * q.deg).wait()
    assert motor.position == 1 * q.deg
Ejemplo n.º 2
0
def test_focusing():
    motor = Motor(hard_limits=(MIN_POSITION.magnitude,
                               MAX_POSITION.magnitude))
    motor.position = 85. * q.mm
    camera = BlurringCamera(motor)
    focus(camera, motor).wait()
    assert_almost_equal(motor.position, FOCUS_POSITION, 1e-2)
Ejemplo n.º 3
0
def test_different_calibration_unit():
    calibration = LinearCalibration(q.count / q.deg, 0 * q.deg)

    motor = DummyMotor(calibration)
    motor.position = 0 * q.deg
    motor.move(1 * q.deg).wait()
    assert motor.position == 1 * q.deg
Ejemplo n.º 4
0
class TestDummyMotor(unittest.TestCase):
    def setUp(self):
        self.motor = DummyMotor()
        self.handler = logbook.TestHandler()
        self.handler.push_application()

    def tearDown(self):
        self.handler.pop_application()

    def test_set_position(self):
        position = 1 * q.mm
        self.motor.position = position
        self.assertEqual(position, self.motor.position)

    def test_move(self):
        position = 1 * q.mm
        delta = 0.5 * q.mm
        self.motor.position = position
        self.motor.move(delta).wait()
        self.assertEqual(position + delta, self.motor.position)

    def test_log_output(self):
        self.motor.position = 0 * q.mm
        info = "Motor: try position='0.0 mm'"
        self.assertTrue(self.handler.has_info(info))

        self.motor.position = 2 * q.mm
        info = "Motor: try position='2.0 mm'"
        self.assertTrue(self.handler.has_info(info))
Ejemplo n.º 5
0
    def setUp(self):
        self.x_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.x_motor["position"].unit = q.deg
        self.y_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.y_motor["position"].unit = q.deg
        self.z_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.z_motor["position"].unit = q.deg

        # The bigger the image size, the more images we need to determine
        # the ellipse_center correctly.
        self.image_source = SimulationCamera(256, self.x_motor["position"],
                                             self.y_motor["position"],
                                             self.z_motor["position"])

        # A scanner which scans the rotation axis.
        self.scanner = Scanner(
            self.y_motor["position"], self.image_source.grab)
        self.scanner.minimum = 0*q.rad
        self.scanner.maximum = 2*np.pi*q.rad
        self.scanner.intervals = 50

        self.measure = Ellipse()

        # Allow 1 px misalignment in y-direction.
        self.eps = np.arctan(2.0/self.image_source.rotation_radius)*q.rad

        self.handler = logbook.TestHandler()
        self.handler.push_application()
Ejemplo n.º 6
0
class TestDummyMotor(TestCase):
    def setUp(self):
        super(TestDummyMotor, self).setUp()
        self.motor = DummyMotor()

    def test_set_position(self):
        position = 1 * q.mm
        self.motor.position = position
        self.assertEqual(position, self.motor.position)

    def test_move(self):
        position = 1 * q.mm
        delta = 0.5 * q.mm
        self.motor.position = position
        self.motor.move(delta).wait()
        self.assertEqual(position + delta, self.motor.position)
Ejemplo n.º 7
0
class TestDummyMotor(TestCase):

    def setUp(self):
        super(TestDummyMotor, self).setUp()
        self.motor = DummyMotor()

    def test_set_position(self):
        position = 1 * q.mm
        self.motor.position = position
        self.assertEqual(position, self.motor.position)

    def test_move(self):
        position = 1 * q.mm
        delta = 0.5 * q.mm
        self.motor.position = position
        self.motor.move(delta).wait()
        self.assertEqual(position + delta, self.motor.position)
    def setUp(self):
        self.x_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.x_motor["position"].unit = q.deg
        self.y_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.y_motor["position"].unit = q.deg
        self.z_motor = Motor(LinearCalibration(1 / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.z_motor["position"].unit = q.deg

        self.x_motor.position = 0 * q.deg
        self.z_motor.position = 0 * q.deg

        self.image_source = SimulationCamera(256, self.x_motor["position"],
                                             self.y_motor["position"],
                                             self.z_motor["position"])

        # A scanner which scans the rotation axis.
        self.scanner = Scanner(self.y_motor["position"],
                               self.image_source.grab)
        self.scanner.minimum = 0 * q.rad
        self.scanner.maximum = 2 * np.pi * q.rad
        self.scanner.intervals = 10

        dispatcher.subscribe(self.y_motor["position"],
                             self.y_motor["position"].CHANGED,
                             self.iteration_listener)
        self.aligner = Aligner(Ellipse(), self.scanner, self.x_motor,
                               self.z_motor)
        dispatcher.subscribe(self.aligner, self.aligner.AXIS_ALIGNED,
                             self.alignment_listener)

        self.iteration = 0
        self.max_iterations = 10

        # Alignment finishes after the aligner finishes or it iterates
        # too much, in which case the test fails.
        self.alignment_finished = Event()

        # Allow 1 px misalignment in y-direction.
        self.eps = np.arctan(2.0 / self.image_source.rotation_radius) * q.rad

        self.handler = logbook.TestHandler()
        self.handler.push_application()
Ejemplo n.º 9
0
 def setUp(self):
     super(TestOptimizers, self).setUp()
     self.algorithms = [optimization.halver, optimization.down_hill,
                        optimization.powell,
                        optimization.nonlinear_conjugate,
                        optimization.bfgs,
                        optimization.least_squares]
     self.center = 3.0 * q.mm
     self.motor = Motor(position=0 * q.count)
Ejemplo n.º 10
0
    def test_saving(self):
        m = Motor()
        param = m['position']

        param.set(1.0 * q.mm).wait()
        param.stash().wait()
        param.set(2.0 * q.mm).wait()
        param.set(0.02 * q.mm).wait()
        param.restore().wait()
        self.assertEqual(param.get().result(), 1.0 * q.mm)
Ejemplo n.º 11
0
    def setUp(self):
        super(TestDummyAlignment, self).setUp()
        calibration = LinearCalibration(q.count / q.deg, 0 * q.deg)
        hard_limits = (-np.Inf * q.count, np.Inf * q.count)
        self.x_motor = Motor(calibration=calibration, hard_limits=hard_limits)
        self.y_motor = Motor(calibration=calibration, hard_limits=hard_limits)
        self.z_motor = Motor(calibration=calibration, hard_limits=hard_limits)

        self.x_motor.position = 0 * q.deg
        self.z_motor.position = 0 * q.deg

        self.image_source = SimulationCamera(128, self.x_motor["position"],
                                             self.y_motor["position"],
                                             self.z_motor["position"])

        self.feedback = self.image_source.grab

        # Allow 1 px misalignment in y-direction.
        self.eps = np.arctan(2.0 / self.image_source.rotation_radius) * q.rad
Ejemplo n.º 12
0
    def setUp(self):
        super(TestRotationAxisMeasure, self).setUp()
        self.x_motor = Motor(LinearCalibration(q.count / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.x_motor["position"].unit = q.deg
        self.y_motor = Motor(LinearCalibration(q.count / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.y_motor["position"].unit = q.deg
        self.z_motor = Motor(LinearCalibration(q.count / q.deg, 0 * q.deg),
                             hard_limits=(-1e5, 1e5))
        self.z_motor["position"].unit = q.deg

        # The bigger the image size, the more images we need to determine
        # the center correctly.
        self.image_source = SimulationCamera(128, self.x_motor["position"],
                                             self.y_motor["position"],
                                             self.z_motor["position"])

        # Allow 1 px misalignment in y-direction.
        self.eps = np.arctan(2.0 / self.image_source.rotation_radius) * q.rad
Ejemplo n.º 13
0
 def setUp(self):
     super(TestDummyMotor, self).setUp()
     self.motor = DummyMotor()
Ejemplo n.º 14
0
    def test_saving(self):
        m = Motor()

        m.position = 1 * q.mm
        m.stash().wait()
        m.position = 2 * q.mm
        m.stash().wait()
        m.position = 0.123 * q.mm
        m.position = 1.234 * q.mm

        m.restore().wait()
        self.assertEqual(m.position, 2 * q.mm)

        m.restore().wait()
        self.assertEqual(m.position, 1 * q.mm)
Ejemplo n.º 15
0
 def setUp(self):
     super(TestDummyMotor, self).setUp()
     self.motor = DummyMotor()
Ejemplo n.º 16
0
 def setUp(self):
     self.motor = DummyMotor()
     self.handler = logbook.TestHandler()
     self.handler.push_application()