Variant control variable initialization

7 ビュー (過去 30 日間)
Cheyenne Hua
Cheyenne Hua 2019 年 4 月 22 日
回答済み: Jesús Zambrano 2020 年 2 月 6 日
I have a variant subsystem where one of the controls is throttle_controller == 1.
My initFcn first clears the workspace, then runs a script where this variable throttle_controller gets initialized. If I run the stuff in the initFcn from the command line, this variable throttle_controller does show up so I know the initFcn works as intended.
When I run the simulation, I get an error
Variant control 'throttle_controller == 1' used by block 'Car/software/throttle_controller' should return a logical value.
Caused by:
  • Undefined function or variable 'throttle_controller'.
Then I check the workspace, it is blank. Apparently the initFcn didn't even run yet. Does the variant subsystem look for its necessary variables before callbacks are run?
How do I initialize the variable in the initFcn? I don't want to put it in postLoadFcn because I change the value of the variable and run the model many times after I load it once.
Capture.PNG
Capture2.PNG

回答 (1 件)

Jesús Zambrano
Jesús Zambrano 2020 年 2 月 6 日
Hi Cheyenne,
Try to use the PreLoadFcn callback, which is executed before the model is loaded. The variable will be in the workspace, then you can change it before running a new variant. Also check some workflow here https://se.mathworks.com/help/simulink/ug/create-and-open-models.html#btozflu-1

カテゴリ

Help Center および File ExchangeComponent-Based Modeling についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by