saving the kmotion cnc jogged value to a permanent common variables

Moderators: TomKerekes, dynomotion

ajith
Posts: 51
Joined: Sat May 21, 2022 3:57 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by ajith » Tue Jun 14, 2022 10:47 am

Respected Sir,
using the "SetFixturez.c" program i can the read the value in the offset variable. but the jogged value gets added in the same variable unless i change the fixture offset in the gcode screen. is there a way to store the jogged value one by one in each variable in the variable file .and also i need to combine "SetFixtureX.c", "SetFixtureY.c", "SetFixtureZ.c" into a single program so that when I press a user button I need to move all three axis value to variable file in corresponding each variable. now im trying to combine these three program but i cant understand the functions used in these program.where can i find the description of the function used in the "SetFixturez.c" program.



regards,
M.Ajith Arawinth,

User avatar
TomKerekes
Posts: 1935
Joined: Mon Dec 04, 2017 1:49 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by TomKerekes » Tue Jun 14, 2022 7:10 pm

Hi Ajith,

Well the functions should be fairly self-explanatory.

You don't understand what GetDROs does?

Please put some effort into studying the Program and explain what parts you understand and don't understand.

The basic function this program does (which is somewhat different from what you may want) is:

New Fixture Offset = Previous Origin Offset + DRO
Regards,

Tom Kerekes
Dynomotion, Inc.

ajith
Posts: 51
Joined: Sat May 21, 2022 3:57 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by ajith » Tue Jun 28, 2022 12:27 pm

Respected Sir,
After gone through the "SetFixtureZ.c" I had doubts in the following program lines,
pg2.PNG
pg2.PNG (6.72 KiB) Viewed 286 times

can you explain what is
[PC_COMM_PERSIST+2]
and
DoPCInt(PC_COMM_GET_VARS,varoff);
what is the purpose of variable n(no of elements)?
pg1.PNG
pg1.PNG (4.27 KiB) Viewed 286 times
can you explain this command line
((int*)(&d))[1] = persist.UserData[i*2+1];
pg3.PNG
pg3.PNG (10.5 KiB) Viewed 286 times
what is this line mean
if (DoPCInt(PC_COMM_GET_DROS,TMP)) return 1;

User avatar
TomKerekes
Posts: 1935
Joined: Mon Dec 04, 2017 1:49 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by TomKerekes » Wed Jun 29, 2022 2:00 am

Hi Ajith,
After gone through the "SetFixtureZ.c" I had doubts in the following program lines,
Minor thing: I assume you mean "questions". In English the word "doubt" is used more when you distrust or don't have confidence in something. What is the word for question in your language?

I think you would be better focusing on what the functions do rather than how they do it. You only need to know what they do to use them. But sometimes it helps to know how they do things.
can you explain what is

[PC_COMM_PERSIST+2]
There is an array of 200 persist variables in KFLOP that both the PC and KFLOP can read and write called persist.UserData. These are 32-bit integer variables. A few of these are used to send commands and parameters to KMotionCNC. PC_COMM_PERSIST is the first one used. PC_COMM_PERSIST+1 is the 2nd. PC_COMM_PERSIST+2 is the 3rd.
DoPCInt(PC_COMM_GET_VARS,varoff);
This puts the varoff (where KMotionCNC should put the results) into [PC_COMM_PERSIST+1] and places the Command Code PC_COMM_GET_VARS into [PC_COMM_PERSIST] which issues the command that tells KMotionCNC that it should put some GCode variables into KFLOP.
what is the purpose of variable n(no of elements)?
This tells KMotionCNC how many GCode Variables KFLOP wants

can you explain this command line

((int*)(&d))[1] = persist.UserData[i*2+1];
This is a bit complicated because the persist variables that are shared between KFLOP and KMotioCNC are 32-bit integers and the GCode Variables are 64-bit floating point numbers (doubles). So 2 32-bit persist variable need to be packed into one 64-bit double.

This line of code gets the 2nd persist variable - persist.UserData[i*2+1].

Then takes the memory address of the double "&d".

Then tells the Compiler to treat it as an address that points to an integer "((int*)(&d))".

Then advances to the next integer memory location " ((int*)(&d))[1]"

And puts the persist variable there.
what is this line mean

if (DoPCInt(PC_COMM_GET_DROS,TMP)) return 1;
This tells KMotionCNC to get the 6 DRO values and place them as pairs into 12 KFLOP persist variables starting at persist variable pair TMP.
Regards,

Tom Kerekes
Dynomotion, Inc.

ajith
Posts: 51
Joined: Sat May 21, 2022 3:57 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by ajith » Wed Jun 29, 2022 12:39 pm

Dear sir,
Minor thing: I assume you mean "questions". In English the word "doubt" is used more when you distrust or don't have confidence in something. What is the word for question in your language?
The doubt i mentioned is just a question that popup in my mind.This kmotion controller is purely new concept for me. whatever your reply and solution for my questions i always try it and once again come to search answers for my question while trying the solution you suggested. so i dont distrust you, maybe my grammer is somewhat bad to understand.
Is
#define TMP 10
means TMP carries a value 10 which is constant.or else TMP and 10 symbolises temporary addresses.
return DoPCInt(PC_COMM_GET_VARS,varoff);
int DoPCInt(int cmd, int i)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = i;
return DoPC(cmd);
}
In this lines, does cmd=PC_COMM_GET_VARS,varoff. because in the calling function the parameter cmd is defined as an integer but some command is passed in calling side.

User avatar
TomKerekes
Posts: 1935
Joined: Mon Dec 04, 2017 1:49 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by TomKerekes » Thu Jun 30, 2022 2:22 pm

means TMP carries a value 10 which is constant.or else TMP and 10 symbolises temporary addresses.
Yes. You can basically think of a define as text replacement. Replace TMP everywhere with 10. In this case TMP defines which Persist variables are to be temporarily used in the communication between KMotionCNC and KFLOP.
In this lines, does cmd=PC_COMM_GET_VARS,varoff. because in the calling function the parameter cmd is defined as an integer but some command is passed in calling side.
Its not clear what you mean. But yes cmd is set to PC_COMM_GET_VARS and i is set to varoff by the function call.
Regards,

Tom Kerekes
Dynomotion, Inc.

ajith
Posts: 51
Joined: Sat May 21, 2022 3:57 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by ajith » Mon Jul 04, 2022 12:23 pm

respected sir,
msg ibox.PNG
msg ibox.PNG (10.02 KiB) Viewed 283 times
In this program, after the input for keyboard
Answer = InputBox("Enter Distance",&value);
there is a if else clause inside the if and else block there is print command
printf("Operator Canceled\n");
,
printf("Operator Entered Value of %.3f\n",value);
.
My question is that where i can spectate the printed line in my flop amd kmotion cnc software.

User avatar
TomKerekes
Posts: 1935
Joined: Mon Dec 04, 2017 1:49 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by TomKerekes » Mon Jul 04, 2022 2:51 pm

I don't understand the question. The number the operator entered will be in 'value'
Regards,

Tom Kerekes
Dynomotion, Inc.

ajith
Posts: 51
Joined: Sat May 21, 2022 3:57 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by ajith » Tue Jul 05, 2022 11:38 am

Respected sir,
Answer = InputBox("Enter Distance",&value);
In the above command the operator enters a value which is stored in the value and is assigned to the variable "Answer".
if (Answer)
Next If any value is assigned to the variable "Answer"
printf("Operator Canceled\n");
then the if block is executed which contains a print statement.
My question is if i execute the program via both kmotion nd kmotion cnc where will the printed statement will be displayed?

#include "KMotionDef.h"

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

#define Zaxis 2

main()
{
int FixtureIndex;
double NewOriginOffset,OriginOffsetZ;
double DROx, DROy, DROz, DROa, DROb, DROc;

GetFixtureIndex(&FixtureIndex);

GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);

GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);

// Adjust Origin Offset to make DRO zero
NewOriginOffset = OriginOffsetZ + DROz;

SetUserDataDouble(TMP,NewOriginOffset);
SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP);

DoPC(PC_COMM_UPDATE_FIXTURE);
}
In the above program what is purpose of these lines
GetFixtureIndex(&FixtureIndex);

GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);

GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);

Because when I executed the "setfixtureZ" program the variable 5223 value changed. That is the the DRO value of Z Axis after executing the "SetFixtureIndexZ"value get added with the present value in the variable 5223 and the DRO of Z axis is zeroed.
GetFixtureIndex(&FixtureIndex);
This command is a calling function which calls the following function block
int GetFixtureIndex(int *FixtureIndex)
{
if (GetVars(5220,1,TMP)) return 1; // Download to persist TMP
*FixtureIndex=GetUserDataDouble(TMP);
return 0;
}
where the address of fixture index is send as a parameter.
if (GetVars(5220,1,TMP)) return 1;
When this line gets executed which calls the below function block
int GetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_GET_VARS,varoff); // Var index and Cmd
}
where varoff=5220 and n=1 poff=TMP. in this block we are sending the parameter to kmotion cnc that is no of variable (n) and the value from kmotion cnc to be stored in TMP. Then the below line gets executed,
return DoPCInt(PC_COMM_GET_VARS,varoff);

This puts the varoff (where KMotionCNC should put the results) into [PC_COMM_PERSIST+1] and places the Command Code PC_COMM_GET_VARS into [PC_COMM_PERSIST] which issues the command that tells KMotionCNC that it should put some GCode variables into KFLOP.
This is the clarification you have given earlier and with that I Came to an conclusion that we are storing the value of the variable 5220 in the TMP.. This is what i understand and if the If block gets executed then it returns 1 and where will be this 1 is used? . but my question is why we need the value of the variable 5220?
next the below line gets executed
*FixtureIndex=GetUserDataDouble(TMP);
which calls the below function block
double GetUserDataDouble(int i)
{
double d;

((int*)(&d))[0] =persist.UserData[i*2];
((int*)(&d))[1] = persist.UserData[i*2+1];
return d;
}
In this if i=TMP(which carries the value of variable 5220). then whether i also carries the value of variable 5220?
then what about
persist.UserData[i*2];
In the above line what will be the value i*2? but already you told that kmotion cnc value is 64bit so it was stored in two 32 bit persist.userdata.
atlast may I know the algorithm of "SetFixtureIndexZ".
Is it possible to arrange an online meeting with you atleast an audio call?
regards,
Ajith Arawinth,

User avatar
TomKerekes
Posts: 1935
Joined: Mon Dec 04, 2017 1:49 am

Re: saving the kmotion cnc jogged value to a permanent common variables

Post by TomKerekes » Tue Jul 05, 2022 8:10 pm

Answer = InputBox("Enter Distance",&value);

In the above command the operator enters a value which is stored in the value and is assigned to the variable "Answer".
No Answer isn't assigned the value. Answer is set based on whether the operator clicked OK or Cancel.
then the if block is executed which contains a print statement.
My question is if i execute the program via both kmotion nd kmotion cnc where will the printed statement will be displayed?In both cases the program executes in KFLOP and KMotion.exe Console Screen shows KFLOP printfs. Note printfs are normally only used for debugging. Any final code shouldn't have any printf statements.
In the above program what is purpose of these lines

GetFixtureIndex(&FixtureIndex);

GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);

GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
The 1st gets the Fixture index to determine which Fixture offset is in effect. G54, G55, G56, etc

The second gets the current Z Offset for the fixture in use

The 3rd gets the DROs
Because when I executed the "setfixtureZ" program the variable 5223 value changed. That is the the DRO value of Z Axis after executing the "SetFixtureIndexZ"value get added with the present value in the variable 5223 and the DRO of Z axis is zeroed.
The Offset is adjusted to make the DRO zero. Don't think of it as zeroing the DRO. The DROs display where the machine actually is in the current coordinate system. So if we want the current position to be zero then we shift the coordinate system to make this so.
where the address of fixture index is send as a parameter.
correct
This is the clarification you have given earlier and with that I Came to an conclusion that we are storing the value of the variable 5220 in the TMP
We are asking KMotionCNC to put GCode Variable #5220 into the KFLOP persist variables at location TMP
In this if i=TMP(which carries the value of variable 5220). then whether i also carries the value of variable 5220?
then what about
i and TMP are 10 which specifies where the value is located, not the value of variable 5220

In the above line what will be the value i*2? but already you told that kmotion cnc value is 64bit so it was stored in two 32 bit persist.userdata.
i*2 = 10*2 = 20, I*2+1 = 10*2+1 = 21. So variable 5220 can be extracted from the pair of persist variables 20 and 21
atlast may I know the algorithm of "SetFixtureIndexZ".
That's what we've been discussing.
Is it possible to arrange an online meeting with you atleast an audio call?
For personal training we charge a fee. We charge $250/hr with a 2hr minimum. Contact our support if you would like to arrange this.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply