diff --git a/docs/agents/hwp_supervisor_agent.rst b/docs/agents/hwp_supervisor_agent.rst index c698ac367..47311ab93 100644 --- a/docs/agents/hwp_supervisor_agent.rst +++ b/docs/agents/hwp_supervisor_agent.rst @@ -109,7 +109,7 @@ or not. For example, to spin up to a particular frequency, you can run: {'class': 'Done', 'msg': None, 'success': True}], 'success': True} -To stop an action while its running, you can use the ``abort_action`` task, +To stop an action while its running, you can use the ``abort_action`` task, which will set the state of the current action to ``Abort``, and put the supervisor into the Idle state. @@ -127,7 +127,7 @@ supervisor into the Idle state. print("Result 2: ") print(res2.session['data']['action']) - >> + >> Result 1: {'action_id': 1, 'completed': True, @@ -139,7 +139,7 @@ supervisor into the Idle state. 'target_freq': 2.0}, {'class': 'Abort'}], 'success': False} - Result 2: + Result 2: {'action_id': 3, 'completed': True, 'cur_state': {'class': 'Done', 'msg': None, 'success': True}, diff --git a/socs/agents/hwp_supervisor/agent.py b/socs/agents/hwp_supervisor/agent.py index 0e33a013b..7a12e1aa4 100644 --- a/socs/agents/hwp_supervisor/agent.py +++ b/socs/agents/hwp_supervisor/agent.py @@ -4,7 +4,7 @@ import time import traceback from dataclasses import asdict, dataclass, field -from typing import Optional, List, Dict +from typing import Dict, List, Optional import numpy as np import ocs @@ -14,8 +14,9 @@ from ocs.ocs_client import OCSClient, OCSReply from ocs.ocs_twisted import Pacemaker - client_cache = {} + + def get_op_data(agent_id, op_name, log=None, test_mode=False): """ Process data from an agent operation, and formats it for the ``monitor`` @@ -362,12 +363,12 @@ class Base: def __init__(self): super().__init__() self.start_time = time.time() - + def encode(self): d = {'class': self.__class__.__name__} d.update(asdict(self)) return d - + @dataclass class Idle(Base): """Does nothing""" @@ -506,7 +507,8 @@ class Abort(Base): """Abort current action""" pass - completed_states = ( Done, Error, Abort, Idle ) + completed_states = (Done, Error, Abort, Idle) + class ControlAction: """ @@ -526,7 +528,7 @@ def __init__(self, state: ControlState.Base): self.success = False self.state_history = [] self.set_state(state) - + def set_state(self, state: ControlState.Base): """ Sets state for the current action. If this is a `completed_state`, @@ -538,7 +540,7 @@ def set_state(self, state: ControlState.Base): self.completed = True if isinstance(state, ControlState.Done): self.success = state.success - + def encode(self): """Encodes this as a dict""" return dict( @@ -548,10 +550,10 @@ def encode(self): cur_state=self.cur_state.encode(), state_history=[s.encode() for s in self.state_history], ) - + def sleep_until_complete(self, session=None, dt=1): """ - Sleeps until the action is complete. + Sleeps until the action is complete. Args ----- @@ -568,6 +570,7 @@ def sleep_until_complete(self, session=None, dt=1): return time.sleep(dt) + class ControlStateMachine: def __init__(self): self.action: ControlAction = ControlAction(ControlState.Idle()) @@ -1109,17 +1112,17 @@ def make_parser(parser=None): "shutdown is triggered") pgroup.add_argument( - '--driver-iboot-id', + '--driver-iboot-id', help="Instance ID for IBoot-PDU agent that powers the HWP Driver board") pgroup.add_argument( - '--driver-iboot-outlets', nargs='+', type=int, + '--driver-iboot-outlets', nargs='+', type=int, help="Outlets for driver iboot power") pgroup.add_argument( - '--gripper-iboot-id', + '--gripper-iboot-id', help="Instance ID for IBoot-PDU agent that powers the gripper controller") pgroup.add_argument( - '--gripper-iboot-outlets', nargs='+', type=int, + '--gripper-iboot-outlets', nargs='+', type=int, help="Outlets for gripper iboot power") pgroup.add_argument('--forward-dir', choices=['cw', 'ccw'], default="cw", diff --git a/socs/testing/hwp_emulator.py b/socs/testing/hwp_emulator.py index 222a14a46..b0a0e4c49 100644 --- a/socs/testing/hwp_emulator.py +++ b/socs/testing/hwp_emulator.py @@ -1,6 +1,7 @@ """ HWP Emulation module """ +import argparse import logging import threading import time