[Scilab-users] C code in Xcos simulation

Steve stepan.podhorsky at gmail.com
Sat Sep 26 09:03:21 CEST 2020


Hello,

I have hit a problem regarding the Xcos c_block usage. I have developed 
a c_block with following C code:

#include <machine.h>
#include <math.h>

void Ramp(flag,nevprt,t,xd,x,nx,z,nz,tvec,
             ntvec,rpar,nrpar,ipar,nipar
      ,u1,nu1,y1,ny1)
 
 
      double *t,xd[],x[],z[],tvec[];
      int *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar,*nu1,*ny1;
      double rpar[],u1[],y1[];
/* modify below this line */
{

static double target     = 0;
static double inputDelta = 0;
static double out        = 0;

if(u1[0] != target)
{
	target = u1[0];

	if(target - y1[0] < 0)
	{
		inputDelta = y1[0] - target;
	}
	else
	{
		inputDelta = target - y1[0];
	}
}

if(target > y1[0])
{
	out += inputDelta*rpar[2]/rpar[0];
	if(out > target)
	{
		out = target;
	}
}
else if(target < y1[0])
{
	out -= inputDelta*rpar[2]/rpar[1];
	if(out < target)
	{
		out = target;
	}
}
	
y1[0] = out;

}

Xcos simulation containing this block works but my problem is that I need to 
have multiple instances of this block in one Xcos simulation (each instance
with
different set of parameters). I have tried to make several copies of this
block
and set different values of parameters for each copy. This naive approach 
resulted in wrong behavior of all the instances (all the instances gave
exactly
the same output but this output did not correspond to any set of
parameters).

My question is whether it is ever possible to have multiple instances of one 
c_block in one simulation? If so, can anybody give me an advice how to do
that?



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html



More information about the users mailing list