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] committed Feb 2, 2024
1 parent b9964d2 commit 412d642
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 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
2 changes: 1 addition & 1 deletion socs/testing/hwp_emulator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
HWP Emulation module
"""
import argparse
import logging
import threading
import time
from dataclasses import dataclass
import argparse

import pytest

Expand Down

0 comments on commit 412d642

Please sign in to comment.