Skip to content
Open
Changes from 3 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
49 changes: 32 additions & 17 deletions socs/agents/hwp_supervisor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ class Brake:
freq_tol: float
freq_tol_duration: float
brake_voltage: float
fast: bool = False

@dataclass
class WaitForBrake:
Expand All @@ -656,6 +657,7 @@ class WaitForBrake:
"""
min_freq: float
prev_freq: float = None
fast: bool = False

@dataclass
class PmxOff:
Expand Down Expand Up @@ -1104,45 +1106,56 @@ def check_acu_ok_for_spinup():
self.action.set_state(ControlState.Done(success=True))

elif isinstance(state, ControlState.Brake):
pid_dir = int(query_pid_state()['direction'])
if state.fast:
# set pcu fase brake state
new_pcu_state = 'on_2' if (pid_dir == 1) else 'on_1'
min_freq = 0.2
else:
new_pcu_state = 'off'
min_freq = 0.5
self.run_and_validate(
clients.pcu.send_command,
kwargs={'command': 'off'}, timeout=None
kwargs={'command': new_pcu_state}, timeout=None
)

# Flip PID direciton and tune stop
pid_dir = int(query_pid_state()['direction'])
new_d = '0' if (pid_dir == 1) else '1'
self.run_and_validate(clients.pid.set_direction,
kwargs=dict(direction=new_d))
self.run_and_validate(clients.pid.tune_stop)

if not state.fast:
# Flip PID direciton and tune stop
new_d = '0' if (pid_dir == 1) else '1'
self.run_and_validate(clients.pid.set_direction,
kwargs=dict(direction=new_d))
self.run_and_validate(clients.pid.tune_stop)
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.WaitForBrake(
min_freq=0.5,
min_freq=min_freq,
prev_freq=hwp_state.enc_freq,
fast=state.fast
))

elif isinstance(state, ControlState.WaitForBrake):
f0 = query_pid_state()['current_freq']
time.sleep(5)
f1 = query_pid_state()['current_freq']
if f0 < 0.5 or (f1 > f0):
if f0 < state.min_freq 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
)
self.action.set_state(ControlState.WaitForTargetFreq(
target_freq=0,
freq_tol=0.05,
freq_tol_duration=30,
))
return
if state.fast:
time.sleep(5)
return
Comment thread
ykyohei marked this conversation as resolved.
Outdated
else:
self.action.set_state(ControlState.WaitForTargetFreq(
target_freq=0,
freq_tol=0.05,
freq_tol_duration=30,
))
return

elif isinstance(state, ControlState.EnableDriverBoard):
def set_outlet_state(outlet: int, outlet_state: bool):
Expand Down Expand Up @@ -1549,6 +1562,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 @@ -1582,6 +1596,7 @@ def brake(self, session, params):
freq_tol=params['freq_tol'],
freq_tol_duration=params['freq_tol_duration'],
brake_voltage=params['brake_voltage'],
fast=params['fast']
)
action = self.control_state_machine.request_new_action(state)
action.sleep_until_complete(session=session)
Expand Down