I've been reading up on S Functions and Callbacks (both new to me) in an effort to understand how the Manual Switch block works.
The motivation behind this is that I would like to write a similar block that transitions linearly between its two inputs over a certain amount of time (in particular it is a power electronics simulation, and I want to test a controller with a specific load step profile.) I also like interactive simulink blocks like that since I'm not at a point in development to write automated tests and acceptance criteria.
Here's what I know so far:
Manual Switch Callbacks
*OpenFcn - manswitch Open; //Don't know what this does, called when you double click the block
*StopFcn - manswitch_config stop; // Don't know what this does
Initialization
* [x,y] = manswitch; //populates x and y with points to plot the icon
* manswitch_config; //Don't know what this does
Mask Parameters
*Current Setting (sw) - 0 or 1 //determines which input is going through
*Action (action) - 0 or 1//if set to one in the dialog, will change sw upon closing the parameter dialog, doesn't make the OpenFcn callback
Internal Blocks
*sfblk_manswitch - S Function that appears to simply pass through an 8-bit unsigned int with a value of 1 to a switch control block. I see no reference to the action or sw parameters here, or in any other internal block, and don't see how the "manswitch Open" dialog would have any effect on this block.
Can anyone help shed some light on this? Is there a way to look at the code that is run by the manswitch commands? ('help manswitch' in the console is not that helpful)
Thank you,
-Tony Olivo
Eaton Electrical
The core parts are in manswitch:
lines 38-53: change/toggle the blocks dialog parameters
lines 71-114: change the properties of the underlying (non-manual) switch block being masked by the Manual Switch block.
Note that line 81 changes the Threshold value of the underlying switch block.
(You were looking for a change to the constant block being fed into the switch block, which is a sensible thing to have done, and from lines 97-114 it seems that is what used to happen in older versions, but for some some reason a different approach is now used.)
manswitch is called by the mask initialization routine and returns the x and y data for the block icon (lines 118-119) which are then displayed automatically due to the "plot(x,y)" is the mask icon callback.
Hence there is no icon update within manswitch.
I might add that working on creating a block with type of manual user input although not difficult is typically very time consuming and would fall into the category of an advanced manoeuvre.
I suspect that you can achieve what you want with the judicious use of other blocks, perhaps a manual switch used as an enable on an Enabled Subsystem where there is some ramp inside the enabled system.
(It's a little hard to suggest alternatives without knowing exactly what functionality is required.)
If you wish to look at another example then look at the Slider Gain block (in the Math Library) and its associated helper function
>> edit slideg
Phil.
Reading through manswitch (I didn't realize edit could open built in functions, but I guess it just grabs things out of the search path) I can understand the steps it's taking. I don't mean to imply the Mathworks should have detailed helpfiles on helper functions, I just wanted to point out that I did try to RTM before posting :]
>
> The core parts are in manswitch:
> lines 38-53: change/toggle the blocks dialog parameters
> lines 71-114: change the properties of the underlying (non-manual) switch block being masked by the Manual Switch block.
>
> Note that line 81 changes the Threshold value of the underlying switch block.
> (You were looking for a change to the constant block being fed into the switch block, which is a sensible thing to have done, and from lines 97-114 it seems that is what used to happen in older versions, but for some some reason a different approach is now used.)
>
I see it, I see it.
> manswitch is called by the mask initialization routine and returns the x and y data for the block icon (lines 118-119) which are then displayed automatically due to the "plot(x,y)" is the mask icon callback.
> Hence there is no icon update within manswitch.
And a surprising amount of that file is dedicated to drawing the icon...
>
> I might add that working on creating a block with type of manual user input although not difficult is typically very time consuming and would fall into the category of an advanced manoeuvre.
I can see now why it is a little more of an advanced topic. Thanks for taking the time to point out the main points of functionality.
> I suspect that you can achieve what you want with the judicious use of other blocks, perhaps a manual switch used as an enable on an Enabled Subsystem where there is some ramp inside the enabled system.
> (It's a little hard to suggest alternatives without knowing exactly what functionality is required.)
That's a good suggestion, and I'm sure I can get the desired functionality out of it. I was thinking of pursuing this avenue to get a nice and clean model with as few blocks as possible, but it's probably not worth the effort for the amount of re-use it would get.
>
> If you wish to look at another example then look at the Slider Gain block (in the Math Library) and its associated helper function
> >> edit slideg
>
> Phil.
Thanks again,
-Tony Olivo