Jump to content
OMRON Forums

obtain the current axis position in programs


shu

Recommended Posts

Hi,

I'm trying to find a way to get axis positions in a C program (Capp or Cplc). The GetCoordPos() function takes about 700µs to obtain all the structure information. Is there a faster way instead?

 

I've tried something in a Capp program as below:

double x, y, aa;
pshm->Ldata.coord = cs_number;
Command("pread");
x = pshm->Ldata.D[6];
y = pshm->Ldata.D[7];
aa = pshm->Ldata.D[9];

 

and:

double x, y, aa;
char  *szdata = (char *)malloc(CHAR_BUF_SIZE*sizeof(unsigned char));
sprintf(szdata,"Ldata.coord = %u", cs_number);	
Command(szdata);
Command("pread");
x = pshm->Ldata.D[6];
y = pshm->Ldata.D[7];
aa = pshm->Ldata.D[9];

 

and:

double x, y, aa;
char  *szdata = (char *)malloc(CHAR_BUF_SIZE*sizeof(unsigned char));
sprintf(szdata,"&%u p", cs_number);
x = pshm->Ldata.D[6];
y = pshm->Ldata.D[7];
aa = pshm->Ldata.D[9];

But none of them worked, the results showed always : x=0, y=0, aa=0 with the debugger tool.

 

Another question, I tried with a script program:

open plc 10
ldata.coord = 9 
pread 
p100 = D6
p101 = D7
close

But I couldn't really understand the result, as shown attached pictures : "watch window.PNG" and "terminal window.PNG", the responses for "&9p" axes position are not the same from different query command calls.

1584869685_watchwindow.PNG.0c100ae4be79b760d4193bd6e40e69c1.PNG208287357_terminalwindow.PNG.206ddba297e91e1cc3db0cf434470431.PNG

Do I make some mistakes somewhere?

 

Thanks in advance for help!

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Your C-code can not work as you have written since your access to the D-variables is not referenced in any way to the CS. And as C-apps have no "default" CS you have to find a way to know where on the stack the D6 in CS9 is at and use that address.

 

Your script code and terminal and watch window should work. It works fine for me on my system here. I have no idea what else is going on in your system but the command &9p will give the same result from any ascii channel.

 

When we access local variables in CfromScript we do it as follows. Difference is that cfromscript is already referenced to the CS offset. So you will need to find the CS offset for the local vars in CS9 and also add that.

 

UserAlgo.CFunc=1

 

open plc 1

local dummy(20);

local myarray(4);

myarray(0)=0;

myarray(1)=0;

while(1)

{

myarray(0) +=1;

myarray(1) +=2;

P0 = CfromScript(&myarray(0),0,0,0,0,0,0);// The '&' discards the following character (L,M,P,Q,etc.) leaving just the "(L-offset + myarray_index)" as an expression.

}

close

 

double CfromScript(double arg1, double arg2, double arg3, double arg4,double arg5, double arg6, double arg7, LocalData *Ldata) {

double *L;

L = GetLVarPtr(Ldata);//Ldata->L + Ldata->Lindex;

pshm->P[1] = L[(int)arg1+0]; // Now I'm accessing "myarray(0) of PLC 1

pshm->P[2] = L[(int)arg1+1]; // Now I'm accessing "myarray(1) of PLC 1

return 0;

}

 

And since a D-var is a special L-var you should be able to do about the same. Below is how to get base pointers for other types of local variables.

 

double *R;

double *L;

double *C;

double *D;

 

R = GetRVarPtr(Ldata);//Ldata->L + Ldata->Lindex + Ldata->Lsize;

L = GetLVarPtr(Ldata);//Ldata->L + Ldata->Lindex;

C = GetCVarPtr(Ldata);//Ldata->L + Ldata->Lindex + MAX_MOTORS;

D = GetDVarPtr(Ldata);// Ldata->D;

Link to comment
Share on other sites

Hi Brad,

Thanks for your advices. The terminal and watch window work now with the IDE updated.

I'm trying to compile the usrcode.c with the CfromScript function. But a compilation error occurred:

Error : The compiler was not able to generate an executable file.  Please open the following error log file for more information

The log references to "..\Realtime Routines\\err.log" and "..\Realtime Routines\\msg.log" files. The "..\Realtime Routines\err.log" shows:

cp: cannot stat '/usr/local/usralgo/usralgomain.c': No such file or directory
make: *** [all] Error 1

Have you met this problem?

Link to comment
Share on other sites

No I have not. Some things to check/try.

 

make sure the usercode.h has the proper prototype

 

double CfromScript(double arg1,double arg2,double arg3,double

arg4,double arg5,double arg6,double arg7,LocalData *Ldata);

EXPORT_SYMBOL(CfromScript);

 

Make sure usercode.c properties build action is set to compile

 

I imagine both are OK.

 

Open a new project and make a simple cfromscript and see if it builds. it does not matter if anyone calls this, just looking if the build is OK. Maybe some setting in the old project makes a problem.

 

double CfromScript(double arg1, double arg2, double arg3, double arg4, double arg5, double arg6, double arg7, LocalData *Ldata)

{

double myDouble;

 

pshm->P[1]++;

 

myDouble = pshm->P[1];

return myDouble; // Can change this to return anything else if needed

}

Link to comment
Share on other sites

Both usercode.h and usercode.c have been correctly set.

 

I tried a new project, but the compile failed with the same error.

 

With Putty, I connected to the ppmac, there is indeed no folder named "usralgo" in '/usr/local/' directory. Should I need to update something?

Link to comment
Share on other sites

  • 2 weeks later...

Make sure you are using the latest firmware and IDE from FileDepot.

 

I'm using IDE 2.0.3.40, the firmware version is 2.0.2.14.

However I tried on another PC using the same IDE version and same project on same PowerBrick, it succeed to compiler the code. I can't really understand what's wrong...

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...