How to code a discrete rotating switch from simulink into matlab
이전 댓글 표시
Hi, I'm new to matlab and I'm making a basic fuel system. I want to be able to control the refuel states with a discrete rotating selector switch with 5 states: refuel, refuel2desired, off, defuel2desired. Whenever I run the model I get an algabraic loop error and I don't know why. Either it's this section of code or I've done something wrong in the simulink model.
Is this code correct or is there a better way of writing it?
Thank you!
CurrentFuel = (Calculated in other section of code)
DesiredFuelQuantity = (user input)
MaxQuantity = 5180;
MinQuantity = 50;
while (RefuelSwitch == 1) && (LThrottle == 0) && (RThrottle == 0) && (EngineOnSwitch == 0)
if (RefuelState == 0)
BOpen = 0;
else
%Refuel
if (RefuelState == 1)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 1) && (CurrentFuel == MaxQuantity)
BOpen = 0;
end
%Refuel to Desired Quantity
if (RefuelState == 2)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel to Desired Quantity
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel <= MinQuantity)
BOpen = 0;
end
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!