How to maintain variable values between stateflow transitions

1 回表示 (過去 30 日間)
Alex Galligan
Alex Galligan 2024 年 4 月 23 日
回答済み: Sayan 2024 年 5 月 2 日
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.

回答 (1 件)

Sayan
Sayan 2024 年 5 月 2 日
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.

カテゴリ

Help Center および File ExchangeStateflow についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by