Changing Z Axis

Moderators: TomKerekes, dynomotion

Post Reply
Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Changing Z Axis

Post by Snyggis » Sat Jun 09, 2018 8:37 pm

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

Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Re: Changing Z Axis

Post by Snyggis » Sat Jun 09, 2018 9:46 pm

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

Moray
Posts: 6
Joined: Thu Apr 26, 2018 10:16 pm

Re: Changing Z Axis

Post by Moray » Mon Jun 11, 2018 3:50 pm

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.

Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Re: Changing Z Axis

Post by Snyggis » Tue Jun 12, 2018 12:41 am

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

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

Re: Changing Z Axis

Post by TomKerekes » Tue Jun 12, 2018 5:53 pm

Hi Snyggis,
seems to set the Z axis for the previous axis 0
What do you mean by this exactly?

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.

Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Re: Changing Z Axis

Post by Snyggis » Tue Jun 12, 2018 7:26 pm

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
You do not have the required permissions to view the files attached to this post.

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

Re: Changing Z Axis

Post by TomKerekes » Wed Jun 13, 2018 9:55 pm

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.


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);
}

HTH
You do not have the required permissions to view the files attached to this post.
Regards,

Tom Kerekes
Dynomotion, Inc.

Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Re: Changing Z Axis

Post by Snyggis » Fri Jun 15, 2018 2:54 am

Thanks Tom! Works like a champ!

Snyggis
Posts: 14
Joined: Thu May 10, 2018 4:04 am

Re: Changing Z Axis

Post by Snyggis » Sun Jun 17, 2018 1:10 am

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

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

Re: Changing Z Axis

Post by TomKerekes » Mon Jun 18, 2018 5:03 am

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.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply