How to code a discrete rotating switch from simulink into matlab
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Signal Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!