Skip to content

Commit

Permalink
add check tasks etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ykyohei committed Dec 11, 2024
1 parent 7631d0e commit c40d3f5
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 12 deletions.
76 changes: 72 additions & 4 deletions socs/agents/hwp_pmx/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class CancelShutdown(BaseAction):
def process(self, module):
self.log.info("Cancel shutdown...")

@dataclass
class CheckI(BaseAction):
def process(self, module):
msg, val = module.check_current()
self.log.info(msg + "...")

@dataclass
class CheckV(BaseAction):
def process(self, module):
msg, val = module.check_voltage()
self.log.info(msg + "...")

@dataclass
class SetI(BaseAction):
curr: float
Expand All @@ -74,6 +86,18 @@ def process(self, module):
msg, val = module.set_voltage(self.volt)
self.log.info(msg + "...")

@dataclass
class CheckILim(BaseAction):
def process(self, module):
msg, val = module.check_current_limit()
self.log.info(msg + "...")

@dataclass
class CheckVLim(BaseAction):
def process(self, module):
msg, val = module.check_voltage_limit()
self.log.info(msg + "...")

@dataclass
class SetILim(BaseAction):
curr: float
Expand Down Expand Up @@ -184,7 +208,27 @@ def ign_ext(self, session, params):
return True, 'Set PMX Kikusui to direct control'

@defer.inlineCallbacks
@ocs_agent.param('curr', default=0, type=float, check=lambda x: 0 <= x <= 3)
def check_i(self, session, params):
"""check_i()
**Task** - Set the current setting.
"""
action = Actions.CheckI(**params)
self.action_queue.put(action)
session.data = yield action.deferred
return True, 'Check current is done'

@defer.inlineCallbacks
def check_v(self, session, params):
"""check_v()
**Task** - Set the voltage setting.
"""
action = Actions.CheckV(**params)
self.action_queue.put(action)
session.data = yield action.deferred
return True, 'Check voltage is done'

@defer.inlineCallbacks
@ocs_agent.param('curr', default=0, type=float)
def set_i(self, session, params):
"""set_i(curr=0)
**Task** - Set the current.
Expand All @@ -198,7 +242,7 @@ def set_i(self, session, params):
return True, 'Set current is done'

@defer.inlineCallbacks
@ocs_agent.param('volt', default=0, type=float, check=lambda x: 0 <= x <= 35)
@ocs_agent.param('volt', default=0, type=float)
def set_v(self, session, params):
"""set_v(volt=0)
**Task** - Set the voltage.
Expand All @@ -212,7 +256,27 @@ def set_v(self, session, params):
return True, 'Set voltage is done'

@defer.inlineCallbacks
@ocs_agent.param('curr', default=1., type=float, check=lambda x: 0. <= x <= 3.)
def check_i_lim(self, session, params):
"""check_i_lim()
**Task** - Check the current protection limit.
"""
action = Actions.CheckILim(**params)
self.action_queue.put(action)
session.data = yield action.deferred
return True, 'Check current protection limit is done'

@defer.inlineCallbacks
def check_v_lim(self, session, params):
"""check_v_lim()
**Task** - Check the voltage protection limit.
"""
action = Actions.CheckVLim(**params)
self.action_queue.put(action)
session.data = yield action.deferred
return True, 'Check voltage protection limit is done'

@defer.inlineCallbacks
@ocs_agent.param('curr', default=1.3, type=float)
def set_i_lim(self, session, params):
"""set_i_lim(curr=1)
**Task** - Set the drive current limit.
Expand All @@ -226,7 +290,7 @@ def set_i_lim(self, session, params):
return True, 'Set voltage limit is done'

@defer.inlineCallbacks
@ocs_agent.param('volt', default=32., type=float, check=lambda x: 0. <= x <= 35.)
@ocs_agent.param('volt', default=37., type=float)
def set_v_lim(self, session, params):
"""set_v_lim(volt=32)
**Task** - Set the drive voltage limit.
Expand Down Expand Up @@ -475,8 +539,12 @@ def main(args=None):
agent.register_task('set_on', PMX.set_on, blocking=False)
agent.register_task('set_off', PMX.set_off, blocking=False)
agent.register_task('clear_alarm', PMX.clear_alarm, blocking=False)
agent.register_task('check_i', PMX.check_i, blocking=False)
agent.register_task('check_v', PMX.check_v, blocking=False)
agent.register_task('set_i', PMX.set_i, blocking=False)
agent.register_task('set_v', PMX.set_v, blocking=False)
agent.register_task('check_i_lim', PMX.check_i_lim, blocking=False)
agent.register_task('check_v_lim', PMX.check_v_lim, blocking=False)
agent.register_task('set_i_lim', PMX.set_i_lim, blocking=False)
agent.register_task('set_v_lim', PMX.set_v_lim, blocking=False)
agent.register_task('use_ext', PMX.use_ext, blocking=False)
Expand Down
24 changes: 16 additions & 8 deletions socs/agents/hwp_pmx/drivers/PMX_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,29 @@ def ign_external_voltage(self):
self.wait()
return self.check_source()

def check_current_limit(self):
""" Check the PMX current protection limit """
val = float(self.send_message(b'curr:prot?\n'))
msg = "Current protection limit = {:.3f} A".format(val)
return msg, val

def check_voltage_limit(self):
""" Check the PMX voltage protection limit """
val = float(self.send_message(b'volt:prot?\n'))
msg = "Voltage protection limit = {:.3f} V".format(val)
return msg, val

def set_current_limit(self, curr_lim):
""" Set the PMX current limit """
""" Set the PMX current protection limit """
self.send_message(b'curr:prot %a\n' % curr_lim, read=False)
self.wait()
val = float(self.send_message(b'curr:prot?\n'))
msg = "Current Limit: {:.3f} A".format(val)
return msg
return self.check_current_limit()

def set_voltage_limit(self, vol_lim):
""" Set the PMX voltage limit """
""" Set the PMX voltage protection limit """
self.send_message(b'volt:prot %a\n' % vol_lim, read=False)
self.wait()
val = float(self.send_message(b'volt:prot?\n'))
msg = "Voltage Limit: {:.3f} V".format(val)
return msg
return self.check_voltage_limit()

def check_prot(self):
""" Check the protection status
Expand Down

0 comments on commit c40d3f5

Please sign in to comment.