Error Simscape Number of variables exceeds number of equations : fault_detection_and_control_system/Voltage Sensor
2 次查看(过去 30 天)
显示 更早的评论
Hi All,
I have 2 matlab equation. I want to monitor the conversion of voltage from AC to DC. Added the Simulink Model.
Funtion 1:
function switch_inputs = mpc_voltage_control(V_ref, V_in, V_out, Np)
% Inputs:
% V_ref - Reference voltage (400 kV)
% V_in - Measured input voltages [V_a, V_b, V_c]
% V_out - Measured output voltage
% Np - Prediction horizon (number of future steps)
% Outputs:
% switch_inputs - Input to the switching control function [S1, S2, S3, S4, S5, S6]
% Define system parameters
num_switches = 6; % Number of switches (IGBTs)
% Initialize switch inputs (control commands)
switch_inputs = zeros(1, num_switches);
% Define cost function variables
min_cost = inf; % Initialize minimum cost to a large value
optimal_switch_inputs = switch_inputs; % Initialize optimal switches
% Define possible switch combinations (6 IGBTs: S1, S2, S3, S4, S5, S6)
possible_switch_states = dec2bin(0:(2^num_switches-1), num_switches) - '0';
% Loop over all possible switching combinations
for i = 1:size(possible_switch_states, 1)
% Get current switch combination
current_switch_states = possible_switch_states(i, :);
% Predict future output voltage based on switch states and measured inputs
V_out_pred = predict_future_voltage(current_switch_states, V_in, V_out, Np);
% Compute cost function: (V_ref - V_out_pred)^2
voltage_error = (V_ref - V_out_pred)^2;
% Total cost for current switch combination
total_cost = voltage_error;
% Find minimum cost and update optimal switch states
if total_cost < min_cost
min_cost = total_cost;
optimal_switch_inputs = current_switch_states;
end
end
% Return the optimal switching inputs to control the IGBTs
switch_inputs = optimal_switch_inputs;
end
function [V_out_pred] = predict_future_voltage(switch_states, V_in, V_out, Np)
% Inputs:
% switch_states - Current states of the 6 IGBT switches
% V_in - Measured input voltages [V_a, V_b, V_c]
% V_out - Measured output DC voltage
% Np - Prediction horizon
% Extract input voltages
V_a = V_in(1);
V_b = V_in(2);
V_c = V_in(3);
% Initialize predicted output voltage
V_out_pred = V_out; % Start with the current output voltage
% Future voltage prediction logic based on switches
for k = 1:Np
if switch_states(1) == 1 && switch_states(2) == 1
V_out_pred = V_a;
elseif switch_states(3) == 1 && switch_states(4) == 1
V_out_pred = V_b;
elseif switch_states(5) == 1 && switch_states(6) == 1
V_out_pred = V_c;
end
end
end
Funtion 2:
function [S1, S2, S3, S4, S5, S6] = switch_control_function(V_in, V_out, V_ref, switch_inputs)
% Inputs:
% V_in - Measured input voltages [V_a, V_b, V_c]
% V_out - Measured output voltage
% V_ref - Reference voltage
% switch_inputs - Input from MPC indicating the optimal switch states
% Outputs:
% S1, S2, S3, S4, S5, S6 - Switching signals for the 6 IGBTs
% Extract input voltages
V_a = V_in(1);
V_b = V_in(2);
V_c = V_in(3);
% Initialize switch states
S1 = switch_inputs(1);
S2 = switch_inputs(2);
S3 = switch_inputs(3);
S4 = switch_inputs(4);
S5 = switch_inputs(5);
S6 = switch_inputs(6);
% Apply switching logic based on voltage conditions
if V_a == 0
% If phase A voltage is zero, turn off S1, S2 and increase switching speeds of others
S1 = 0;
S2 = 0;
S3 = adjust_switch_speed(V_out, V_ref);
S4 = adjust_switch_speed(V_out, V_ref);
S5 = adjust_switch_speed(V_out, V_ref);
S6 = adjust_switch_speed(V_out, V_ref);
elseif V_b == 0
% If phase B voltage is zero, turn off S3, S4 and increase switching speeds of others
S3 = 0;
S4 = 0;
S1 = adjust_switch_speed(V_out, V_ref);
S2 = adjust_switch_speed(V_out, V_ref);
S5 = adjust_switch_speed(V_out, V_ref);
S6 = adjust_switch_speed(V_out, V_ref);
elseif V_c == 0
% If phase C voltage is zero, turn off S5, S6 and increase switching speeds of others
S5 = 0;
S6 = 0;
S1 = adjust_switch_speed(V_out, V_ref);
S2 = adjust_switch_speed(V_out, V_ref);
S3 = adjust_switch_speed(V_out, V_ref);
S4 = adjust_switch_speed(V_out, V_ref);
end
end
% Helper function to adjust the switching speed of IGBTs
function [adjusted_speed] = adjust_switch_speed(V_out, V_ref)
% If output voltage is below reference, increase the switching speed
if V_out < V_ref
adjusted_speed = 1; % Full speed
else
adjusted_speed = 0; % Turn off
end
end
The issue is when I try to run and compile, these error came up.
Error compiling Simscape network for model fault_detection_and_control_system.
Caused by:
- Number of variables exceeds number of equations. Click on any Simscape blocks identified below for more detailed diagnostics.
- fault_detection_and_control_system/Voltage Sensor
- fault_detection_and_control_system/Voltage Sensor1
- fault_detection_and_control_system/Voltage Sensor2
- fault_detection_and_control_system/Voltage Sensor3
Component:Simulink | Category:Model error
After Vinay suggestion to add electrical reference at the voltage sensors, the slx model now can compile. However, after I pressed RUN.
New error popped up. Please refer to the error below.
Array element 2 is out-of-bounds. Modify the index expression to access elements in the range 1-1. More informationFunction 'MATLAB Function1' (#24.456.457), line 13, column 16: "2" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Array element 3 is out-of-bounds. Modify the index expression to access elements in the range 1-1. More informationFunction 'MATLAB Function1' (#24.475.476), line 14, column 16: "3" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Component:MATLAB Function | Category:Coder error
Simulink unable to determine sizes and/or types of the outputs for block 'fault_detection_and_control_system/MATLAB Function1' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink unable to determine sizes and/or types of the outputs for block 'fault_detection_and_control_system/MATLAB Function1' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Output Port 1' of 'fault_detection_and_control_system/MATLAB Function1/switch_inputs' is a [1x6] matrix.
Component:Simulink | Category:Model error
Please help.
Thank you in advace.
3 个评论
Swastik Sarkar
2024-10-15
Could the SLX file be attached to this question? It would help others in the community provide better assistance.
采纳的回答
Vinay
2024-10-16
Hi Ahmad,
The voltage sensor block is designed to measure the voltage between two points in an electrical circuit. However, in the Simulink model, the ‘electrical reference’ is not connected to the ‘Voltage sensor’ blocks, which is causing an error. To resolve this issue, connect the Simscape ‘electrical reference’ to the ‘Voltage sensor’ block.
Kindly refer to the below documentation of ‘Voltage sensor’ for more details:
更多回答(0 个)
社区
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Electrical Sensors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!