Skip to content

Commit

Permalink
fix bug in drivers/Actuator.py for fast moving (speed_rate>1.)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadachi5 committed Nov 28, 2023
2 parents 89f4aa4 + c78e6f4 commit 9ade328
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 101 deletions.
6 changes: 6 additions & 0 deletions docs/agents/pysmurf-controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ These can be installed via pip:
$ python -m pip install 'sodetlib @ git+https://github.com/simonsobs/sodetlib.git@master'
$ python -m pip install 'sotodlib @ git+https://github.com/simonsobs/sotodlib.git@master'
Additionally, ``socs`` should be installed with the ``pysmurf`` group:

.. code-block:: bash
$ pip install -U socs[pysmurf]
Configuration File Examples
-----------------------------------

Expand Down
4 changes: 3 additions & 1 deletion docs/agents/wiregrid_actuator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ The parameter details are here:

- distance: Actuator moving distance [mm] (default: 10)
- speedrate: Actuator speed rate [0.0, 5.0] (default: 0.2)
DO NOT use speedrate > 1.0 if el != 90 deg!!

.. warning::
DO NOT use ``speedrate > 1.0`` if ``el != 90 deg``!


Hardware Configurations
Expand Down
2 changes: 2 additions & 0 deletions docs/user/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ The different groups, and the agents they provide dependencies for are:
- Magpie Agent
* - ``pfeiffer``
- Pfeiffer TC 400 Agent
* - ``pysmurf``
- Pysmurf Controller Agent
* - ``smurf_sim``
- SMuRF File Emulator, SMuRF Stream Simulator
* - ``synacc``
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pandas
pfeiffer-vacuum-protocol==0.4

# pysmurf controller
pyepics
pysmurf @ git+https://github.com/slaclab/pysmurf.git@main
sodetlib @ git+https://github.com/simonsobs/sodetlib.git@master
sotodlib @ git+https://github.com/simonsobs/sotodlib.git@master
Expand Down
15 changes: 8 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
pfeiffer_deps = ['pfeiffer-vacuum-protocol==0.4']

# Pysmurf Controller Agent
# pysmurf_deps = [
# 'pysmurf @ git+https://github.com/slaclab/pysmurf.git@main',
# 'sodetlib @ git+https://github.com/simonsobs/sodetlib.git@master',
# 'sotodlib @ git+https://github.com/simonsobs/sotodlib.git@master',
# ]
pysmurf_deps = [
'pyepics',
# 'pysmurf @ git+https://github.com/slaclab/pysmurf.git@main',
# 'sodetlib @ git+https://github.com/simonsobs/sodetlib.git@master',
# 'sotodlib @ git+https://github.com/simonsobs/sotodlib.git@master',
]

# SMuRF File Emulator, SMuRF Stream Simulator
smurf_sim_deps = ['so3g']
Expand All @@ -60,7 +61,7 @@
# Note: Not including the holograph deps, which are Python 3.8 only. Also not
# including any dependencies with only direct references.
all_deps = acu_deps + labjack_deps + magpie_deps + pfeiffer_deps + \
smurf_sim_deps + synacc_deps + timing_master_deps
pysmurf_deps + smurf_sim_deps + synacc_deps + timing_master_deps
all_deps = list(set(all_deps))

setup(
Expand Down Expand Up @@ -119,7 +120,7 @@
'labjack': labjack_deps,
'magpie': magpie_deps,
'pfeiffer': pfeiffer_deps,
# 'pysmurf': pysmurf_deps,
'pysmurf': pysmurf_deps,
'smurf_sim': smurf_sim_deps,
'synacc': synacc_deps,
'timing_master': timing_master_deps,
Expand Down
11 changes: 5 additions & 6 deletions socs/agents/hwp_gripper/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def shutdown(self, session, params=None):
self.shutdown_mode = True
return True, 'Shutdown completed'

def grip_hwp(self, session, params=None):
"""grip_hwp()
def grip(self, session, params=None):
"""grip()
**Task** - Series of commands to automatically grip the HWP.
This will return grippers to their home position, then move them each
Expand Down Expand Up @@ -442,7 +442,8 @@ def run_and_append(func, *args, **kwargs):

# Reset alarms. If the warm-limit is hit, the alarm will be triggered
# and return_dict['result'] will be True
return_dict = run_and_append(self.client.reset, job='grip', check_shutdown=check_shutdown)
return_dict = run_and_append(self.client.reset, job='grip',
check_shutdown=check_shutdown)

if return_dict['result']:
# If the warm-limit is hit, move the actuator outwards bit
Expand Down Expand Up @@ -676,9 +677,7 @@ def main(args=None):
args=args)

agent, runner = ocs_agent.init_site_agent(args)
gripper_agent = HWPGripperAgent(agent, mcu_ip=args.mcu_ip,
control_port=args.control_port,
supervisor_id=args.supervisor_id)
gripper_agent = HWPGripperAgent(agent, args)
agent.register_task('init_connection', gripper_agent.init_connection,
startup=True)
agent.register_process('monitor_state', gripper_agent.monitor_state,
Expand Down
18 changes: 11 additions & 7 deletions socs/agents/hwp_pid/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,17 @@ def acq(self, session, params):
data = {'timestamp': time.time(),
'block_name': 'HWPPID', 'data': {}}

current_freq = self.pid.get_freq()
target_freq = self.pid.get_target()
direction = self.pid.get_direction()

data['data']['current_freq'] = current_freq
data['data']['target_freq'] = target_freq
data['data']['direction'] = direction
try:
current_freq = self.pid.get_freq()
target_freq = self.pid.get_target()
direction = self.pid.get_direction()

data['data']['current_freq'] = current_freq
data['data']['target_freq'] = target_freq
data['data']['direction'] = direction
except BaseException:
time.sleep(1)
continue

self.agent.publish_to_feed('hwppid', data)

Expand Down
30 changes: 16 additions & 14 deletions socs/agents/hwp_pid/drivers/pid_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ class PID:

def __init__(self, ip, port, verb=False):
self.verb = verb
self.ip = ip
self.port = port
self.hex_freq = '00000'
self.direction = None
self.target = 0
# Need to setup connection before setting direction
self.conn = self._establish_connection(ip, int(port))
self.conn = self._establish_connection(self.ip, int(self.port))
self.set_direction('0')

@staticmethod
def _establish_connection(ip, port, timeout=5):
def _establish_connection(ip, port, timeout=2):
"""Connect to PID controller.
Args:
Expand All @@ -45,18 +47,17 @@ def _establish_connection(ip, port, timeout=5):
"""
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.settimeout(timeout)
# unit tests might fail on first connection attempt
attempts = 3
for attempt in range(attempts):
try:
conn.connect((ip, port))
break
except ConnectionRefusedError:
except (ConnectionRefusedError, OSError):
print(f"Failed to connect to device at {ip}:{port}")
print(f"Connection attempts remaining: {attempts-attempt-1}")
time.sleep(1)
conn.settimeout(timeout)

else:
raise RuntimeError('Could not connect to PID controller')
return conn

@staticmethod
Expand Down Expand Up @@ -259,20 +260,21 @@ def send_message(self, msg):
str: Respnose from the controller.
"""
self.conn.sendall((msg + '\r\n').encode())
time.sleep(0.5) # Don't send messages too quickly
for attempt in range(2):
try:
self.conn.sendall((msg + '\r\n').encode())
time.sleep(0.5) # Don't send messages too quickly
data = self.conn.recv(4096).decode().strip()
break
except socket.timeout:
return data
except (socket.timeout, OSError):
print("Caught timeout waiting for response from PID controller. "
+ "Trying again...")
time.sleep(1)
if attempt == 1:
raise RuntimeError(
'Response from PID controller timed out.')
return data
print("Resetting connection")
self.conn.close()
self.conn = self._establish_connection(self.ip, int(self.port))
return self.send_message(msg)

def return_messages(self, msg):
"""Decode list of responses from PID controller and return useful
Expand Down
35 changes: 20 additions & 15 deletions socs/agents/hwp_pmx/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,31 @@ def acq(self, session, params):
'block_name': 'hwppmx',
'data': {}
}
msg, curr = self.dev.meas_current()
data['data']['current'] = curr

msg, volt = self.dev.meas_voltage()
data['data']['voltage'] = volt
try:
msg, curr = self.dev.meas_current()
data['data']['current'] = curr

msg, code = self.dev.check_error()
data['data']['err_code'] = code
data['data']['err_msg'] = msg
msg, volt = self.dev.meas_voltage()
data['data']['voltage'] = volt

prot_code = self.dev.check_prot()
if prot_code != 0:
self.prot = prot_code
msg, code = self.dev.check_error()
data['data']['err_code'] = code
data['data']['err_msg'] = msg

prot_msg = self.dev.get_prot_msg(self.prot)
data['data']['prot_code'] = self.prot
data['data']['prot_msg'] = prot_msg
prot_code = self.dev.check_prot()
if prot_code != 0:
self.prot = prot_code

msg, src = self.dev.check_source()
data['data']['source'] = src
prot_msg = self.dev.get_prot_msg(self.prot)
data['data']['prot_code'] = self.prot
data['data']['prot_msg'] = prot_msg

msg, src = self.dev.check_source()
data['data']['source'] = src
except BaseException:
time.sleep(sleep_time)
continue

self.agent.publish_to_feed('hwppmx', data)
session.data = {'curr': curr,
Expand Down
Loading

0 comments on commit 9ade328

Please sign in to comment.