How to maintain variable values between stateflow transitions

1 visualización (últimos 30 días)
Alex Galligan
Alex Galligan el 23 de Abr. de 2024
Respondida: Sayan el 2 de Mayo de 2024
Hello,
I have a stateflow model which is modeling the State of Charge (SOC) of a battery as it cycles between charging and discharging. The stateflow diagram starts in charge and the SOC increases relative to the amount of time the charge is activated, and then the diagram transitions to discharge and the SOC decreases to relative to the amount of time the discharge state is activated. The SOC must maintain its value persisently through 'charge' and 'discharge' however everytime one cycle is completed and the stateflow transitions from discharge back to charge, SOC is reset. How do I avoid this reset? I want SOC to persist through multiple cycles and not be reset after each cycle.
Right now the stateflow diagram can complete one 'cycle' before SOC is reset to zero.

Respuestas (1)

Sayan
Sayan el 2 de Mayo de 2024
Hi Alex Galligan,
I think the issue is with the logic you have written for modifying the value of SOC in the "StateOfCharge" variable in the "Charge" state. Every time one cycle is completed, the value of the "StateOfCharge" variable is re-initialized with the total elapsed time since the "Charge" state is active as it is initialized with the "ChargeAdded" variable. You can modify it as follows:
StateOfCharge = StateOfCharge + ChargeAdded
Hope this helps in resolving the issue.

Categorías

Más información sobre Stateflow en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by