Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and jlashner committed Feb 6, 2024
1 parent 86ad5aa commit 0f0dd5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions docs/agents/hwp_supervisor_agent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -127,7 +127,7 @@ supervisor into the Idle state.
print("Result 2: ")
print(res2.session['data']['action'])
>>
>>
Result 1:
{'action_id': 1,
'completed': True,
Expand All @@ -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},
Expand Down
29 changes: 16 additions & 13 deletions socs/agents/hwp_supervisor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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``
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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`,
Expand All @@ -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(
Expand All @@ -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
-----
Expand All @@ -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())
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions socs/testing/hwp_emulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
HWP Emulation module
"""
import argparse
import logging
import threading
import time
Expand Down

0 comments on commit 0f0dd5a

Please sign in to comment.