Skip to content

Commit

Permalink
hwp-supervisor: make IBootState compatible with synaccess. (#693)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ykyohei and pre-commit-ci[bot] authored Jun 19, 2024
1 parent d6cb152 commit 7e31eea
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions socs/agents/hwp_supervisor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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',
})
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7e31eea

Please sign in to comment.