Skip to content

Commit 4d077f5

Browse files
committedJun 18, 2015
thorlabs tdc driver: all moves are now blocking and wait for move to end or be stopped
1 parent b059720 commit 4d077f5

File tree

1 file changed

+56
-53
lines changed

1 file changed

+56
-53
lines changed
 

Diff for: ‎artiq/devices/thorlabs_tcube/driver.py

+56-53
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ def send(self, msg):
221221
def handle_message(self, msg):
222222
pass
223223

224-
def send_request(self, msgreq_id, msgget_id, param1=0, param2=0):
225-
Message(msgreq_id, param1, param2).send(self.port)
224+
def send_request(self, msgreq_id, wait_for_msgs, param1=0, param2=0, data=None):
225+
Message(msgreq_id, param1, param2, data=data).send(self.port)
226226
msg = msg_id = None
227-
while msg is None or msg_id != msgget_id:
227+
while msg is None or msg_id not in wait_for_msgs:
228228
msg = Message.recv(self.port)
229229
self.handle_message(msg)
230230
msg_id = msg.id
@@ -247,7 +247,7 @@ def set_channel_enable_state(self, activated):
247247

248248
def get_channel_enable_state(self):
249249
get_msg = self.send_request(MGMSG.MOD_REQ_CHANENABLESTATE,
250-
MGMSG.MOD_GET_CHANENABLESTATE, 1)
250+
[MGMSG.MOD_GET_CHANENABLESTATE], 1)
251251
self.chan_enabled = get_msg.param2
252252
if self.chan_enabled == 1:
253253
self.chan_enabled = True
@@ -286,7 +286,7 @@ def hardware_stop_update_messages(self):
286286

287287
def hardware_request_information(self):
288288
return self.send_request(MGMSG.HW_REQ_INFO,
289-
MGMSG.HW_GET_INFO)
289+
[MGMSG.HW_GET_INFO])
290290

291291
def is_channel_enabled(self):
292292
return self.chan_enabled
@@ -355,7 +355,7 @@ def get_position_control_mode(self):
355355
"""
356356

357357
get_msg = self.send_request(MGMSG.PZ_REQ_POSCONTROLMODE,
358-
MGMSG.PZ_GET_POSCONTROLMODE, 1)
358+
[MGMSG.PZ_GET_POSCONTROLMODE], 1)
359359
return get_msg.param2
360360

361361
def set_output_volts(self, voltage):
@@ -389,7 +389,7 @@ def get_output_volts(self):
389389
"""
390390

391391
get_msg = self.send_request(MGMSG.PZ_REQ_OUTPUTVOLTS,
392-
MGMSG.PZ_GET_OUTPUTVOLTS, 1)
392+
[MGMSG.PZ_GET_OUTPUTVOLTS], 1)
393393
return st.unpack("<H", get_msg.data[2:])[0]*self.voltage_limit*V/32767
394394

395395
def set_output_position(self, position_sw):
@@ -417,7 +417,7 @@ def get_output_position(self):
417417
"""
418418

419419
get_msg = self.send_request(MGMSG.PZ_REQ_OUTPUTPOS,
420-
MGMSG.PZ_GET_OUTPUTPOS, 1)
420+
[MGMSG.PZ_GET_OUTPUTPOS], 1)
421421
return st.unpack("<H", get_msg.data[2:])[0]
422422

423423
def set_input_volts_source(self, volt_src):
@@ -459,7 +459,7 @@ def get_input_volts_source(self):
459459
"""
460460

461461
get_msg = self.send_request(MGMSG.PZ_REQ_INPUTVOLTSSRC,
462-
MGMSG.PZ_GET_INPUTVOLTSSRC, 1)
462+
[MGMSG.PZ_GET_INPUTVOLTSSRC], 1)
463463
return st.unpack("<H", get_msg.data[2:])[0]
464464

465465
def set_pi_constants(self, prop_const, int_const):
@@ -488,7 +488,7 @@ def get_pi_constants(self):
488488
"""
489489

490490
get_msg = self.send_request(MGMSG.PZ_REQ_PICONSTS,
491-
MGMSG.PZ_GET_PICONSTS, 1)
491+
[MGMSG.PZ_GET_PICONSTS], 1)
492492
return st.unpack("<HH", get_msg.data[2:])
493493

494494
def set_output_lut(self, lut_index, output):
@@ -546,7 +546,7 @@ def get_output_lut(self):
546546
"""
547547

548548
get_msg = self.send_request(MGMSG.PZ_REQ_OUTPUTLUT,
549-
MGMSG.PZ_GET_OUTPUTLUT, 1)
549+
[MGMSG.PZ_GET_OUTPUTLUT], 1)
550550
(index, output) = st.unpack("<Hh", get_msg.data[2:])
551551
return index, output*self.voltage_limit*V/32767
552552

@@ -626,7 +626,7 @@ def get_output_lut_parameters(self):
626626
"""
627627

628628
get_msg = self.send_request(MGMSG.PZ_REQ_OUTPUTLUTPARAMS,
629-
MGMSG.PZ_GET_OUTPUTLUTPARAMS, 1)
629+
[MGMSG.PZ_GET_OUTPUTLUTPARAMS], 1)
630630
return st.unpack("<HHLLLL", get_msg.data[2:22])
631631

632632
def start_lut_output(self):
@@ -669,7 +669,7 @@ def get_tpz_display_settings(self):
669669
"""
670670

671671
get_msg = self.send_request(MGMSG.PZ_REQ_TPZ_DISPSETTINGS,
672-
MGMSG.PZ_GET_TPZ_DISPSETTINGS, 1)
672+
[MGMSG.PZ_GET_TPZ_DISPSETTINGS], 1)
673673
return st.unpack("<H", get_msg.data)[0]
674674

675675
def set_tpz_io_settings(self, voltage_limit, hub_analog_input):
@@ -731,7 +731,7 @@ def get_tpz_io_settings(self):
731731
"""
732732

733733
get_msg = self.send_request(MGMSG.PZ_REQ_TPZ_IOSETTINGS,
734-
MGMSG.PZ_GET_TPZ_IOSETTINGS, 1)
734+
[MGMSG.PZ_GET_TPZ_IOSETTINGS], 1)
735735
voltage_limit, hub_analog_input = st.unpack("<HH", get_msg.data[2:6])
736736
if voltage_limit == 1:
737737
voltage_limit = 75*V
@@ -763,8 +763,6 @@ def handle_message(self, msg):
763763
raise MsgError("Hardware error {}: {}"
764764
.format(code,
765765
data[4:].decode(encoding="ascii")))
766-
elif msg_id == MGMSG.MOT_MOVE_HOMED:
767-
pass
768766
elif (msg_id == MGMSG.MOT_MOVE_COMPLETED or
769767
msg_id == MGMSG.MOT_MOVE_STOPPED or
770768
msg_id == MGMSG.MOT_GET_DCSTATUSUPDATE):
@@ -777,6 +775,10 @@ def handle_message(self, msg):
777775
(self.position, self.velocity, r, self.status) = st.unpack(
778776
"<LHHL", data[2:])
779777

778+
def is_moving(self):
779+
status_bits = self.get_status_bits()
780+
return (status_bits & 0x2F0) != 0
781+
780782
def set_pot_parameters(self, zero_wnd, vel1, wnd1, vel2, wnd2, vel3,
781783
wnd3, vel4):
782784
"""Set pot parameters.
@@ -811,12 +813,12 @@ def get_pot_parameters(self):
811813
"""
812814

813815
get_msg = self.send_request(MGMSG.MOT_REQ_POTPARAMS,
814-
MGMSG.MOT_GET_POTPARAMS, 1)
816+
[MGMSG.MOT_GET_POTPARAMS], 1)
815817
return st.unpack("<HLHLHLHL", get_msg.data[2:])
816818

817819
def hub_get_bay_used(self):
818820
get_msg = self.send_request(MGMSG.HUB_REQ_BAYUSED,
819-
MGMSG.HUB_GET_BAYUSED)
821+
[MGMSG.HUB_GET_BAYUSED])
820822
return get_msg.param1
821823

822824
def set_position_counter(self, position):
@@ -841,7 +843,7 @@ def get_position_counter(self):
841843
"""
842844

843845
get_msg = self.send_request(MGMSG.MOT_REQ_POSCOUNTER,
844-
MGMSG.MOT_GET_POSCOUNTER, 1)
846+
[MGMSG.MOT_GET_POSCOUNTER], 1)
845847
return st.unpack("<l", get_msg.data[2:])[0]
846848

847849
def set_encoder_counter(self, encoder_count):
@@ -865,7 +867,7 @@ def get_encoder_counter(self):
865867
"""
866868

867869
get_msg = self.send_request(MGMSG.MOT_REQ_ENCCOUNTER,
868-
MGMSG.MOT_GET_ENCCOUNTER, 1)
870+
[MGMSG.MOT_GET_ENCCOUNTER], 1)
869871
return st.unpack("<l", get_msg.data[2:])[0]
870872

871873
def set_velocity_parameters(self, acceleration, max_velocity):
@@ -886,7 +888,7 @@ def get_velocity_parameters(self):
886888
"""
887889

888890
get_msg = self.send_request(MGMSG.MOT_REQ_VELPARAMS,
889-
MGMSG.MOT_GET_VELPARAMS, 1)
891+
[MGMSG.MOT_GET_VELPARAMS], 1)
890892
return st.unpack("<LL", get_msg.data[6:])
891893

892894
def set_jog_parameters(self, mode, step_size, acceleration,
@@ -915,7 +917,7 @@ def get_jog_parameters(self):
915917
"""
916918

917919
get_msg = self.send_request(MGMSG.MOT_REQ_JOGPARAMS,
918-
MGMSG.MOT_GET_JOGPARAMS, 1)
920+
[MGMSG.MOT_GET_JOGPARAMS], 1)
919921
(jog_mode, step_size, _, acceleration, max_velocity,
920922
stop_mode) = st.unpack("<HLLLLH", get_msg.data[2:])
921923
return jog_mode, step_size, acceleration, max_velocity, stop_mode
@@ -938,7 +940,7 @@ def get_gen_move_parameters(self):
938940
"""
939941

940942
get_msg = self.send_request(MGMSG.MOT_REQ_GENMOVEPARAMS,
941-
MGMSG.MOT_GET_GENMOVEPARAMS, 1)
943+
[MGMSG.MOT_GET_GENMOVEPARAMS], 1)
942944
return st.unpack("<l", get_msg.data[2:])[0]
943945

944946
def set_move_relative_parameters(self, relative_distance):
@@ -960,7 +962,7 @@ def get_move_relative_parameters(self):
960962
"""
961963

962964
get_msg = self.send_request(MGMSG.MOT_REQ_MOVERELPARAMS,
963-
MGMSG.MOT_GET_MOVERELPARAMS, 1)
965+
[MGMSG.MOT_GET_MOVERELPARAMS], 1)
964966
return st.unpack("<l", get_msg.data[2:])[0]
965967

966968
def set_move_absolute_parameters(self, absolute_position):
@@ -982,7 +984,7 @@ def get_move_absolute_parameters(self):
982984
"""
983985

984986
get_msg = self.send_request(MGMSG.MOT_REQ_MOVEABSPARAMS,
985-
MGMSG.MOT_GET_MOVEABSPARAMS, 1)
987+
[MGMSG.MOT_GET_MOVEABSPARAMS], 1)
986988
return st.unpack("<l", get_msg.data[2:])[0]
987989

988990
def set_home_parameters(self, home_velocity):
@@ -1002,17 +1004,17 @@ def get_home_parameters(self):
10021004
"""
10031005

10041006
get_msg = self.send_request(MGMSG.MOT_REQ_HOMEPARAMS,
1005-
MGMSG.MOT_GET_HOMEPARAMS, 1)
1007+
[MGMSG.MOT_GET_HOMEPARAMS], 1)
10061008
return st.unpack("<L", get_msg.data[6:10])[0]
10071009

10081010
def move_home(self):
10091011
"""Start a home move sequence.
10101012
1011-
This call is blocking until device is homed.
1013+
This call is blocking until device is homed or move is stopped.
10121014
"""
10131015

10141016
self.send_request(MGMSG.MOT_MOVE_HOME,
1015-
MGMSG.MOT_MOVE_HOMED, 1)
1017+
[MGMSG.MOT_MOVE_HOMED, MGMSG.MOT_MOVE_STOPPED], 1)
10161018

10171019
def set_limit_switch_parameters(self, cw_hw_limit, ccw_hw_limit):
10181020
"""Set the limit switch parameters.
@@ -1057,7 +1059,7 @@ def get_limit_switch_parameters(self):
10571059
"""
10581060

10591061
get_msg = self.send_request(MGMSG.MOT_REQ_LIMSWITCHPARAMS,
1060-
MGMSG.MOT_GET_LIMSWITCHPARAMS, 1)
1062+
[MGMSG.MOT_GET_LIMSWITCHPARAMS], 1)
10611063
return st.unpack("<HH", get_msg.data[2:6])
10621064

10631065
def move_relative_memory(self):
@@ -1069,7 +1071,8 @@ def move_relative_memory(self):
10691071
command.
10701072
"""
10711073

1072-
self.send(Message(MGMSG.MOT_MOVE_RELATIVE, param1=1))
1074+
self.send_request(MGMSG.MOT_MOVE_RELATIVE,
1075+
[MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED], 1)
10731076

10741077
def move_relative(self, relative_distance):
10751078
"""Start a relative move
@@ -1079,7 +1082,9 @@ def move_relative(self, relative_distance):
10791082
"""
10801083

10811084
payload = st.pack("<Hl", 1, relative_distance)
1082-
self.send(Message(MGMSG.MOT_MOVE_RELATIVE, data=payload))
1085+
self.send_request(MGMSG.MOT_MOVE_RELATIVE,
1086+
[MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED],
1087+
data=payload)
10831088

10841089
def move_absolute_memory(self):
10851090
"""Start an absolute move of distance in the controller's memory.
@@ -1090,7 +1095,9 @@ def move_absolute_memory(self):
10901095
command.
10911096
"""
10921097

1093-
self.send(Message(MGMSG.MOT_MOVE_ABSOLUTE, param1=1))
1098+
self.send_request(MGMSG.MOT_MOVE_ABSOLUTE,
1099+
[MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED],
1100+
param1=1)
10941101

10951102
def move_absolute(self, absolute_distance):
10961103
"""Start an absolute move.
@@ -1101,21 +1108,19 @@ def move_absolute(self, absolute_distance):
11011108
"""
11021109

11031110
payload = st.pack("<Hl", 1, absolute_distance)
1104-
self.send(Message(MGMSG.MOT_MOVE_ABSOLUTE, data=payload))
1111+
self.send_request(MGMSG.MOT_MOVE_ABSOLUTE,
1112+
[MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED],
1113+
data=payload)
11051114

1106-
def move_jog(self, direction, async=False):
1115+
def move_jog(self, direction):
11071116
"""Start a job move.
11081117
11091118
:param direction: The direction to jog. 1 is forward, 2 is backward.
1110-
:param async: If True then the command does not wait for the move to
1111-
finish. If False the command only returns when move is finished.
11121119
"""
11131120

1114-
if async:
1115-
self.send_request(MGMSG.MOT_MOVE_JOG,
1116-
MGMSG.MOT_MOVE_COMPLETED, 1, direction)
1117-
else:
1118-
self.send(Message(MGMSG.MOT_MOVE_JOG, param1=1, param2=direction))
1121+
self.send_request(MGMSG.MOT_MOVE_JOG,
1122+
[MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED],
1123+
param1=1, param2=direction)
11191124

11201125
def move_velocity(self, direction):
11211126
"""Start a move.
@@ -1134,7 +1139,7 @@ def move_velocity(self, direction):
11341139

11351140
self.send(Message(MGMSG.MOT_MOVE_VELOCITY, param1=1, param2=direction))
11361141

1137-
def move_stop(self, stop_mode, async=False):
1142+
def move_stop(self, stop_mode):
11381143
"""Stop any type of motor move.
11391144
11401145
Stops any of those motor move: relative, absolute, homing or move at
@@ -1143,15 +1148,13 @@ def move_stop(self, stop_mode, async=False):
11431148
:param stop_mode: The stop mode defines either an immediate (abrupt)
11441149
or profiled stop. Set this byte to 1 to stop immediately, or to 2
11451150
to stop in a controlled (profiled) manner.
1146-
:param async: If set to False, this method will block until motor
1147-
is really stopped. Returns immediately if set to True.
11481151
"""
11491152

1150-
if async:
1151-
self.send(Message(MGMSG.MOT_MOVE_STOP, param1=1, param2=stop_mode))
1152-
else:
1153+
if self.is_moving():
11531154
self.send_request(MGMSG.MOT_MOVE_STOP,
1154-
MGMSG.MOT_MOVE_STOPPED, 1, stop_mode)
1155+
[MGMSG.MOT_MOVE_STOPPED,
1156+
MGMSG.MOT_MOVE_COMPLETED],
1157+
1, stop_mode)
11551158

11561159
def set_dc_pid_parameters(self, proportional, integral, differential,
11571160
integral_limit, filter_control=0x0F):
@@ -1185,7 +1188,7 @@ def get_dc_pid_parameters(self):
11851188
"""
11861189

11871190
get_msg = self.send_request(MGMSG.MOT_REQ_DCPIDPARAMS,
1188-
MGMSG.MOT_GET_DCPIDPARAMS, 1)
1191+
[MGMSG.MOT_GET_DCPIDPARAMS], 1)
11891192
return st.unpack("<LLLLH", get_msg.data[2:])
11901193

11911194
def set_av_modes(self, mode_bits):
@@ -1212,7 +1215,7 @@ def get_av_modes(self):
12121215
"""
12131216

12141217
get_msg = self.send_request(MGMSG.MOT_REQ_AVMODES,
1215-
MGMSG.MOT_GET_AVMODES, 1)
1218+
[MGMSG.MOT_GET_AVMODES], 1)
12161219
return st.unpack("<H", get_msg.data[2:])[0]
12171220

12181221
def set_button_parameters(self, mode, position1, position2):
@@ -1250,7 +1253,7 @@ def get_button_parameters(self):
12501253
"""
12511254

12521255
get_msg = self.send_request(MGMSG.MOT_REQ_BUTTONPARAMS,
1253-
MGMSG.MOT_GET_BUTTONPARAMS, 1)
1256+
[MGMSG.MOT_GET_BUTTONPARAMS], 1)
12541257
return st.unpack("<Hll", get_msg.data[2:12])
12551258

12561259
def set_eeprom_parameters(self, msg_id):
@@ -1274,7 +1277,7 @@ def get_dc_status_update(self):
12741277
"""
12751278

12761279
get_msg = self.send_request(MGMSG.MOT_REQ_DCSTATUSUPDATE,
1277-
MGMSG.MOT_GET_DCSTATUSUPDATE, 1)
1280+
[MGMSG.MOT_GET_DCSTATUSUPDATE], 1)
12781281
pos, vel, _, stat = st.unpack("<LHHL", get_msg.data[2:])
12791282
return pos, vel, stat
12801283

@@ -1286,7 +1289,7 @@ def get_status_bits(self):
12861289
"""
12871290

12881291
get_msg = self.send_request(MGMSG.MOT_REQ_STATUSBITS,
1289-
MGMSG.MOT_GET_STATUSBITS, 1)
1292+
[MGMSG.MOT_GET_STATUSBITS], 1)
12901293
return st.unpack("<L", get_msg.data[2:])[0]
12911294

12921295
def suspend_end_of_move_messages(self):

1 commit comments

Comments
 (1)

sbourdeauducq commented on Jun 19, 2015

@sbourdeauducq
Member

Documentation update needed.

Please sign in to comment.