Uncategorized

Integrating python code into simulink matlab function block


I am working on a python simulink project, where i integrated a python script into a simulink matlab function block, but when i tried to run my simulation i got the following error:

**Cell contents reference from a non-cell array object.
**

i tried to solve it with differents ways but no one works.

This is my python function:

def simulationat(a,b,c):
    load_demand = load_agent.get_demand_power(a)
    pv_agent.receive_forecasted_pvpower(b)
    battery_agent.calculate_soc(c)
    load_state=load_agent.send_state()
    pv_state=pv_agent.send_state()
    battery_state=battery_agent.send_state()
    grid_state=grid_agent.send_state()
    supervisor_agent.receive_data(pv_agent.name, pv_state)
    supervisor_agent.receive_data(battery_agent.name, battery_state)
    supervisor_agent.receive_data(load_agent.name, load_state)
    supervisor_agent.receive_data(grid_agent.name, grid_state)
    supervisor_agent.take_decision() 
    supervisor_agent.send_commands(pv_agent, battery_agent,grid_agent)
    return pv_agent.relay_state,battery_agent.relay_state,grid_agent.relay_stateimport,grid_agent.relay_stateexport

and the following is the matlab function used in the simulink block:

function [pvagent, batteryagent, gridimport, gridexport] = fcn(pv, load, soc)
    coder.extrinsic('py.simult.simulationat');
    % Initialize outputs
    pvagent = 0;
    batteryagent = 0;
    gridimport = 0;
    gridexport = 0;
    pout = py.simult.simulationat(load, pv, soc);
     if isa(pout, 'py.tuple')
        pout_cell = cell(pout);
        pvagent = double(pout_cell{1});
        batteryagent = double(pout_cell{2});
        gridimport =double(pout_cell{3});
        gridexport = double(pout_cell{4});
 else
    pvagent = -1;
    batteryagent =-1;
    gridimport =-1;
    gridexport =-1;
 end
  
end

knowing that this two functions works normally when i called the matlab function in a matlab scirpt, but it doesn’t work in simulink, Have any of you faced a problem like this before?



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *