How can I create a Pandapower controller to set p_mw value in net.load column based on voltage threshold?

109 views Asked by At

I want to create a controller for a pandapower run_timeseries calculation it should check on the voltage of the net.res_bus and than set the p_mw value in the net.load column to a predefined value for all loads which have the string 'cp' in the net.load.type column I don't know why it is not working.

this is my code so far:

import pandapower.control

class ChargingController(pandapower.control.basic_controller.Controller):
  

    def __init__(self, net, voltage_threshold, p_mw_limit, load_id, in_service=True,
                 recycle=False, order=0, level=0, **kwargs):
        super().__init__(net, in_service=in_service, recycle=recycle, order=order, level=level,
                         initial_powerflow=True, **kwargs)
        self.load_id = load_id
        self.voltage_threshold = voltage_threshold
        self.p_mw_limit = p_mw_limit
        self.p_mw = net.load.at[load_id, 'p_mw']
        self.q_mvar = net.load.at[load_id, 'q_mvar']
        self.applied = False

    def is_converged(self, net):
        return self.applied

    def control_step(self, net):
        load_bus = net.load.at[self.load_id, 'bus']
        voltage = net.res_bus.at[load_bus, 'vm_pu']
        for i in range(len(self.voltage_threshold)):
            if voltage < self.voltage_threshold[i]:
                self.p_mw = self.p_mw_limit[i]
                self.q_mvar = self.p_mw*0.35
                self.write_to_net(net)
                break
        self.applied = True

    def write_to_net(self, net):
        net.load.at[self.load_id, "p_mw"] = self.p_mw
        net.load.at[self.load_id, "q_mvar"] = self.q_mvar

    def time_step(self, time, net):
        self.applied = False


voltage_list = [0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]
p_mw_limit_list = [0,0,0,0,0,0,0,0,0,0,0]

for load_index, p_mw_limit, voltage_threshold in zip(net.load.index, p_mw_limit_list, voltage_list):
    load_type = net.load.at[load_index, 'type']
    if isinstance(load_type, str) and 'cp' in load_type:
        ChargingController(net, voltage_threshold=voltage_threshold, p_mw_limit=p_mw_limit, load_id=load_index)

This is a minimal example there the p_mw should be set to 0 for all loads with the string 'cp' in the net.load.type column but it doesn't work as expected

0

There are 0 answers