Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using CfromScript() - Calling C Functions from the PMAC Script Language
Attached is a new document describing how to use CfromScript() in Power PMAC, which is a function that permits users to call C functions directly from PMAC Script programs, such as PLCs and Kinematics Subroutines.

CfromScript() can be used for general purpose calculations, but CfromScript() is useful primarily for performing kinematics calculations, because to perform these calculations in a compiled C program is significantly faster than to calculate them using the interpreted PMAC Script kinematics subroutines. This is especially useful for highly nonlinear, computationally-intensive calculations, such as that which occurs in Hexapod or Delta Robot kinematics. Another advantage is that with CfromScript(), the user can more easily implement common C-based nonlinear iterative solvers, such as those given in the famous Numerical Recipes in C cookbook.

If you have any questions on the usage or implementation of this function, please feel free to post them.

Attached Files
.pdf   Using CfromScript in Power PMAC.pdf (Size: 268.01 KB / Downloads: 324)
I know what's the meaning of the L,C and D datas.The documens tells us that:
//#define KinPosMotor1 L1
//#define KinPosMotor2 L2
//#define KinPosAxisX C6
//#define KinPosAxisY C7
//#define KinAxisUsed D0
But what is the meaning of R data,especially in CfromScript,and how to use it?

R variables, according to page 6 of the Power PMAC Computational Features manual, are:

"Stack/return (“R”) variables: local user variables for passing and returning arguments to subroutines and subprograms; equivalent to differently numbered L-variables."

You will not actually need R-Variables for your kinematics subroutines in CfromScript since you can just use whatever variables the C programming language offers for passing parameters between functions. You probably will not need to access these in CfromScript, since they are normally only used in Script-based subprograms and subroutines, but we permit access to R-Variables in C just in case you do need it.

I was hoping you could provide a small example of how to implement C functions in the realtime routine for specifically kinematics. Does the C application need to be called in the realtime PLC to use with kinematics? I have a two motor kinematic equation (motor 1-X and motor 2-Y) that has a fairly simple equation. We are hoping to see the performance gains of moving the kinematic calculations to the C realtime routines.

When i use cfromscrip() function in scrip plc ,i put its result into P var, and it always nan,who could tell me the reason?
Please contact with your code and observed issues.

Forum Jump:

Users browsing this thread: 1 Guest(s)