Skip to content

Commit

Permalink
Offset for homing parameters can now be set to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Mar 25, 2022
1 parent bd4fc9f commit b05b6c9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions instruments/tests/test_thorlabs/test_thorlabs_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,64 @@ def test_apt_mc_home_parameters_set_with_none(init_kdc101):
apt.channel[0].home_parameters = None, None, None, None


def test_apt_mc_home_parameters_set_offset_to_zero(init_kdc101):
"""Ensure setting offset to zero is not interpreted as `None`."""
home_direction = 1
limit_switch = 1
velocity = 1000
offset = 1250
offset_new = 0
with expected_protocol(
ik.thorlabs.APTMotorController,
[
init_kdc101[0],
ThorLabsPacket(
message_id=ThorLabsCommands.MOT_REQ_HOMEPARAMS,
param1=0x01,
param2=0x00,
dest=0x50,
source=0x01,
data=None,
).pack(),
ThorLabsPacket(
message_id=ThorLabsCommands.MOT_SET_HOMEPARAMS,
param1=None,
param2=None,
dest=0x50,
source=0x01,
data=struct.pack(
"<HHHll",
0x01,
home_direction,
limit_switch,
velocity,
offset_new,
),
).pack(),
],
[
init_kdc101[1],
ThorLabsPacket(
message_id=ThorLabsCommands.MOT_GET_HOMEPARAMS,
param1=None,
param2=None,
dest=0x50,
source=0x01,
data=struct.pack(
"<HHHll",
0x01,
home_direction,
limit_switch,
velocity,
offset,
),
).pack(),
],
sep="",
) as apt:
apt.channel[0].home_parameters = None, None, None, offset_new


def test_apt_mc_home_parameters(init_kdc101):
"""Get / set home_parameters in unitful fashion."""
home_direction = 1
Expand Down
2 changes: 1 addition & 1 deletion instruments/thorlabs/thorlabsapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ def home_parameters(self, values):
# replace values that are `None`
if None in values:
set_params = self.home_parameters
values = [x if x else y for x, y in zip(values, set_params)]
values = [x if x is not None else y for x, y in zip(values, set_params)]

home_dir, lim_sw, velocity, offset = values
if isinstance(velocity, u.Quantity):
Expand Down

0 comments on commit b05b6c9

Please sign in to comment.