Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Index into structures
#1
Is it the intention that I cannot index structure elements by Global (P) variable in a pmc file?

e.g.
Code:
global MyEnc;

Motor[14].pEnc = EncTable[MyEnc].a;

It seems to allow

Code:
    global MyEnc;

    local enc = MyEnc;
    Motor[14].pEnc = EncTable[enc].a;

I need this for flexible code for different machine configurations and using the local variable feels like a waste.

I cannot find this mentioned in the user guide in the computational features area discussing element indexing.
Reply
#2
Yes, you can only use a local variable, that is the design.
Reply
#3
Thanks for the info, I altered my design to use parameters in a callsub (so effectively local in the sub) and I am happy.
Reply
#4
FYI - the index value limitations are described at the beginning of "MOTOR[X]. SAVED DATA STRUCTURE ELEMENTS" in the "Power PMAC Software Reference Manual".
Reply
#5
You're right, my search in the PDFs for "index" quickly lost my attention!

Although it does explicitly say the index to the 'Motor' (I also now see it mentioned in comptable[m].data[i] for i, coord[x], sys.cdata[i] etc). No mention in EncTable[n].

Can I assume this is the case for all [] access in script code?

Perhaps it should be explained in POWER PMAC COMPUTATIONAL FEATURES - Pre-Defined Data Structures where indexing is described, and in the same area as the other quirks of the script language.

Ultimately I think it would be nice to allow P-variable indexing. It seems natural to want to define a machine configuration (e.g. FrontMotor=1) in a global variable then refer to this throughout the code without worrying about its type.
Reply
#6
This is part of the training slides, chapter 6. It should also be in the User Manual.

Index is in square brackets, not in parentheses
Index must be integer constant or local L-variable
No expressions, no fractions
If calculating index value, must do this in separate program command that assigns value to L-variable, e.g.
L0=Ldata.Motor;
Motor[L0].JogSpeed=100;
Indices always start at 0
Motor[x]. index value matches Motor number (#x)
Coord[x]. index value matches C.S. number (&x)
ASIC index value matches ASIC number (but ASIC numbering scheme different from Turbo PMAC)
ASIC channel index (0 – 3) is one less than ASIC channel number (1 – 4)
Constant index values can range from 0 to Sys.MaxItems - 1
Variables used for index can range from L0 to L(1022 – Sys.MaxItems)

You are correct, It would be nice, but when we designed this there were several technical reasons why P-vars and expressions could not be used in indecies so we had to do it this way.
Reply
#7
Can I use index structure L0 or Ldata.motor in a PLC?

My intention is to make a loop for 8 motors in a PLC. In this loop, I need the index for Motor[index], kill, jog, etc. I also want to use the index L0 for indexing my global array.
Reply
#8
You can use numbered L-Variables like L0 or or named local variables for looping over Motor[index]. Looping over global variables arrays works with either.

Ldata.motor can be used to specify a single motor jog commands that don't otherwise specify a number go to. It would probably be clearer to include the motor number in the jog commands (even if as a loop variable).
Reply
#9
Eric, can you explain why following code in kinematic script:

Code:
open forward (1)      // Put Coordinate System number inside "(cs)"
    LOCAL mot;
    local ax;
    LOCAL ratio;
    ax = 1;
    mot = 1;
    ratio = Motor[mot].CoordSf[ax];
close

... raises following compiler error:

Code:
...
Total Project download time = 3.344 seconds.
Total Project build and download time = 3.344 seconds.
There were errors during the download process and the download process has stopped.
The following errors were found:
    1 Error(s)

C:\job\.....\PMAC Script Language\Kinematic Routines\Forward1.kin(18,1) : Error : ( error #31)  invalid data :   L322 = Motor[L320].CoordSf[L321]

What is wrong? How to fix it?

Roman
Reply
#10
Roman,

We're still looking into this, but to consolidate, whenever we figure it out I will reply in the other thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)