From e179461077f07d9c1ea6d655f89f170de075b568 Mon Sep 17 00:00:00 2001 From: jsugiyama <75608221+17-sugiyama@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:44:44 +0900 Subject: [PATCH 1/2] add fast_brake command for rapid dpindown --- socs/agents/hwp_supervisor/agent.py | 70 +++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/socs/agents/hwp_supervisor/agent.py b/socs/agents/hwp_supervisor/agent.py index 3957b1262..a207200b7 100644 --- a/socs/agents/hwp_supervisor/agent.py +++ b/socs/agents/hwp_supervisor/agent.py @@ -657,6 +657,26 @@ class WaitForBrake: min_freq: float prev_freq: float = None + @dataclass + class FastBrake: + """ + Configure the PID and PCU agents to more actively brake the HWP + """ + freq_tol: float + freq_tol_duration: float + brake_voltage: float + + @dataclass + class WaitForFastBrake: + """ + Waits until the HWP has slowed down enough before shutting off PMX. + + min_freq : float + Frequency (Hz) below which the PMX should be shut off. + """ + min_freq: float + prev_freq: float = None + @dataclass class PmxOff: """ @@ -1143,6 +1163,42 @@ def check_acu_ok_for_spinup(): freq_tol_duration=30, )) return + elif isinstance(state, ControlState.FastBrake): + # Flip PID direciton and tune stop + pid_dir = int(query_pid_state()['direction']) + if pid_dir == 1: + self.run_and_validate( + clients.pcu.send_command, + kwargs={'command': 'on_2'}, timeout=None + ) + else: + self.run_and_validate( + clients.pcu.send_command, + kwargs={'command': 'on_1'}, timeout=None + ) + self.run_and_validate(clients.pmx.ign_ext) + self.run_and_validate(clients.pmx.set_v, kwargs={'volt': state.brake_voltage}) + self.run_and_validate(clients.pmx.set_on) + + time.sleep(10) + self.action.set_state(ControlState.WaitForFastBrake( + min_freq=0.2, + prev_freq=hwp_state.enc_freq, + )) + + elif isinstance(state, ControlState.WaitForFastBrake): + f0 = query_pid_state()['current_freq'] + time.sleep(5) + f1 = query_pid_state()['current_freq'] + if f0 < 0.2 or (f1 > f0): + self.log.info("Turning off PMX and putting PCU in stop mode") + self.run_and_validate(clients.pmx.set_off) + self.run_and_validate( + clients.pcu.send_command, + kwargs={'command': 'stop'}, timeout=None + ) + time.sleep(5) + return elif isinstance(state, ControlState.EnableDriverBoard): def set_outlet_state(outlet: int, outlet_state: bool): @@ -1549,6 +1605,7 @@ def set_const_voltage(self, session, params): @ocs_agent.param('freq_tol', type=float, default=0.05) @ocs_agent.param('freq_tol_duration', type=float, default=10) @ocs_agent.param('brake_voltage', type=float, default=10.) + @ocs_agent.param('fast', type=bool, default=False) def brake(self, session, params): """brake(freq_thresh=0.05, freq_thresh_duration=10, brake_voltage=10) @@ -1578,11 +1635,18 @@ def brake(self, session, params): 'success': True} } """ - state = ControlState.Brake( + if params['fast']: + state = ControlState.FastBrake( freq_tol=params['freq_tol'], freq_tol_duration=params['freq_tol_duration'], - brake_voltage=params['brake_voltage'], - ) + brake_voltage=30., + ) + else: + state = ControlState.Brake( + freq_tol=params['freq_tol'], + freq_tol_duration=params['freq_tol_duration'], + brake_voltage=params['brake_voltage'], + ) action = self.control_state_machine.request_new_action(state) action.sleep_until_complete(session=session) return action.success, f"Completed with state: {action.cur_state_info.state}" From 3eef07ca7a144f04d9de4e6f531c389a3e39194f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:06:14 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- socs/agents/hwp_supervisor/agent.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/socs/agents/hwp_supervisor/agent.py b/socs/agents/hwp_supervisor/agent.py index a207200b7..9f0fafac3 100644 --- a/socs/agents/hwp_supervisor/agent.py +++ b/socs/agents/hwp_supervisor/agent.py @@ -1637,16 +1637,16 @@ def brake(self, session, params): """ if params['fast']: state = ControlState.FastBrake( - freq_tol=params['freq_tol'], - freq_tol_duration=params['freq_tol_duration'], - brake_voltage=30., + freq_tol=params['freq_tol'], + freq_tol_duration=params['freq_tol_duration'], + brake_voltage=30., ) else: state = ControlState.Brake( freq_tol=params['freq_tol'], freq_tol_duration=params['freq_tol_duration'], brake_voltage=params['brake_voltage'], - ) + ) action = self.control_state_machine.request_new_action(state) action.sleep_until_complete(session=session) return action.success, f"Completed with state: {action.cur_state_info.state}"