Jump to content
OMRON Forums

CFromScript include problems


daves

Recommended Posts

I am probably missing something simple here but I am struggling to get the simplest c-code built in to the CFromScript architecture... I can offer a simple example:

 

Create a new project.

Add the following to usercode.c

 

//#include "../Include/test.h"

double CfromScript(double arg1, double arg2, double arg3, double arg4, double arg5,double arg6, double arg7, LocalData *Ldata)
{
return fabs(arg1);
//return DoTest(arg1);
}

 

This works fine.

If I want some shared code by uncommenting the include and return from a function:

 

#include "../Include/test.h"

double CfromScript(double arg1, double arg2, double arg3, double arg4, double arg5,double arg6, double arg7, LocalData *Ldata)
{
//return fabs(arg1);
return DoTest(arg1);
}

 

and test.h contains:

 

double DoTest(double arg1)
{
return fabs(arg1);
}

 

I get build errors containing:

 

C:\Users\daves.ABD\Documents\PowerPmacSuite\PowerPmac5\PowerPmac5\C Language\Realtime Routines\usrcode.c(23,0): Warning : in file included from  /cygdrive/c/Users/daves.ABD/DOCUME~1/POWERP~1/PO3361~1/POWERP~1/CLANGU~1/REALTI~1/usrcode.c
C:\Users\daves.ABD\Documents\PowerPmacSuite\PowerPmac5\PowerPmac5\C Language\Realtime Routines\test.h(3,0): Error :  implicit declaration of function 'fabs'
C:\Users\daves.ABD\Documents\PowerPmacSuite\PowerPmac5\PowerPmac5\C Language\Realtime Routines\test.h(3,0): Warning :  incompatible implicit declaration of built-in function 'fabs'

 

I had a go at fixing this with standard includes but it got even more complainy. The code I actually want to share in CFromScript used more standard routines than this and actually slowed the build to a painful halt and had to be killed.

 

What am I not getting here? I assume it is to do with the kernel double-build thing somehow as only the ko complains

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

daves:

 

I don't think fabs() is defined in the kernel (it's usually in math.h, which is for user-mode only). You could try including RtGpShm.h and using FABS() instead. In test.h:

 

#include 
...
double DoTest(double arg1)
{
   return FABS(arg1);
}

 

If you'd rather define it yourself, here's the macro:

 

#define FABS(x) \
({ double result, argx = (x); \
  asm volatile ("fabs %0, %1"  : "=f"(result) : "f"(argx)); \
  result; })

Link to comment
Share on other sites

try including RtGpShm.h and using FABS() instead

 

Thanks shansen this built and downloaded.

 

It is a shame the end user needs to have to know about kernel mode limitations (I am currently trying to educate myself in this area!). Maybe this should be implicit from knowledge of the system architecture but some hints in the User Guide would be useful.

Link to comment
Share on other sites

daves:

 

I don't know if the Power PMAC IDE has a similar feature, but in Eclipse I can hover over any function and it will show me if the function has been declared in the right scope.

 

For example, if I write some user phase code and type fabs() and hover over it, it shows me nothing (not defined). If I do the same thing for FABS(), I get the prototype and it has been bolded (see attached image).

 

Maybe the Power PMAC IDE has a similar way of checking functions exist before compiling? At the very least, the compiler did give a decent error message relating to fabs().

 

Either way, it's probably a good bet that most functions you will be using for user phase or user servo code come from RtGpShm.h or rtpmacapi.h, so if the function doesn't exist within these header files it probably isn't available.

Example.jpg.e59d42c3d22e23d7d05058548740008e.jpg

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...