From 7e31eeaf56e96fec12c960f6fb2fdedf0aa61299 Mon Sep 17 00:00:00 2001 From: Kyohei YAMADA <38639108+ykyohei@users.noreply.github.com> Date: Tue, 18 Jun 2024 23:09:59 -0400 Subject: [PATCH] hwp-supervisor: make IBootState compatible with synaccess. (#693) * make IBootState compatible with synaccess * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add gripper-power-agent-type --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- socs/agents/hwp_supervisor/agent.py | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/socs/agents/hwp_supervisor/agent.py b/socs/agents/hwp_supervisor/agent.py index 2d4f2ee4a..a0a7a96bd 100644 --- a/socs/agents/hwp_supervisor/agent.py +++ b/socs/agents/hwp_supervisor/agent.py @@ -118,12 +118,12 @@ class HWPClients: class IBootState: instance_id: str outlets: List[int] + agent_type: Literal['iboot, synaccess'] outlet_state: Dict[int, Optional[int]] = None op_data: Optional[Dict] = None def __post_init__(self): self.outlet_state = {o: None for o in self.outlets} - self.outlet_labels = {o: f'outletStatus_{o}' for o in self.outlets} def update(self): op = get_op_data(self.instance_id, 'acq', test_mode=False) @@ -132,10 +132,23 @@ def update(self): self.outlet_state = {o: None for o in self.outlets} return - self.outlet_state = { - outlet: op['data'][label]['status'] - for outlet, label in self.outlet_labels.items() - } + if self.agent_type == 'iboot': + self.outlet_labels = {o: f'outletStatus_{o}' for o in self.outlets} + self.outlet_state = { + outlet: op['data'][label]['status'] + for outlet, label in self.outlet_labels.items() + } + elif self.agent_type == 'synaccess': + self.outlet_labels = {o: str(o - 1) for o in self.outlets} + self.outlet_state = { + outlet: op['data']['fields'][label]['status'] + for outlet, label in self.outlet_labels.items() + } + else: + raise ValueError( + f"Invalid agent_type: {self.agent_type}. " + "Must be in ['iboot', 'synaccess']" + ) @dataclass @@ -179,9 +192,11 @@ def from_args(cls, args: argparse.Namespace): ups_minutes_remaining_thresh=args.ups_minutes_remaining_thresh, ) if args.gripper_iboot_id is not None: - self.gripper_iboot = IBootState(args.gripper_iboot_id, args.gripper_iboot_outlets) + self.gripper_iboot = IBootState(args.gripper_iboot_id, args.gripper_iboot_outlets, + args.gripper_power_agent_type) if args.driver_iboot_id is not None: - self.driver_iboot = IBootState(args.driver_iboot_id, args.driver_iboot_outlets) + self.driver_iboot = IBootState(args.driver_iboot_id, args.driver_iboot_outlets, + args.driver_power_agent_type) return self def _update_from_keymap(self, op, keymap): @@ -205,6 +220,7 @@ def update_enc_state(self, op): """ self._update_from_keymap(op, { 'enc_freq': 'approx_hwp_freq', + 'encoder_last_updated': 'encoder_last_updated', 'last_quad': 'last_quad', 'last_quad_time': 'last_quad_time', }) @@ -1456,6 +1472,9 @@ def make_parser(parser=None): pgroup.add_argument( '--gripper-iboot-outlets', nargs='+', type=int, help="Outlets for gripper iboot power") + pgroup.add_argument( + '--gripper-power-agent-type', choices=['iboot', 'synaccess'], default=None, + help="Type of agent used for controlling the gripper power") pgroup.add_argument('--forward-dir', choices=['cw', 'ccw'], default="cw", help="Whether the PID 'forward' direction is cw or ccw")