Changing Z Axis
Moderators: TomKerekes, dynomotion
Changing Z Axis
Howdy,
Got stuck again. I am trying to use a C program to change which axis is the "Z" axis, and then to Zero the new axis at the new coordinate system.
//Set Spindle 2 as Z
DefineCoordSystem6(6,5,1,-1,-1,-1);
//Set work coordinates for Z
NewZOffset=(Tool2-Offset)*-1;
DoPCFloat(PC_COMM_SET_Z,(NewZOffset/StepsPerIN));
When I execute this program, it changes Z to Axis 1 and jogs just fine, but it seems to set the Z axis for the previous axis 0. Is this a timing issue? Maybe KMotionCNC is getting confused by the changing coordinate system followed quickly by a new zero? Any ideas?
Thanks,
Snyggis
Got stuck again. I am trying to use a C program to change which axis is the "Z" axis, and then to Zero the new axis at the new coordinate system.
//Set Spindle 2 as Z
DefineCoordSystem6(6,5,1,-1,-1,-1);
//Set work coordinates for Z
NewZOffset=(Tool2-Offset)*-1;
DoPCFloat(PC_COMM_SET_Z,(NewZOffset/StepsPerIN));
When I execute this program, it changes Z to Axis 1 and jogs just fine, but it seems to set the Z axis for the previous axis 0. Is this a timing issue? Maybe KMotionCNC is getting confused by the changing coordinate system followed quickly by a new zero? Any ideas?
Thanks,
Snyggis
Re: Changing Z Axis
It is strange, when I run the C program outside of KMotion CNC it works fine. When I run it as a user program from KMotionCNC it doesn't work. Leads me to believe that KMotionCNC is having trouble processing the new coordinates and zero position in the same program. Anyone have any ideas on how to fix this?
Snyggis
Snyggis
Re: Changing Z Axis
When you run the program via KMCNC, have you selected the Exec/Wait/Sync option, so the the coordinated motion buffer is flushed/re-synchronised from the new position?
If you don't select the Sync option, the motion buffer doesn't get flushed, so any previously buffered motion remains, and there will be a sudden jump in motion, which may be causing the problem, as the buffer won't know about the axis change.
If you don't select the Sync option, the motion buffer doesn't get flushed, so any previously buffered motion remains, and there will be a sudden jump in motion, which may be causing the problem, as the buffer won't know about the axis change.
Re: Changing Z Axis
Moray,
Thanks for the reply. Yeah, I tried that first thing, didnt help. I tied without the sync, and wait, none of it worked.
I am using a tool change M-Code to change which spindle I am using. If it is tool1 then I set coordinates and zero for spindle 1. I think it has something to do with the communication between the KFlop and KMotionCNC. When I run the program from KMotion it works, but KMotionCNC only gets the axis change without the new zero when I try to do it from the MCode.
Snyggis
Thanks for the reply. Yeah, I tried that first thing, didnt help. I tied without the sync, and wait, none of it worked.
I am using a tool change M-Code to change which spindle I am using. If it is tool1 then I set coordinates and zero for spindle 1. I think it has something to do with the communication between the KFlop and KMotionCNC. When I run the program from KMotion it works, but KMotionCNC only gets the axis change without the new zero when I try to do it from the MCode.
Snyggis
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Changing Z Axis
Hi Snyggis,
Can you post a complete code example that shows what is Tool2 and Offset, what you expect, and what happens?
What do you mean by this exactly?seems to set the Z axis for the previous axis 0
Can you post a complete code example that shows what is Tool2 and Offset, what you expect, and what happens?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Changing Z Axis
Tom,
The goal is to switch between two spindles through a M6 T1 or T2 command. I have the program Tool Change2.0.c set to Exec/Wait/Sync under the M6 Program.
KMotionCNC:
M6 T1
M30
When I run run this in KmotionCNC
- Spindle 1 Turns ON/Off Correctly
- Spindle 1 is connected to Z and jogs up and down through KMotionCNC
- The Console prints out the correct Z Position
- KMotionCNC does NOT update the Z Position
The same thing happens when I do "T2" everything works with the exception of the updated Z position. If I run the program from KMotion directly it does update the Z position.
Does this make sense? If I havent explained well let me know. I really appreciate the help.
Thanks,
Scott
The goal is to switch between two spindles through a M6 T1 or T2 command. I have the program Tool Change2.0.c set to Exec/Wait/Sync under the M6 Program.
KMotionCNC:
M6 T1
M30
When I run run this in KmotionCNC
- Spindle 1 Turns ON/Off Correctly
- Spindle 1 is connected to Z and jogs up and down through KMotionCNC
- The Console prints out the correct Z Position
- KMotionCNC does NOT update the Z Position
The same thing happens when I do "T2" everything works with the exception of the updated Z position. If I run the program from KMotion directly it does update the Z position.
Does this make sense? If I havent explained well let me know. I really appreciate the help.
Thanks,
Scott
- Attachments
-
- RouterIO.h
- (2.25 KiB) Downloaded 167 times
-
- Tool Change2.0.c
- (1.69 KiB) Downloaded 170 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Changing Z Axis
Hi Scott,
Thanks for the good description.
I think the issue is that the PC_COMM_SET_Z effectively pushes the Set/Zero buttons on the KMotionCNC Screen which are intentionally disabled while GCode is executing.
Below (and attached) is an alternate method of changing the current Fixture Offset to effectively set the DRO in the same manner which is allowed while a Job is running.
As a side note there are other ways of handling dual Spindles. One is to use the Tool Table Length and XY offsets for Tool 1 and Tool 2. In this way you shouldn't really need to do anything in your Tool Change Program. Your GCode must then enable Tool Length Compensation with G43Hx.
HTH
Thanks for the good description.
I think the issue is that the PC_COMM_SET_Z effectively pushes the Set/Zero buttons on the KMotionCNC Screen which are intentionally disabled while GCode is executing.
Below (and attached) is an alternate method of changing the current Fixture Offset to effectively set the DRO in the same manner which is allowed while a Job is running.
As a side note there are other ways of handling dual Spindles. One is to use the Tool Table Length and XY offsets for Tool 1 and Tool 2. In this way you shouldn't really need to do anything in your Tool Change Program. Your GCode must then enable Tool Length Compensation with G43Hx.
Code: Select all
#include "KMotionDef.h"
#include "RouterIO.h"
#define TMP 70 // which spare persist to use to transfer data
#include "c:\KMotion433\C Programs\KflopToKMotionCNCFunctions.c"
#define StepsPerIN 4064
void SetFixZ(double value);
main()
{
float Tool1, Tool2, Offset, NewZOffset;
int Active = *(int *) &persist.UserData[0];
//Distance between Axis home and each tool touchoff
Tool1 = *(float *) &persist.UserData[S1Offset];
Tool2 = *(float *) &persist.UserData[S2Offset];
Offset = *(float *) &persist.UserData[ZOffset];
if(Active==1)
{
//Make sure spindle is off
ClearBit(SpindleON);
//Raise all spindles
Move(0,0);
Move(1,0);
while(!CheckDone(0));
while(!CheckDone(1));
//Disconnect other spindles
ClearBit(SpindleRLY1);
//Connect Spindle 1 to EDC
SetBit(SpindleRLY0);
//Set Spindle 1 as Z
DefineCoordSystem6(6,5,0,-1,-1,-1);
//Calculate Axis Position
NewZOffset=(Tool1-Offset)*-1;
//Write to Console
printf("New Z Position %f\n\n",(NewZOffset/StepsPerIN));
//Set New Z Position
SetFixZ(NewZOffset/StepsPerIN);
}
if(Active==2)
{
//Make sure spindle is off
ClearBit(SpindleON);
//Raise all spindles
Move(0,0);
Move(1,0);
while(!CheckDone(0));
while(!CheckDone(1));
//Disconnect other spindles
ClearBit(SpindleRLY0);
//Connect Spindle 1 to EDC
SetBit(SpindleRLY1);
//Set Spindle 1 as Z
DefineCoordSystem6(6,5,1,-1,-1,-1);
//Calculate Axis Position
NewZOffset=(Tool2-Offset)*-1;
//Write to Console
printf("Tool 2 New Z Position %f\n\n",(NewZOffset/StepsPerIN));
//Set New Z Position
SetFixZ(NewZOffset/StepsPerIN);
}
}
// Set Z DRO to specified value by adjusting current Fixture Offset
// Similar functionality as Set button but will function while Job is running
#define Zaxis 2
void SetFixZ(double value)
{
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 the value
NewOriginOffset = OriginOffsetZ + DROz - value;
SetUserDataDouble(TMP,NewOriginOffset);
SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP);
DoPC(PC_COMM_UPDATE_FIXTURE);
}
- Attachments
-
- Tool Change3.0.c
- (2.8 KiB) Downloaded 148 times
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Changing Z Axis
Thanks Tom! Works like a champ!
Re: Changing Z Axis
Tom,
Your reply has been very helpful. I am wondering if I could do a similar thing with the X Axis. I am currently using "G43 H" to offset the X axis when I change spindles. Unfortunately all of the generic post processors that I find do a "M6 T" call, then move to position, then do the "G43" command. When it executes the G43 and puts in my X offset it cuts through my part. I have been spending most of the day trying to modify a post to call G43 right after the tool change without success.
Would it be possible that right after I set the new Z position, that I could add a second function that offsets X by the distance between spindles? I dont understand how the SetFixZ function you wrote works. Could it be simply modified to do what I described?
//Set New X Position
SetFixX(ch6->Position+XOffset);
Snyggis
Your reply has been very helpful. I am wondering if I could do a similar thing with the X Axis. I am currently using "G43 H" to offset the X axis when I change spindles. Unfortunately all of the generic post processors that I find do a "M6 T" call, then move to position, then do the "G43" command. When it executes the G43 and puts in my X offset it cuts through my part. I have been spending most of the day trying to modify a post to call G43 right after the tool change without success.
Would it be possible that right after I set the new Z position, that I could add a second function that offsets X by the distance between spindles? I dont understand how the SetFixZ function you wrote works. Could it be simply modified to do what I described?
//Set New X Position
SetFixX(ch6->Position+XOffset);
Snyggis
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Changing Z Axis
Hi Snyggis,
Well yes, but you can’t call a function to change the x Fixture offset that doesn’t exist. You will need to create it. Duplicate the SetFixZ function, change its name, and change it so it deals with x instead of z.
Well yes, but you can’t call a function to change the x Fixture offset that doesn’t exist. You will need to create it. Duplicate the SetFixZ function, change its name, and change it so it deals with x instead of z.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.