Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 14c759ff89a8
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c2831db253c3
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 4, 2015

  1. Copy the full SHA
    5b8691f View commit details
  2. thorlabs_tcube: add unit tests

    fallen authored and sbourdeauducq committed Mar 4, 2015
    Copy the full SHA
    bc19d6f View commit details
  3. thorlabs_tcube: driver PEP8 fix

    fallen authored and sbourdeauducq committed Mar 4, 2015
    Copy the full SHA
    5091098 View commit details
  4. Copy the full SHA
    c2831db View commit details
Showing with 169 additions and 5 deletions.
  1. +5 −5 artiq/devices/thorlabs_tcube/driver.py
  2. +164 −0 artiq/test/thorlabs_tcube.py
10 changes: 5 additions & 5 deletions artiq/devices/thorlabs_tcube/driver.py
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ def ping(self):
class Tpz(Tcube):
def __init__(self, serial_dev):
Tcube.__init__(self, serial_dev)
self.voltage_limit = self.get_tpz_iosettings()[0].amount
self.voltage_limit = self.get_tpz_io_settings()[0].amount

def handle_message(self, msg):
msg_id = msg.id
@@ -1150,7 +1150,7 @@ def move_stop(self, stop_mode, async=False):
MGMSG.MOT_MOVE_STOPPED, 1, stop_mode)

def set_dc_pid_parameters(self, proportional, integral, differential,
integral_limit, filter_control=0x0F):
integral_limit, filter_control=0x0F):
"""Set the position control loop parameters.
:param proportional: The proportional gain, values in range [0; 32767].
@@ -1325,7 +1325,7 @@ def set_position_control_mode(self, control_mode):
def get_position_control_mode(self):
return self.control_mode

def set_outputvolts(self, voltage):
def set_output_volts(self, voltage):
self.voltage = voltage

def get_output_volts(self):
@@ -1536,10 +1536,10 @@ def set_eeprom_parameters(self, msg_id):
pass

def get_dc_status_update(self):
return None # FIXME: not implemented yet for simulation
return 0, 0, 0x80000400 # FIXME: not implemented yet for simulation

def get_status_bits(self):
return None # FIXME: not implemented yet for simulation
return 0x80000400 # FIXME: not implemented yet for simulation

def suspend_end_of_move_messages(self):
pass
164 changes: 164 additions & 0 deletions artiq/test/thorlabs_tcube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import unittest
import os
import time

from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
from artiq.language.units import V

no_hardware = bool(os.getenv("ARTIQ_NO_HARDWARE"))


class GenericTdcTest(unittest.TestCase):
def test_pot_parameters(self):
test_vector = 1, 2, 3, 4, 5, 6, 7, 8
self.cont.set_pot_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_pot_parameters())

def test_position_counter(self):
test_vector = 42
self.cont.set_position_counter(test_vector)
self.assertEqual(test_vector, self.cont.get_position_counter())

def test_encoder_counter(self):
test_vector = 43
self.cont.set_encoder_counter(test_vector)
self.assertEqual(test_vector, self.cont.get_encoder_counter())

def test_velocity_parameters(self):
test_vector = 44, 45
self.cont.set_velocity_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_velocity_parameters())

def test_jog_parameters(self):
test_vector = 46, 47, 48, 49, 50
self.cont.set_jog_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_jog_parameters())

def test_gen_move_parameters(self):
test_vector = 51
self.cont.set_gen_move_parameters(test_vector)
self.assertEqual(test_vector, self.cont.get_gen_move_parameters())

def test_moverelparams(self):
test_vector = 52
self.cont.set_move_relative_parameters(test_vector)
self.assertEqual(test_vector, self.cont.get_move_relative_parameters())

def test_move_absolute_parameters(self):
test_vector = 53
self.cont.set_move_absolute_parameters(test_vector)
self.assertEqual(test_vector, self.cont.get_move_absolute_parameters())

def test_home_parameters(self):
test_vector = 54
self.cont.set_home_parameters(test_vector)
self.assertEqual(test_vector, self.cont.get_home_parameters())

def test_limit_switch_parameters(self):
test_vector = 2, 1
self.cont.set_limit_switch_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_limit_switch_parameters())

def test_dc_pid_parameters(self):
test_vector = 57, 58, 59, 60, 0x0f
self.cont.set_dc_pid_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_dc_pid_parameters())

def test_av_modes(self):
for i in range(1):
for j in range(1):
for k in range(1):
with self.subTest(i=i):
with self.subTest(j=j):
with self.subTest(k=k):
test_vector = i << 2 + j << 1 + k
self.cont.set_av_modes(test_vector)
self.assertEqual(test_vector,
self.cont.get_av_modes())

def test_button_parameters(self):
test_vector = 2, 3, 4
self.cont.set_button_parameters(*test_vector)
self.assertEqual(test_vector, self.cont.get_button_parameters())


class GenericTpzTest(unittest.TestCase):
def test_position_control_mode(self):
test_vector = 1
self.cont.set_position_control_mode(test_vector)
self.assertEqual(test_vector, self.cont.get_position_control_mode())

def test_ouput_volts(self):

for voltage in 5*V, 10*V, 15*V, \
round(self.cont.get_tpz_io_settings()[0].amount)*V:
with self.subTest(voltage=voltage):
test_vector = voltage
self.cont.set_output_volts(test_vector)
time.sleep(1) # Wait for the output voltage to converge
self.assertAlmostEqual(test_vector,
self.cont.get_output_volts(),
delta=0.03*V)

def test_output_position(self):
test_vector = 31000
self.cont.set_output_position(test_vector)
self.assertEqual(test_vector, self.cont.get_output_position())

def test_input_volts_source(self):
for i in range(3):
test_vector = i
self.cont.set_input_volts_source(i)
with self.subTest(i=i):
self.assertEqual(test_vector,
self.cont.get_input_volts_source())

def test_pi_constants(self):
test_vector = 42, 43
self.cont.set_pi_constants(*test_vector)
self.assertEqual(test_vector, self.cont.get_pi_constants())

def test_tpz_display_settings(self):
for intensity in 0, 10, 30, 50, 100, 150, 254:
with self.subTest(intensity=intensity):
test_vector = intensity
self.cont.set_tpz_display_settings(test_vector)
self.assertEqual(test_vector,
self.cont.get_tpz_display_settings())

def test_tpz_io_settings(self):
for v in 75*V, 100*V, 150*V:
with self.subTest(v=v):
test_vector = v, 1
self.cont.set_tpz_io_settings(*test_vector)
self.assertEqual(test_vector, self.cont.get_tpz_io_settings())


@unittest.skipIf(no_hardware, "no hardware")
class TestTdc(GenericTdcTest):
def setUp(self):
serial = os.getenv("ARTIQ_TDC001_SERIAL")
args = dict()
if serial is not None:
args["serial_dev"] = serial
self.cont = Tdc(**args)


class TestTdcSim(GenericTdcTest):
def setUp(self):
self.cont = TdcSim()


@unittest.skipIf(no_hardware, "no hardware")
class TestTpz(GenericTpzTest):
def setUp(self):
serial = os.getenv("ARTIQ_TPZ001_SERIAL")
args = dict()
if serial is not None:
args["serial_dev"] = serial
self.cont = Tpz(**args)


class TestTpzSim(GenericTpzTest):
def setUp(self):
self.cont = TpzSim()