Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions socs/agents/lakeshore372/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from socs.Lakeshore.Lakeshore372 import LS372

heater_display_key = {'1': 'current',
'2': 'power'}


def still_power_to_perc(power, res, lead, max_volts):
cur = np.sqrt(power / res)
Expand Down Expand Up @@ -461,6 +464,42 @@ def set_heater_range(self, session, params):

return True, f'Set {heater_string} heater range to {params["range"]}'

@ocs_agent.param('_')
def get_sample_output(self, session, params):
"""get_sample_output()

**Task** - Query sample heater ouput (res, display mode, output in %)
for servoing cryostat.

Notes:
The sample heater output is stored in the session data
object in the format::

>>> response.session['data']
{'sample_resistance': 1020.0,
'display_mode': 'current',
'heater_power_percent': 0.0005}

"""
with self._lock.acquire_timeout(job='get_sample_output') as acquired:
if not acquired:
self.log.warn(f"Could not start Task because "
f"{self._lock.job} is already running")
return False, "Could not acquire lock"

session.set_status('running')

heater_perc = self.module.sample_heater.get_sample_heater_output()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this necessarily always return a percentage. Whether this is a percentage of the current set for the heater range or in power depends on heater output selection (aka "display mode") of either "current" or "power".

We should generalize the field you have as 'heater_power_percent' to 'heater_value'. Adding a "units" field would be reasonable. ocs-web could use that for a good display of heater output.

heater_settings = self.module.sample_heater.get_heater_setup()
res = float(heater_settings[0])
display_mode = heater_display_key[heater_settings[3]]

session.data = {"sample_resistance": res,
"display_mode": display_mode,
"heater_power_percent": heater_perc}

return True, 'Sample heater res {} ohms, display mode set to {} at {}%'.format(res, display_mode, heater_perc)

@ocs_agent.param('channel', type=int, check=lambda x: 1 <= x <= 16)
@ocs_agent.param('mode', type=str, choices=['current', 'voltage'])
def set_excitation_mode(self, session, params):
Expand Down Expand Up @@ -1442,6 +1481,7 @@ def main(args=None):
agent.register_task('set_heater_output', lake_agent.set_heater_output)
agent.register_task('set_still_output', lake_agent.set_still_output)
agent.register_task('get_still_output', lake_agent.get_still_output)
agent.register_task('get_sample_output', lake_agent.get_sample_output)
agent.register_process('acq', lake_agent.acq, lake_agent._stop_acq)
agent.register_process('custom_pid', lake_agent.custom_pid, lake_agent._stop_custom_pid)
agent.register_task('enable_control_chan', lake_agent.enable_control_chan)
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_ls372_agent_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def test_ls372_get_input_setup(wait_for_crossbar, emulator, run_agent, client):
assert resp.session['op_code'] == OpCode.SUCCEEDED.value


@pytest.mark.integtest
def test_ls372_get_sample_output(wait_for_crossbar, emulator, run_agent, client):
client.init_lakeshore()
resp = client.get_sample_output()
assert resp.status == ocs.OK
assert resp.session['op_code'] == OpCode.SUCCEEDED.value


@pytest.mark.integtest
def test_ls372_sample_custom_pid(wait_for_crossbar, emulator, run_agent, client):
client.init_lakeshore()
Expand Down