agentlib.modules.controller package
Submodules
agentlib.modules.controller.bangbang module
- class agentlib.modules.controller.bangbang.BangBang(*, config: dict, agent: Agent)[source]
Bases:
SISOController
A bang–bang controller (2 step or on–off controller), also known as a hysteresis controller, that switches abruptly between two states.
- do_step(inp_var: AgentVariable)[source]
Controller step function. Needs to be a generator function, thus using yield instead of return
- property gain
Get the gain of the BangBang controller
- property last_out_val
Last output value of the controller
- pydantic model agentlib.modules.controller.bangbang.BangBangConfig[source]
Bases:
SISOControllerConfig
Special config for a BangBang-Controller
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
- field gain: float = 1
- field input: AgentVariable = AgentVariable(name='u', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='u', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field lb: float = -inf
- Validated by:
- field log_level: str | None = None
The log level for this Module. Default uses the root-loggers level.Options: DEBUG; INFO; WARNING; ERROR; CRITICAL
- Validated by:
- field module_id: str [Required]
The unqiue id of the module within an agent, used only to communicate withing the agent.
- field output: AgentVariable = AgentVariable(name='y', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='y', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field reverse: bool = False
A list of strings with each string being a field of the Modules configs. The field must be or contain an AgentVariable. If the field is added to this list, all shared attributes of the AgentVariables will be set to True.
- Validated by:
- field type: str | Dict[str, str] [Required]
The type of the Module. Used to find the Python-Object from all agentlib-core and plugin Module options. If a dict is given,it must contain the keys ‘file’ and ‘class_name’. ‘file’ is the filepath of a python file containing the Module.’class_name’ is the name of the Module class within this file.
- field ub: float = inf
- field validate_incoming_values: bool | None = True
If true, the validator of the AgentVariable value is called when receiving a new value from the DataBroker.
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
agentlib.modules.controller.controller module
This modules defines re-use able controller modules, such as the standard Controller and the SISOController
- class agentlib.modules.controller.controller.Controller(*, config: dict, agent: Agent)[source]
Bases:
BaseModule
Base class for all controller tasks within an agent
- abstract do_step(inp_var: AgentVariable)[source]
Controller step function. Needs to be a generator function, thus using yield instead of return
- property step: Generator
Return the generator for the do_step function
- class agentlib.modules.controller.controller.SISOController(*, config: dict, agent: Agent)[source]
Bases:
Controller
Base class for all controller having one single input and one single output
- property lb
The lb value
- property reverse
The reverse value
- property ub
The ub value
- pydantic model agentlib.modules.controller.controller.SISOControllerConfig[source]
Bases:
BaseModuleConfig
Check all inputs of a SISO-Contoller
Parameters used in all SISO Controllers. ub: Upper bound of controller output lb: Lower bound of controller output reverser: Change of sign.
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
- field input: AgentVariable = AgentVariable(name='u', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='u', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field lb: float = -inf
- Validated by:
- field log_level: str | None = None
The log level for this Module. Default uses the root-loggers level.Options: DEBUG; INFO; WARNING; ERROR; CRITICAL
- Validated by:
- field module_id: str [Required]
The unqiue id of the module within an agent, used only to communicate withing the agent.
- field output: AgentVariable = AgentVariable(name='y', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='y', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field reverse: bool = False
A list of strings with each string being a field of the Modules configs. The field must be or contain an AgentVariable. If the field is added to this list, all shared attributes of the AgentVariables will be set to True.
- Validated by:
- field type: str | Dict[str, str] [Required]
The type of the Module. Used to find the Python-Object from all agentlib-core and plugin Module options. If a dict is given,it must contain the keys ‘file’ and ‘class_name’. ‘file’ is the filepath of a python file containing the Module.’class_name’ is the name of the Module class within this file.
- field ub: float = inf
- field validate_incoming_values: bool | None = True
If true, the validator of the AgentVariable value is called when receiving a new value from the DataBroker.
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
agentlib.modules.controller.pid module
- class agentlib.modules.controller.pid.PID(*, config, agent)[source]
Bases:
SISOController
A proportional–integral–derivative controller (PID controller or three-term controller) with anti-wind up. It continuously calculates an error value e(t) as the difference between a desired set point and a measured process variable and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively) +——————–+—————+—————+———————+ | Parameter | Kp | Ki=(Kp/Ti) | Kd=(Kp*Td) | +——————–+—————+—————+———————+ | Rise time | Decrease | Decrease | Minor change | | Overshoot | Increase | Increase | Decrease | | Settling time | Small change | Increase | Decrease | | Steady-state error | Decrease | Eliminate | No effect in theory | | Stability | Degrade | Degrade | Improve if Kd small | +——————–+—————+—————+———————+
- Configs:
setpoint (float): Set point of the controller Kp (float): proportional gain Ti (float): integration time in s Td (float): derivative time in s ub (float): high control limit lb (float): low control limit reverse(boolean): change of sign
- property Kp
Get the current Kp value from data_broker or config
- property Td
Get the current Td value from data_broker or config
- property Ti
Get the current Ti value from data_broker or config
- do_step(inp_var: AgentVariable)[source]
Controller step function. Needs to be a generator function, thus using yield instead of return
- property setpoint
Get the current setpoint value from data_broker or config
- pydantic model agentlib.modules.controller.pid.PIDConfig[source]
Bases:
SISOControllerConfig
Pydantic data model for pid controller configuration parser
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
- field Kp: AgentVariable | float = AgentVariable(name='Kp', type='float', timestamp=None, unit='Not defined', description='Proportional gain', ub=inf, lb=-inf, clip=False, allowed_values=[], value=1, alias='Kp', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field Td: AgentVariable | float = AgentVariable(name='Td', type='float', timestamp=None, unit='seconds', description='Derivative time in s', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='Td', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field Ti: AgentVariable | float = AgentVariable(name='Ti', type='float', timestamp=None, unit='Not defined', description='Integration time in s', ub=inf, lb=-inf, clip=False, allowed_values=[], value=inf, alias='Ti', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field input: AgentVariable = AgentVariable(name='u', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='u', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field lb: float = -inf
- Validated by:
- field log_level: str | None = None
The log level for this Module. Default uses the root-loggers level.Options: DEBUG; INFO; WARNING; ERROR; CRITICAL
- Validated by:
- field module_id: str [Required]
The unqiue id of the module within an agent, used only to communicate withing the agent.
- field output: AgentVariable = AgentVariable(name='y', type='float', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=0, alias='y', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
- field reverse: bool = False
- field setpoint: AgentVariable | float = AgentVariable(name='setpoint', type='float', timestamp=None, unit='Not defined', description='Pid Setpoint', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='setpoint', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)
- Validated by:
A list of strings with each string being a field of the Modules configs. The field must be or contain an AgentVariable. If the field is added to this list, all shared attributes of the AgentVariables will be set to True.
- Validated by:
- field type: str | Dict[str, str] [Required]
The type of the Module. Used to find the Python-Object from all agentlib-core and plugin Module options. If a dict is given,it must contain the keys ‘file’ and ‘class_name’. ‘file’ is the filepath of a python file containing the Module.’class_name’ is the name of the Module class within this file.
- field ub: float = inf
- field validate_incoming_values: bool | None = True
If true, the validator of the AgentVariable value is called when receiving a new value from the DataBroker.
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.