-
Notifications
You must be signed in to change notification settings - Fork 1
Functionality to Convert Subsystem to Simulink Function #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
monikajaskolka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sl_customization.m
- Line 40:
- Use a dialog box to get user input: https://www.mathworks.com/help/matlab/ref/inputdlg.html
- Change "Simulink-function" to "Simulink Function" to be consistent with other menus.
- Line 33, 47: Capitalize "To" to be consistent with the other menus.
- Check that a new Simulink Function with the user's input is allowed to be added to the model without causing simulations errors, e.g., if a function of that name already exists in scope. Use
getCallableFunctions.mto get a list of all Simulink Functions in scope at the model level where the new function is to be added, and if the new function has the same name (including qualifier) as another that is in scope (regardless of parameter list), then it cannot be added.
isSubsystem.m
Even though this function is used in the specific sense of converting a subsystem, it should be made more general, so we can reuse it in the future. In particular on Line 11, don't assume that the input will be a cell array with a pathname. When dealing with inputs that can represent a block or other model elements, you should allow the function to accept it as a pathname or handle. So, the input can be a char array, a numeric block handle, a cell array of names, or a vector of handles. The function fails for these cases:
isSubsystem({}),isSubsystem('')Empty inputisSubsystem(gcb)Char array nameisSubsystem(gcbh)Numeric handleisSubsystem({gcb, gcb}),isSubsystem([gcbh, gcbh])Multiple elements. This should return[1, 1]. Note: The functionget_paramalready works on multiple elements.
Other
Please make the code formatting consistent. In particular, add spaces around assignment (=), and one space after commas. You can try using MBeautifier to automatically do it, but I haven't used it myself. Unfortunately MathWorks doesn't provide code beautification other than automatic code indentation.
Before:After:
|
src/subToSimFcn.m
Outdated
| %% Add Trigger to Subsystem | ||
|
|
||
| % Disable subsystem link | ||
| set_param(subsystem, 'LinkStatus', 'inactive'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if the LinkStatus is okay to leave as 'inactive', or do we want to break it entirely by setting it to 'none'? See this for more info: https://www.mathworks.com/help/simulink/ug/control-linked-block-status-programmatically.html
src/subToSimFcn.m
Outdated
| set_param(subsystem, 'LinkStatus', 'inactive'); | ||
|
|
||
| % Adding the trigger block to the subsystem and calibrating its parameters | ||
| TriggerPath = append(subsystem, '/', simulinkFcnName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable names should start with lowercase.
src/subToSimFcn.m
Outdated
| try | ||
| assert(not(strcmp(parameters{port, 4}, 'Inherit: auto'))); | ||
| catch | ||
| disp(['Invalid data type of port', newline, ports{port}, newline,... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be printed on one line? Please also add single quotes around 'Inherit' and 'double'. To print a single quite you escape it with another single quote.
src/subToSimFcn.m
Outdated
| try | ||
| assert(not(strcmp(parameters{port, 6}, '-1'))) | ||
| catch | ||
| disp(['Invalid port dimensions of port:', newline, ports{port},... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print on one line please.
src/sl_customization.m
Outdated
| subToSimFcn(subsystem{1}, simulinkFcnName, 'scoped'); | ||
| end | ||
|
|
||
| function schema=toGlobalSimFcn(callbackInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around = please.
src/sl_customization.m
Outdated
| schema.ChildrenFcns = {@toScopedSimFcn, @toGlobalSimFcn}; | ||
| end | ||
|
|
||
| function schema=toScopedSimFcn(callbackInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around = please.
src/isSubsystem.m
Outdated
| % Check each block to see if its a subsystem | ||
| for block = 1:length(blocks) | ||
| try | ||
| b(block) = strcmpi(get_param(blocks(block),'BlockType'),'SubSystem'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around commas please.
src/isGoodSimFcnName.m
Outdated
| @@ -0,0 +1,37 @@ | |||
| function goodName = isGoodSimFcnName(subsystem, simulinkFcnName) | |||
| % isGoodSimFcnName Checks to see if a Simulink-fcn name clashes with | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be precise and consistent with language in the comments. Please write out 'Simulink Function' instead of 'Simulink-fcn' or 'Simulink-function'. For actual parameter/variable/function names it's okay to shorten it, but be aware that the Simulink language has another block called 'Fcn'.


Three main edits:
Added isSubsystem.m
Added subToSimFcn.m
Edited sl_customization.m