Jump to content
Saurya Mishra

Using C Block for Event Activation

Recommended Posts

I am trying to use a custom C code to generate an activation signal. Are there specific examples to show how a simple activation signal can be generated from a C Block? I am able to use the C Block for generating outputs, but not event signals.

Share this post


Link to post
Share on other sites

I don't know the exact solution, but you start with definition of numer of output event ports:

image.png.372495da63464e3ff63fa06ce6fd5e1d.png

 

If you generate the skeleton of the c function code you get:

#include "vss_block4.h"
VSS_EXPORT void CBlockFunction(vss_block *block,int flag)
{
  SCSREAL_COP *in=(SCSREAL_COP *)GetInPortPtrs(block,1);
  int min=GetInPortRows(block,1);
  int nin=GetInPortCols(block,1);
  SCSREAL_COP *out=(SCSREAL_COP *)GetOutPortPtrs(block,1);
  int mout=GetOutPortRows(block,1);
  int nout=GetOutPortCols(block,1);
  int nevprt=GetEventCode(block);
  SCSREAL_COP *evout=GetNevOutPtrs(block);
  switch (flag){
  case VssFlag_Initialize:

    break;
  case VssFlag_Reinitialize:

    break;
  case VssFlag_Terminate:

    break;
  case VssFlag_OutputUpdate:

    break;
  case VssFlag_EventScheduling:

    break;
  }
}

Now *evout is the variable to be used for the event, e. g. *evout = 1;. It has to be set with flag == VssFlag_EventScheduling.

 

I try to set up a small example, where I set the output event depending on an input value (x > const), but the event occurs sometime, but not at the expected point of time. Here I need the help of someone else.

Share this post


Link to post
Share on other sites

Hello Roket,

 

Thanks for your reply. I tried it and am able to get the activation signal form a C block. But as you said, there is a problem with the timing as well.

Here is the code i used for the C Block.

 

Quote

#include "vss_block4.h"
VSS_EXPORT void CBlockFunction(vss_block *block,int flag)
{
  SCSREAL_COP *u1=(SCSREAL_COP *)GetInPortPtrs(block,1);
  int mu1=GetInPortRows(block,1);
  int nu1=GetInPortCols(block,1);
  SCSREAL_COP *u2=(SCSREAL_COP *)GetInPortPtrs(block,2);
  int mu2=GetInPortRows(block,2);
  int nu2=GetInPortCols(block,2);
  SCSREAL_COP *u3=(SCSREAL_COP *)GetInPortPtrs(block,3);
  int mu3=GetInPortRows(block,3);
  int nu3=GetInPortCols(block,3);
  SCSREAL_COP *BrkDir=(SCSREAL_COP *)GetOutPortPtrs(block,1);
  int mBrkDir=GetOutPortRows(block,1);
  int nBrkDir=GetOutPortCols(block,1);
  int nevprt=GetEventCode(block);
  SCSREAL_COP *evout=GetNevOutPtrs(block);


  switch (flag){
  case VssFlag_Initialize:

    break;
  case VssFlag_Reinitialize:

    break;
  case VssFlag_Terminate:

    break;
  case VssFlag_OutputUpdate:
      
    break;
  case VssFlag_EventScheduling:
        
    double PosDif = 0.1;
    double VelDif = 0.1;
      
      if (*u3 !=1)
      {
        if ((*u1 >= 0) && (*u1 <=PosDif) && (*u2 >=0) && (*u2 <=VelDif) )
            {
                *evout = 1;
                *BrkDir = -1;

            }
        else if ( (*u1 <= 0) && (*u1 >= (-1)*PosDif) && (*u2 <=0) && (*u2 >= (-1)*VelDif) ) 
            {
                *evout = 1;
                *BrkDir = 1;

            }
        }
      
    break;
  }
}
 

 

Although the evout and the BrkDir are generated at the same point, the timing is way off. This is what the graphs of the event and the BrkDir look like.

 

Can anyone from the Altair technical team help ?

 

BR

Saurya

image.png

Share this post


Link to post
Share on other sites

Hi Saurya,

 

I misunderstood the function of evout. It is the relative time between current activation and output of activation (and not the signal itself as I supposed).

 

Best regards,
Ronald

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×