How to maintain variable values between stateflow transitions

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Sayan
Sayan il 2 Mag 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.

Categorie

Scopri di più su Stateflow in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by