Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast_brake command for HWP rapid spindown #787

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 69 additions & 5 deletions socs/agents/hwp_supervisor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Comment on lines +1189 to +1201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code seems largely similar to the block of code handling ControlState.WaitForBrake in lines 1149-1165, with the only difference being that this block doesn't wait for the rotor to completely spin down. It might be simpler to add a boolean attribute to ControlState.WaitForBrake named fast which determines whether or not to run lines 1160-1164.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also whenever the ControlState.WaitForFastBrake finishes, it should set the state to ControlState.Done


elif isinstance(state, ControlState.EnableDriverBoard):
def set_outlet_state(outlet: int, outlet_state: bool):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1578,11 +1635,18 @@ def brake(self, session, params):
'success': True}
}
"""
state = ControlState.Brake(
freq_tol=params['freq_tol'],
freq_tol_duration=params['freq_tol_duration'],
brake_voltage=params['brake_voltage'],
)
if params['fast']:
state = ControlState.FastBrake(
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}"
Expand Down