Skip to content
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

Common: Added switch block for two outputs #14

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 94 additions & 0 deletions CodeGen/Common/common_dev/switch_output.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
COPYRIGHT (C) 2021 Roberto Bucher (roberto.bucher@supsi.ch)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/

#include <pyblock.h>
#include <stdio.h>
#include <stdlib.h>

/****************************************************************************
* Name: init
*
* Description:
* Not used.
*
****************************************************************************/

static void init(python_block *block)
{
}

/****************************************************************************
* Name: inout
*
* Description:
* Set the output values based on input 2.
*
****************************************************************************/

static void inout(python_block *block)
{
double *y1 = block->y[0];
double *y2 = block->y[1];

double *u = block->u[0];
double *change = block->u[1];

if (change[0] >= block->realPar[0])
{
y1[0] = 0;
y2[0] = u[0];
}
else
{
y1[0] = u[0];
y2[0] = 0;
}
}

/****************************************************************************
* Name: end
*
* Description:
* Not used.
*
****************************************************************************/

static void end(python_block *block)
{
}

/****************************************************************************
* Name: switch_output
*
* Description:
* Call needed function based on input flag.
*
****************************************************************************/

void switch_output(int flag, python_block *block)
{
if (flag==CG_OUT){ /* get input */
inout(block);
}
else if (flag==CG_END){ /* termination */
end(block);
}
else if (flag ==CG_INIT){ /* initialisation */
init(block);
}
}
166 changes: 166 additions & 0 deletions resources/blocks/Icons/SWITCH_OUT.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/blocks/blocks/nonlin/SwitchOut.xblk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"lib": "nonlin", "name": "Output Switch", "ip": 2, "op": 2, "stin": 0, "stout": 0, "icon": "SWITCH_OUT", "params": "switchOutBlk|Compare Value: 0.5"}
3 changes: 3 additions & 0 deletions resources/blocks/rcpBlk/help/switchOutBlk.hlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This block decides which output is used based on the value in input 2. If this value is greater than "Compare" value set in block´s parameters, then input 1 is routed to output 2 and vice versa.

Zero value is written to the output that is not currently used.
22 changes: 22 additions & 0 deletions resources/blocks/rcpBlk/nonlin/switchOutBlk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from supsisim.RCPblk import RCPblk
from scipy import size

def switchOutBlk(pin, pout, val):
"""

Call: switchOutBlk(pin, pout, val)

Parameters
----------
pin: connected input ports
pout: connected output ports
val: value to compare

Returns
-------
blk : RCPblk

"""

blk = RCPblk('switch_output',pin,pout,[0,0],1,[val],[])
return blk