analyzing and debugging logic with stateflow video -凯发k8网页登录
a fuel control system is a critical component of an engine. ensuring the engine operates reliably requires a controller that is tolerant to sensor failures. designing such a controller involves keeping track of multiple sensor states and determining the fuel mode based on which or how many sensors have failed. stateflow® has graphical programming features that will help you model interconnected and complex logic in a clear and concise manner. its visual tools provide a powerful way to break down sequences of decisions and explore the behavior of your system in detail. the symbols pane shows which variables are present in the chart and their value at the current execution stage. clicking a state or transition will highlight the relevant symbols for the object. clicking on an individual symbol will in turn show where it is used in the chart. this can help you identify connections that are otherwise not explicit. the value shown in the symbols pane flashes when its value changes from one time step to the next, making it easy to keep track of these changes—even in a system with many symbols. breakpoints can be added to the states and transitions to debug unexpected chart execution. once a breakpoint is hit, you can use the step forward and step over buttons to advance the simulation manually and inspect the logic of the system in detail.
stateflow provides powerful tools for modelling, analyzing, and debugging complex logic. this video will show you how to use its visual programming features to break down sequences of decisions and explore the behavior of your system in detail.
but first, an overview of the system.
this chart models the logic for fault detection and handling of a fuel rate control system and can be divided into three parts. the four parallel subcharts at the top keep track of the state of each individual sensor; the superstate in the middle counts how many of the sensors have failed; and the superstate at the bottom determines the fuel mode of the system based on which sensors have failed. the complexity in this chart comes from the interdependence of these parallel states and their respective child states.
this dashboard can be used to control the fail state for each of the sensors, as well as the engine speed. interacting with the panel during simulation is a great way to explore the logic of the system.
to access this model, follow the first link below this video or execute this command in the matlab command window.
the chart starts in a low emissions mode with no failures. increasing the engine speed activates the transition to the ‘overspeed’ state. in this state, fuel injection is disabled because the engine is above the maximum allowable speed.
the exit condition here is more complex than the entry condition, as it involves multiple chart symbols. to better understand the logic, pause the simulation.
open the symbols pane to see what variables are involved. stateflow will highlight the relevant ones and show their current value. clicking on an individual symbol will in turn show where it is used in the chart. this can help you identify connections that are otherwise not explicit, such as the connection with the ‘speed’ subchart. it also tells you that failing any other sensor will not affect this transition.
now, reduce the engine speed and click on step forward to advance the simulation by a single time step. this shows the chart proceeding to this junction and taking the first transition, because there is only one failed sensor.
at the end of the step, the value of the ‘fuel_mode’ symbol flashes to indicate it has just changed, in this case from ‘disabled’ to ‘low’. with this, it is simple to monitor how the different symbols are affected during simulation.
stepping forward once again transitions the ‘running’ state from ‘low_emissions’ to ‘rich_mixture’, because of the failed ego sensor. it took the chart two steps to get here because of this history junction, which makes a superstate resolve to its most recent child state. was this the behavior you expected?
you can add breakpoints to transitions and states to debug unexpected chart execution. stop the simulation and click on the ‘add breakpoint’ button on the toolstrip to add one to the ‘running’ state.
to understand how the simulation proceeds in detail, use the step over button. stateflow will highlight the state in green, because it is currently being processed, and will also indicate that it is being entered.
this level of granularity will help you break down complex sequences of decisions when analyzing the logic of the chart.
stepping over once more shows that the ‘running’ state resolves into the ‘low_emissions’ state without taking a transition. stepping over twice more shows the same happening to the ‘normal’ child state. with this, the inner workings of a history junction become much clearer.
is this a desirable behavior? would you also use a history junction here or would you rather add a transition straight into ‘single_failure’?
with the powerful analysis and debugging tools of stateflow, it is easy to try out different control logic designs and determine what is best for your system.
this fuel rate control system shows how stateflow can be used to analyze complex and interconnected logic. for more information on modelling and understanding logic with stateflow, visit the ‘get started’ page linked below.
related products
learn more
featured product
stateflow
up next:
related videos:
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 mathworks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- (español)
- (english)
- (english)
欧洲
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
亚太
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)