[docs]classBangBangConfig(SISOControllerConfig):"""Special config for a BangBang-Controller"""gain:float=Field(title="Gain of output",default=1)
[docs]classBangBang(SISOController):""" A bang–bang controller (2 step or on–off controller), also known as a hysteresis controller, that switches abruptly between two states. """config:BangBangConfigdef__init__(self,*,config:dict,agent:Agent):super().__init__(config=config,agent=agent)self._last_out_val=self.get(self.config.output.name).value@propertydefgain(self):"""Get the gain of the BangBang controller"""returnself.config.gain@propertydeflast_out_val(self):"""Last output value of the controller"""returnself._last_out_val@last_out_val.setterdeflast_out_val(self,out_val):"""Set the last output value of the controller"""self._last_out_val=out_val
[docs]defdo_step(self,inp_var:AgentVariable):# y = not pre(y) and u > uHigh or pre(y) and u >= uLowifinp_var.value<=self.ubandself.last_out_val==int(notself.reverse):returnint(notself.reverse)ifinp_var.value>self.ubandself.last_out_val==int(notself.reverse):returnint(self.reverse)ifinp_var.value<self.lbandself.last_out_val==int(self.reverse):returnint(notself.reverse)ifinp_var.value>=self.lbandself.last_out_val==int(self.reverse):returnint(self.reverse)